minor update - light ui tweak

This commit is contained in:
CatChow0 2025-01-23 20:55:55 +01:00
parent c355509870
commit d8851cc679
12 changed files with 66 additions and 21 deletions

View File

@ -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;
};

View File

@ -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::vector<std::reference_wrapper<std::
case Object::SUNLIGHT:
result = m_ShaderManager->RenderSunlightShader(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);

View File

@ -99,6 +99,8 @@ public:
void DeleteLight(int index);
void AddLight();
std::vector<LightClass*> GetLights() const { return m_Lights; };
LightClass* GetSunLight() const { return m_SunLight; };
bool GetShouldQuit() const { return m_ShouldQuit; };
void SetShouldQuit(bool shouldQuit) { m_ShouldQuit = shouldQuit; };

View File

@ -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

View File

@ -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);

View File

@ -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;
};

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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.

View File

@ -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: