diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index a43eec9..1784448 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -25,6 +25,10 @@ ApplicationClass::ApplicationClass() : m_ShouldQuit(false) m_RefractionTexture = 0; m_ReflectionTexture = 0; m_Physics = 0; + m_cubes.clear(); + m_terrainChunk.clear(); + m_object.clear(); + m_RenderQueues.clear(); } ApplicationClass::~ApplicationClass() @@ -47,6 +51,10 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) bool result; HRESULT Hresult; + m_RenderQueues.push_back(std::ref(m_object)); + m_RenderQueues.push_back(std::ref(m_cubes)); + m_RenderQueues.push_back(std::ref(m_terrainChunk)); + m_screenWidth = screenWidth; m_screenHeight = screenHeight; @@ -1072,7 +1080,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t // -------------------------------------------------------- // // ------------ Render the object in the queue ------------ // // -------------------------------------------------------- // - result = RenderPass(m_terrainChunk, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix); + result = RenderPass(m_RenderQueues, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix); if (!result) { Logger::Get().Log("Could not render the model using any shader", __FILE__, __LINE__, Logger::LogLevel::Error); @@ -1904,81 +1912,74 @@ void ApplicationClass::SetScreenWidth(int width) m_screenWidth = width; } -bool ApplicationClass::RenderPass(std::vector RenderQueue, XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection) +bool ApplicationClass::RenderPass(const std::vector>>& RenderQueues, XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection) { XMMATRIX worldMatrix, scaleMatrix, rotateMatrix, translateMatrix, srMatrix; bool result; - for (auto& object : RenderQueue) + for (const auto& RenderQueue : RenderQueues) { - - if (object == nullptr) + for (auto& object : RenderQueue.get()) { - Logger::Get().Log("Object is null", __FILE__, __LINE__, Logger::LogLevel::Error); - return false; - } - - scaleMatrix = object->GetScaleMatrix(); - rotateMatrix = object->GetRotateMatrix(); - translateMatrix = object->GetTranslateMatrix(); - - srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix); - worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix); - - object->Render(m_Direct3D->GetDeviceContext()); - - // Render cel shading. - if (object->GetCelShading()) { - result = m_ShaderManager->RenderCelShadingShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, object->GetTexture(0), - m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor(), TrueLightPosition); - if (!result) + if (object == nullptr) { - Logger::Get().Log("Could not render the model using the cel shader", __FILE__, __LINE__, Logger::LogLevel::Error); - return false; - } - - continue; - } - - // Render normal mapping. - if (object->GetNormalMappingEnabled()) { - - result = m_ShaderManager->RenderNormalMapShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, object->GetTexture(0), object->GetTexture(1), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor()); - - if (!result) - { - Logger::Get().Log("Could not render the model using the normal map shader", __FILE__, __LINE__, Logger::LogLevel::Error); + Logger::Get().Log("Object is null", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } - continue; - } + scaleMatrix = object->GetScaleMatrix(); + rotateMatrix = object->GetRotateMatrix(); + translateMatrix = object->GetTranslateMatrix(); - // Render Specular mapping. - if (object->GetSpecularMappingEnabled()) { - result = m_ShaderManager->RenderSpecMapShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, object->GetTexture(0), object->GetTexture(1), object->GetTexture(2), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor(), m_Camera->GetPosition(), m_Lights[0]->GetSpecularColor(), m_Lights[0]->GetSpecularPower()); - if (!result) + srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix); + worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix); + + object->Render(m_Direct3D->GetDeviceContext()); + + // Utiliser l'enum ShaderType pour déterminer quel shader utiliser + switch (object->GetActiveShader()) { - Logger::Get().Log("Could not render the model using the specular map shader", __FILE__, __LINE__, Logger::LogLevel::Error); - return false; + case Object::CEL_SHADING: + result = m_ShaderManager->RenderCelShadingShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, object->GetTexture(0), + m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor(), TrueLightPosition); + if (!result) + { + Logger::Get().Log("Could not render the model using the cel shader", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + break; + + case Object::NORMAL_MAPPING: + result = m_ShaderManager->RenderNormalMapShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, object->GetTexture(0), object->GetTexture(1), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor()); + if (!result) + { + Logger::Get().Log("Could not render the model using the normal map shader", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + break; + + case Object::SPECULAR_MAPPING: + result = m_ShaderManager->RenderSpecMapShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, object->GetTexture(0), object->GetTexture(1), object->GetTexture(2), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor(), m_Camera->GetPosition(), m_Lights[0]->GetSpecularColor(), m_Lights[0]->GetSpecularPower()); + if (!result) + { + Logger::Get().Log("Could not render the model using the specular map shader", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + break; + + case Object::LIGHTING: + default: + result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, + object->GetTexture(0), diffuse, position, ambient); + if (!result) + { + Logger::Get().Log("Could not render the object model using the light shader", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + break; } - - continue; } - - - // By default, render the object using the light shader. - result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, - object->GetTexture(0) ,diffuse, position, ambient); - - if (!result) - { - Logger::Get().Log("Could not render the object model using the light shader", __FILE__, __LINE__, Logger::LogLevel::Error); - return false; - } - - continue; } return true; -} \ No newline at end of file +} diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h index 03e96e5..00c0a81 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -113,7 +113,7 @@ private: bool RenderSceneToTexture(float); bool RenderRefractionToTexture(); bool RenderReflectionToTexture(); - bool RenderPass(std::vector RenderQueue, XMFLOAT4* diffuse,XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX proijection); + bool RenderPass(const std::vector>>& RenderQueues, XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection); private : @@ -152,6 +152,7 @@ private : float m_speed = 0.1f; // speed for the demo spinning object std::vector m_object; int m_ObjectId = 0; + std::vector>> m_RenderQueues; // ----------------------------------- // // ------------- LIGHTS -------------- // diff --git a/enginecustom/assets/Texture/EmptyTexture.png b/enginecustom/assets/Texture/EmptyTexture.png new file mode 100644 index 0000000..1330aa3 Binary files /dev/null and b/enginecustom/assets/Texture/EmptyTexture.png differ diff --git a/enginecustom/enginecustom.vcxproj b/enginecustom/enginecustom.vcxproj index 32d272d..e76a0b5 100644 --- a/enginecustom/enginecustom.vcxproj +++ b/enginecustom/enginecustom.vcxproj @@ -304,6 +304,7 @@ $(OutDir)\assets\Texture\ + diff --git a/enginecustom/enginecustom.vcxproj.filters b/enginecustom/enginecustom.vcxproj.filters index 4f828c5..84d1d6c 100644 --- a/enginecustom/enginecustom.vcxproj.filters +++ b/enginecustom/enginecustom.vcxproj.filters @@ -388,6 +388,9 @@ Assets + + Assets\Texture + diff --git a/enginecustom/imguiManager.cpp b/enginecustom/imguiManager.cpp index f9c2067..68621db 100644 --- a/enginecustom/imguiManager.cpp +++ b/enginecustom/imguiManager.cpp @@ -162,7 +162,11 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app) // Texture // add all texture category names to a vector std::vector textureCategories = { - "Diffuse" + "Diffuse", + "Normal", + "Specular", + "Reflection", + "Refraction" }; @@ -246,6 +250,34 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app) app->DeleteKobject(index); } + // Shader selection + std::string shaderLabel = "Shader##" + std::to_string(index); + + // Radio buttons for shader options + Object::ShaderType activeShader = object->GetActiveShader(); + + if (ImGui::RadioButton("Enable Lighting", activeShader == Object::LIGHTING)) + { + object->SetActiveShader(Object::LIGHTING); + } + + if (ImGui::RadioButton("Enable Cel Shading", activeShader == Object::CEL_SHADING)) + { + object->SetActiveShader(Object::CEL_SHADING); + } + + if (ImGui::RadioButton("Enable Normal Mapping", activeShader == Object::NORMAL_MAPPING)) + { + object->SetActiveShader(Object::NORMAL_MAPPING); + } + + if (ImGui::RadioButton("Enable Specular Mapping", activeShader == Object::SPECULAR_MAPPING)) + { + object->SetActiveShader(Object::SPECULAR_MAPPING); + } + + + ImGui::Separator(); // Demo spinning diff --git a/enginecustom/object.cpp b/enginecustom/object.cpp index 304d27e..3d16471 100644 --- a/enginecustom/object.cpp +++ b/enginecustom/object.cpp @@ -233,64 +233,4 @@ bool Object::IsPhysicsEnabled() const void Object::SetPhysicsEnabled(bool state) { m_isPhysicsEnabled = state; -} - -void Object::SetCelShading(bool state) -{ - isCelShading = state; -} - -bool Object::GetCelShading() const -{ - return isCelShading; -} - -void Object::SetLightingEnabled(bool state) -{ - isLightingEnabled = state; -} - -bool Object::GetLightingEnabled() const -{ - return isLightingEnabled; -} - -void Object::SetNormalMappingEnabled(bool state) -{ - isNormalMappingEnabled = state; -} - -bool Object::GetNormalMappingEnabled() const -{ - return isNormalMappingEnabled; -} - -void Object::SetSpecularMappingEnabled(bool state) -{ - isSpecularMappingEnabled = state; -} - -bool Object::GetSpecularMappingEnabled() const -{ - return isSpecularMappingEnabled; -} - -void Object::SetReflectionEnabled(bool state) -{ - isReflectionEnabled = state; -} - -bool Object::GetReflectionEnabled() const -{ - return isReflectionEnabled; -} - -void Object::SetRefractionEnabled(bool state) -{ - isRefractionEnabled = state; -} - -bool Object::GetRefractionEnabled() const -{ - return isRefractionEnabled; } \ No newline at end of file diff --git a/enginecustom/object.h b/enginecustom/object.h index 33633b4..111e34b 100644 --- a/enginecustom/object.h +++ b/enginecustom/object.h @@ -57,19 +57,18 @@ public: bool LoadTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, const std::wstring& filename); - // Setters and getters for the shader to use - void SetCelShading(bool state); - bool GetCelShading() const; - void SetLightingEnabled(bool state); - bool GetLightingEnabled() const; - void SetNormalMappingEnabled(bool state); - bool GetNormalMappingEnabled() const; - void SetSpecularMappingEnabled(bool state); - bool GetSpecularMappingEnabled() const; - void SetReflectionEnabled(bool state); - bool GetReflectionEnabled() const; - void SetRefractionEnabled(bool state); - bool GetRefractionEnabled() const; + enum ShaderType + { + CEL_SHADING, + LIGHTING, + NORMAL_MAPPING, + SPECULAR_MAPPING, + REFLECTION, + REFRACTION + }; + + ShaderType GetActiveShader() const { return m_activeShader; }; + void SetActiveShader(ShaderType activeShader) { m_activeShader = activeShader; }; public : bool m_demoSpinning = false; @@ -91,11 +90,5 @@ private: std::string m_name; - // Shader to use for rendering - bool isCelShading = false; - bool isLightingEnabled = true; - bool isNormalMappingEnabled = false; - bool isSpecularMappingEnabled = false; - bool isReflectionEnabled = false; - bool isRefractionEnabled = false; + ShaderType m_activeShader = LIGHTING; };