From d8851cc679820afbf80a2e917f7267dd2603a025 Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Thu, 23 Jan 2025 20:55:55 +0100 Subject: [PATCH] minor update - light ui tweak --- enginecustom/Lightclass.h | 4 ++++ enginecustom/applicationclass.cpp | 10 ++++++---- enginecustom/applicationclass.h | 2 ++ enginecustom/imgui.ini | 5 +++-- enginecustom/imguiManager.cpp | 30 ++++++++++++++++++++++++++++ enginecustom/lightclass.h | 4 ++++ enginecustom/shadermanagerclass.cpp | 4 ++-- enginecustom/shadermanagerclass.h | 2 +- enginecustom/sunlight.ps | 4 +++- enginecustom/sunlight.vs | 6 ++++-- enginecustom/sunlightshaderclass.cpp | 10 ++++------ enginecustom/sunlightshaderclass.h | 6 +++--- 12 files changed, 66 insertions(+), 21 deletions(-) diff --git a/enginecustom/Lightclass.h b/enginecustom/Lightclass.h index 65dda80..e96c8f7 100644 --- a/enginecustom/Lightclass.h +++ b/enginecustom/Lightclass.h @@ -36,12 +36,16 @@ public: XMFLOAT4 GetSpecularColor(); float GetSpecularPower(); XMFLOAT4 GetPosition(); + + void SetIntensity(float intensity) { m_intensity = intensity; } + float GetIntensity() const { return m_intensity; } private: XMFLOAT4 m_ambientColor; XMFLOAT4 m_diffuseColor; XMFLOAT3 m_direction; XMFLOAT4 m_specularColor; + float m_intensity; float m_specularPower; XMFLOAT4 m_position; }; diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index 3f174b8..8785b33 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -277,14 +277,16 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) m_Lights[3]->SetSpecularPower(16.0f); m_Lights[3]->SetPosition(-10.0f, 7.0f, 5.0f); - // Create || THE SUN || + // ------------------------------------------------------------- // + // ----------------------- || THE SUN || ----------------------- // + // ------------------------------------------------------------- // + m_SunLight = new LightClass; m_SunLight->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); // White m_SunLight->SetDirection(0.0f, -1.0f, 0.0f); m_SunLight->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f); - m_SunLight->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f); - m_SunLight->SetSpecularPower(16.0f); m_SunLight->SetPosition(0.0f, 100.0f, 0.0f); + m_SunLight->SetIntensity(1.0f); // Create and initialize the normal map shader object. m_ShaderManager = new ShaderManagerClass; @@ -1944,7 +1946,7 @@ bool ApplicationClass::RenderPass(const std::vectorRenderSunlightShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, - object->GetTexture(0), m_SunLight->GetDiffuseColor(), m_SunLight->GetAmbientColor(), m_SunLight->GetDirection()); + object->GetTexture(0), m_SunLight->GetDiffuseColor(), m_SunLight->GetAmbientColor(), m_SunLight->GetDirection(), m_SunLight->GetIntensity()); if (!result) { Logger::Get().Log("Could not render the object model using the sunlight shader", __FILE__, __LINE__, Logger::LogLevel::Error); diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h index b4d4200..d61994b 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -99,6 +99,8 @@ public: void DeleteLight(int index); void AddLight(); std::vector GetLights() const { return m_Lights; }; + LightClass* GetSunLight() const { return m_SunLight; }; + bool GetShouldQuit() const { return m_ShouldQuit; }; void SetShouldQuit(bool shouldQuit) { m_ShouldQuit = shouldQuit; }; diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index c490a08..d254183 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -23,8 +23,9 @@ DockId=0x00000009,0 [Window][Light] Pos=8,27 -Size=330,487 +Size=290,826 Collapsed=0 +DockId=0x00000009,1 [Window][Shader Manager] Pos=8,27 @@ -78,7 +79,7 @@ DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=8,27 Size=1568,826 Split=Y DockNode ID=0x0000000D Parent=0xCCBD8CF7 SizeRef=1568,598 Split=Y DockNode ID=0x0000000B Parent=0x0000000D SizeRef=1568,637 Split=X DockNode ID=0x00000007 Parent=0x0000000B SizeRef=290,826 Split=Y Selected=0x393905AB - DockNode ID=0x00000009 Parent=0x00000007 SizeRef=395,413 Selected=0x393905AB + DockNode ID=0x00000009 Parent=0x00000007 SizeRef=395,413 Selected=0x321620B2 DockNode ID=0x0000000A Parent=0x00000007 SizeRef=395,411 Selected=0x031DC75C DockNode ID=0x00000008 Parent=0x0000000B SizeRef=1276,826 Split=X DockNode ID=0x00000002 Parent=0x00000008 SizeRef=878,826 CentralNode=1 Selected=0x9204953B diff --git a/enginecustom/imguiManager.cpp b/enginecustom/imguiManager.cpp index ee394d4..75003ac 100644 --- a/enginecustom/imguiManager.cpp +++ b/enginecustom/imguiManager.cpp @@ -438,8 +438,38 @@ bool imguiManager::ImGuiWidgetRenderer(ApplicationClass* app) void imguiManager::WidgetLightWindow(ApplicationClass* app) { ImGui::Begin("Light", &showLightWindow); + + + // Sun light settings + LightClass* sunLight = app->GetSunLight(); + // Direction input + XMFLOAT3 direction = sunLight->GetDirection(); + float dir[3] = { direction.x, direction.y, direction.z }; + if (ImGui::DragFloat3("Sun Direction", dir)) + { + sunLight->SetDirection(dir[0], dir[1], dir[2]); + } + // Color input + XMFLOAT4 color = sunLight->GetDiffuseColor(); + float col[3] = { color.x, color.y, color.z }; + if (ImGui::ColorEdit3("Sun Color", col)) + { + sunLight->SetDiffuseColor(col[0], col[1], col[2], 1.0f); + } + // Intensity input + float intensity = sunLight->GetIntensity(); + if (ImGui::DragFloat("Sun Intensity", &intensity, 0.1f, 0.0f, 100.0f)) + { + sunLight->SetIntensity(intensity); + } + + + ImGui::Separator(); + int index = 0; + // Area light settings + for(auto& light : app->GetLights()) { std::string headerName = "Light " + std::to_string(index); diff --git a/enginecustom/lightclass.h b/enginecustom/lightclass.h index 65dda80..e96c8f7 100644 --- a/enginecustom/lightclass.h +++ b/enginecustom/lightclass.h @@ -36,12 +36,16 @@ public: XMFLOAT4 GetSpecularColor(); float GetSpecularPower(); XMFLOAT4 GetPosition(); + + void SetIntensity(float intensity) { m_intensity = intensity; } + float GetIntensity() const { return m_intensity; } private: XMFLOAT4 m_ambientColor; XMFLOAT4 m_diffuseColor; XMFLOAT3 m_direction; XMFLOAT4 m_specularColor; + float m_intensity; float m_specularPower; XMFLOAT4 m_position; }; diff --git a/enginecustom/shadermanagerclass.cpp b/enginecustom/shadermanagerclass.cpp index 8157e6d..582dd24 100644 --- a/enginecustom/shadermanagerclass.cpp +++ b/enginecustom/shadermanagerclass.cpp @@ -436,11 +436,11 @@ bool ShaderManagerClass::RenderCelShadingShader(ID3D11DeviceContext* deviceConte } bool ShaderManagerClass::RenderSunlightShader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, - ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor, XMFLOAT4 ambientColor, XMFLOAT3 sunDirection) + ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor, XMFLOAT4 ambientColor, XMFLOAT3 sunDirection, float sunIntensity) { bool result; - result = m_SunlightShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection); + result = m_SunlightShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity); if (!result) { return false; diff --git a/enginecustom/shadermanagerclass.h b/enginecustom/shadermanagerclass.h index 7858495..d4a00bd 100644 --- a/enginecustom/shadermanagerclass.h +++ b/enginecustom/shadermanagerclass.h @@ -43,7 +43,7 @@ public: bool RenderRefractionShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[], XMFLOAT4); bool RenderWaterShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, float, float); bool RenderCelShadingShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4, XMFLOAT3); - bool RenderSunlightShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3); + bool RenderSunlightShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float); private: TextureShaderClass* m_TextureShader; NormalMapShaderClass* m_NormalMapShader; diff --git a/enginecustom/sunlight.ps b/enginecustom/sunlight.ps index 60fe950..bf13fa7 100644 --- a/enginecustom/sunlight.ps +++ b/enginecustom/sunlight.ps @@ -8,6 +8,7 @@ cbuffer SunLightBuffer float4 ambientColor; float4 diffuseColor; float3 lightDirection; + float intensity; }; cbuffer SunLightColorBuffer @@ -24,6 +25,7 @@ struct PixelInputType float2 tex : TEXCOORD0; float3 normal : NORMAL; float3 lightDir : TEXCOORD1; + float intensity : TEXCOORD2; }; //////////////////////////////////////////////////////////////////////////////// @@ -42,7 +44,7 @@ float4 SunLightPixelShader(PixelInputType input) : SV_TARGET textureColor = shaderTexture.Sample(SampleType, input.tex); // Calculate the different amounts of light on this pixel based on the direction of the light. - lightIntensity = saturate(dot(input.normal, input.lightDir)); + lightIntensity = saturate(dot(input.normal, input.lightDir)) * input.intensity; // Determine the diffuse color amount of the light. colorArray = diffuseColor * lightIntensity; diff --git a/enginecustom/sunlight.vs b/enginecustom/sunlight.vs index 9f5e800..8c2a64b 100644 --- a/enginecustom/sunlight.vs +++ b/enginecustom/sunlight.vs @@ -19,8 +19,7 @@ cbuffer SunLightBuffer float4 ambientColor; float4 diffuseColor; float3 lightDirection; - float specularPower; - float4 specularColor; + float intensity; }; ////////////// @@ -39,6 +38,7 @@ struct PixelInputType float2 tex : TEXCOORD0; float3 normal : NORMAL; float3 lightDir : TEXCOORD1; + float intensity : TEXCOORD2; }; //////////////////////////////////////////////////////////////////////////////// @@ -67,6 +67,8 @@ PixelInputType SunLightVertexShader(VertexInputType input) // Use the light direction directly. output.lightDir = normalize(lightDirection); + + output.intensity = intensity; return output; } diff --git a/enginecustom/sunlightshaderclass.cpp b/enginecustom/sunlightshaderclass.cpp index 44280c4..6ca20d7 100644 --- a/enginecustom/sunlightshaderclass.cpp +++ b/enginecustom/sunlightshaderclass.cpp @@ -75,13 +75,13 @@ void SunlightShaderClass::Shutdown() } bool SunlightShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, - ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor, XMFLOAT4 ambientColor, XMFLOAT3 sunDirection) + ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor, XMFLOAT4 ambientColor, XMFLOAT3 sunDirection, float sunIntensity) { bool result; // Set the shader parameters that it will use for rendering. - result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection); + result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity); if (!result) { Logger::Get().Log("Failed to set shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); @@ -374,7 +374,7 @@ void SunlightShaderClass::OutputShaderErrorMessage(ID3D10Blob* errorMessage, HWN } -bool SunlightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, ID3D11ShaderResourceView* texture, XMFLOAT4 ambientColor, XMFLOAT4 diffuseColor, XMFLOAT3 lightDirection) +bool SunlightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, ID3D11ShaderResourceView* texture, XMFLOAT4 ambientColor, XMFLOAT4 diffuseColor, XMFLOAT3 lightDirection, float sunIntensity) { HRESULT result; D3D11_MAPPED_SUBRESOURCE mappedResource; @@ -426,6 +426,7 @@ bool SunlightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext dataPtr3->ambientColor = ambientColor; dataPtr3->diffuseColor = diffuseColor; dataPtr3->sunDirection = lightDirection; + dataPtr3->intensity = sunIntensity; // Unlock the constant buffer. deviceContext->Unmap(m_sunlightBuffer, 0); @@ -442,9 +443,6 @@ bool SunlightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext return true; } - - - void SunlightShaderClass::RenderShader(ID3D11DeviceContext* deviceContext, int indexCount) { // Set the vertex input layout. diff --git a/enginecustom/sunlightshaderclass.h b/enginecustom/sunlightshaderclass.h index 4118998..84fa982 100644 --- a/enginecustom/sunlightshaderclass.h +++ b/enginecustom/sunlightshaderclass.h @@ -30,7 +30,7 @@ private : XMFLOAT4 diffuseColor; XMFLOAT4 ambientColor; XMFLOAT3 sunDirection; - float padding; // Ajoutez un padding pour aligner la structure sur 16 octets + float intensity; }; struct SunLightColorBufferType @@ -45,14 +45,14 @@ public : bool Initialize(ID3D11Device*, HWND); void Shutdown(); - bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3); + bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3,float); private: bool InitializeShader(ID3D11Device*, HWND, WCHAR*, WCHAR*); void ShutdownShader(); void OutputShaderErrorMessage(ID3D10Blob*, HWND, WCHAR*); - bool SetShaderParameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3); + bool SetShaderParameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float); void RenderShader(ID3D11DeviceContext*, int); private: