From 6841255bf9eedad24e23b86c348a0b6bf0b31b73 Mon Sep 17 00:00:00 2001 From: GolfOcean334 <130740013+GolfOcean334@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:48:08 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20Update:=20direction=20de=20la=20lumi?= =?UTF-8?q?=C3=A8re=20prise=20en=20compte=20pour=20le=20water=20shader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- enginecustom/applicationclass.cpp | 20 +++++++++++++++++--- enginecustom/refractionshaderclass.cpp | 11 ++++++----- enginecustom/refractionshaderclass.h | 5 +++-- enginecustom/shadermanagerclass.cpp | 4 ++-- enginecustom/shadermanagerclass.h | 2 +- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index 7b5305d..960473d 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -703,7 +703,9 @@ bool ApplicationClass::Frame(InputClass* Input) bool ApplicationClass::RenderRefractionToTexture() { XMMATRIX worldMatrix, viewMatrix, projectionMatrix; + XMFLOAT4 diffuseColor[4], lightPosition[4], ambientColor[4]; XMFLOAT4 clipPlane; + int i; bool result; // Setup a clipping plane based on the height of the water to clip everything above it. @@ -721,6 +723,19 @@ bool ApplicationClass::RenderRefractionToTexture() m_Camera->GetViewMatrix(viewMatrix); m_Direct3D->GetProjectionMatrix(projectionMatrix); + // Get the light properties. + for (i = 0; i < m_numLights; i++) + { + // Create the diffuse color array from the four light colors. + diffuseColor[i] = m_Lights[i]->GetDiffuseColor(); + + // Create the light position array from the four light positions. + lightPosition[i] = m_Lights[i]->GetPosition(); + + // Create the light position array from the four light positions. + ambientColor[i] = m_Lights[i]->GetAmbientColor(); + } + // Translate to where the bath model will be rendered. worldMatrix = XMMatrixTranslation(0.0f, -10.0f, 0.0f); @@ -728,7 +743,7 @@ bool ApplicationClass::RenderRefractionToTexture() m_BathModel->Render(m_Direct3D->GetDeviceContext()); result = m_ShaderManager->RenderRefractionShader(m_Direct3D->GetDeviceContext(), m_BathModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, - m_BathModel->GetTexture(0), m_Lights[0]->GetDirection(), m_Lights[0]->GetAmbientColor(), m_Lights[0]->GetDiffuseColor(), clipPlane); + m_BathModel->GetTexture(0), m_Lights[0]->GetDirection(), ambientColor, diffuseColor, lightPosition, clipPlane); if (!result) { return false; @@ -1147,13 +1162,12 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t result = m_ShaderManager->RenderWaterShader(m_Direct3D->GetDeviceContext(), m_WaterModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, reflectionMatrix, m_ReflectionTexture->GetShaderResourceView(), m_RefractionTexture->GetShaderResourceView(), m_WaterModel->GetTexture(0), m_waterTranslation, 0.01f); + if (!result) { return false; } - - // Setup matrices. rotateMatrix = XMMatrixRotationY(rotation); translateMatrix = XMMatrixTranslation(-5.0f, 1.0f, -20.0f); diff --git a/enginecustom/refractionshaderclass.cpp b/enginecustom/refractionshaderclass.cpp index fc9f8d3..feeef3a 100644 --- a/enginecustom/refractionshaderclass.cpp +++ b/enginecustom/refractionshaderclass.cpp @@ -64,13 +64,13 @@ void RefractionShaderClass::Shutdown() } bool RefractionShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, - ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 ambientColor, XMFLOAT4 diffuseColor, XMFLOAT4 clipPlane) + ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 ambientColor[], XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[], XMFLOAT4 clipPlane) { bool result; // Set the shader parameters that it will use for rendering. - result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, ambientColor, diffuseColor, clipPlane); + result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, ambientColor, diffuseColor, lightPosition, clipPlane); if (!result) { return false; @@ -361,7 +361,7 @@ void RefractionShaderClass::OutputShaderErrorMessage(ID3D10Blob* errorMessage, H bool RefractionShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, - ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 ambientColor, XMFLOAT4 diffuseColor, XMFLOAT4 clipPlane) + ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 ambientColor[], XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[], XMFLOAT4 clipPlane) { HRESULT result; D3D11_MAPPED_SUBRESOURCE mappedResource; @@ -436,8 +436,9 @@ bool RefractionShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceConte dataPtr3 = (LightBufferType*)mappedResource.pData; // Copy the lighting variables into the constant buffer. - dataPtr3->ambientColor = ambientColor; - dataPtr3->diffuseColor = diffuseColor; + dataPtr3->ambientColor = ambientColor[0]; + dataPtr3->diffuseColor = diffuseColor[0]; + dataPtr3->lightPosition = lightPosition[0]; dataPtr3->lightDirection = lightDirection; // Unlock the constant buffer. diff --git a/enginecustom/refractionshaderclass.h b/enginecustom/refractionshaderclass.h index 1d38b5a..19e1ded 100644 --- a/enginecustom/refractionshaderclass.h +++ b/enginecustom/refractionshaderclass.h @@ -30,6 +30,7 @@ private: { XMFLOAT4 ambientColor; XMFLOAT4 diffuseColor; + XMFLOAT4 lightPosition; XMFLOAT3 lightDirection; float padding; }; @@ -47,7 +48,7 @@ public: bool Initialize(ID3D11Device*, HWND); void Shutdown(); bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, - XMFLOAT3, XMFLOAT4, XMFLOAT4, XMFLOAT4); + XMFLOAT3, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[], XMFLOAT4); private: bool InitializeShader(ID3D11Device*, HWND, WCHAR*, WCHAR*); @@ -55,7 +56,7 @@ private: void OutputShaderErrorMessage(ID3D10Blob*, HWND, WCHAR*); bool SetShaderParameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, - XMFLOAT3, XMFLOAT4, XMFLOAT4, XMFLOAT4); + XMFLOAT3, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[], XMFLOAT4); void RenderShader(ID3D11DeviceContext*, int); private: diff --git a/enginecustom/shadermanagerclass.cpp b/enginecustom/shadermanagerclass.cpp index 52c3be1..bd4cd80 100644 --- a/enginecustom/shadermanagerclass.cpp +++ b/enginecustom/shadermanagerclass.cpp @@ -364,12 +364,12 @@ bool ShaderManagerClass::RenderlightMapShader(ID3D11DeviceContext* deviceContext } bool ShaderManagerClass::RenderRefractionShader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, - ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 ambientColor, XMFLOAT4 diffuseColor, XMFLOAT4 clipPlane) + ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 ambientColor[], XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[], XMFLOAT4 clipPlane) { bool result; - result = m_RefractionShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, ambientColor, diffuseColor, clipPlane); + result = m_RefractionShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, ambientColor, diffuseColor, lightPosition, clipPlane); if (!result) { return false; diff --git a/enginecustom/shadermanagerclass.h b/enginecustom/shadermanagerclass.h index 2cfe230..1e68f72 100644 --- a/enginecustom/shadermanagerclass.h +++ b/enginecustom/shadermanagerclass.h @@ -40,7 +40,7 @@ public: bool RenderlightShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[]); bool RenderlightMapShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*); bool RenderRefractionShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, - XMFLOAT3, XMFLOAT4, XMFLOAT4, XMFLOAT4); + XMFLOAT3, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[], XMFLOAT4); bool RenderWaterShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, float, float); private: