Fix Update: direction de la lumière prise en compte pour le water shader
This commit is contained in:
parent
7160ad922c
commit
6841255bf9
@ -703,7 +703,9 @@ bool ApplicationClass::Frame(InputClass* Input)
|
|||||||
bool ApplicationClass::RenderRefractionToTexture()
|
bool ApplicationClass::RenderRefractionToTexture()
|
||||||
{
|
{
|
||||||
XMMATRIX worldMatrix, viewMatrix, projectionMatrix;
|
XMMATRIX worldMatrix, viewMatrix, projectionMatrix;
|
||||||
|
XMFLOAT4 diffuseColor[4], lightPosition[4], ambientColor[4];
|
||||||
XMFLOAT4 clipPlane;
|
XMFLOAT4 clipPlane;
|
||||||
|
int i;
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
// Setup a clipping plane based on the height of the water to clip everything above it.
|
// 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_Camera->GetViewMatrix(viewMatrix);
|
||||||
m_Direct3D->GetProjectionMatrix(projectionMatrix);
|
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.
|
// Translate to where the bath model will be rendered.
|
||||||
worldMatrix = XMMatrixTranslation(0.0f, -10.0f, 0.0f);
|
worldMatrix = XMMatrixTranslation(0.0f, -10.0f, 0.0f);
|
||||||
|
|
||||||
@ -728,7 +743,7 @@ bool ApplicationClass::RenderRefractionToTexture()
|
|||||||
m_BathModel->Render(m_Direct3D->GetDeviceContext());
|
m_BathModel->Render(m_Direct3D->GetDeviceContext());
|
||||||
|
|
||||||
result = m_ShaderManager->RenderRefractionShader(m_Direct3D->GetDeviceContext(), m_BathModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
|
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)
|
if (!result)
|
||||||
{
|
{
|
||||||
return false;
|
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,
|
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_ReflectionTexture->GetShaderResourceView(), m_RefractionTexture->GetShaderResourceView(), m_WaterModel->GetTexture(0),
|
||||||
m_waterTranslation, 0.01f);
|
m_waterTranslation, 0.01f);
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Setup matrices.
|
// Setup matrices.
|
||||||
rotateMatrix = XMMatrixRotationY(rotation);
|
rotateMatrix = XMMatrixRotationY(rotation);
|
||||||
translateMatrix = XMMatrixTranslation(-5.0f, 1.0f, -20.0f);
|
translateMatrix = XMMatrixTranslation(-5.0f, 1.0f, -20.0f);
|
||||||
|
@ -64,13 +64,13 @@ void RefractionShaderClass::Shutdown()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool RefractionShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
|
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;
|
bool result;
|
||||||
|
|
||||||
|
|
||||||
// Set the shader parameters that it will use for rendering.
|
// 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)
|
if (!result)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -361,7 +361,7 @@ void RefractionShaderClass::OutputShaderErrorMessage(ID3D10Blob* errorMessage, H
|
|||||||
|
|
||||||
|
|
||||||
bool RefractionShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
|
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;
|
HRESULT result;
|
||||||
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
||||||
@ -436,8 +436,9 @@ bool RefractionShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceConte
|
|||||||
dataPtr3 = (LightBufferType*)mappedResource.pData;
|
dataPtr3 = (LightBufferType*)mappedResource.pData;
|
||||||
|
|
||||||
// Copy the lighting variables into the constant buffer.
|
// Copy the lighting variables into the constant buffer.
|
||||||
dataPtr3->ambientColor = ambientColor;
|
dataPtr3->ambientColor = ambientColor[0];
|
||||||
dataPtr3->diffuseColor = diffuseColor;
|
dataPtr3->diffuseColor = diffuseColor[0];
|
||||||
|
dataPtr3->lightPosition = lightPosition[0];
|
||||||
dataPtr3->lightDirection = lightDirection;
|
dataPtr3->lightDirection = lightDirection;
|
||||||
|
|
||||||
// Unlock the constant buffer.
|
// Unlock the constant buffer.
|
||||||
|
@ -30,6 +30,7 @@ private:
|
|||||||
{
|
{
|
||||||
XMFLOAT4 ambientColor;
|
XMFLOAT4 ambientColor;
|
||||||
XMFLOAT4 diffuseColor;
|
XMFLOAT4 diffuseColor;
|
||||||
|
XMFLOAT4 lightPosition;
|
||||||
XMFLOAT3 lightDirection;
|
XMFLOAT3 lightDirection;
|
||||||
float padding;
|
float padding;
|
||||||
};
|
};
|
||||||
@ -47,7 +48,7 @@ public:
|
|||||||
bool Initialize(ID3D11Device*, HWND);
|
bool Initialize(ID3D11Device*, HWND);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*,
|
bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*,
|
||||||
XMFLOAT3, XMFLOAT4, XMFLOAT4, XMFLOAT4);
|
XMFLOAT3, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[], XMFLOAT4);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool InitializeShader(ID3D11Device*, HWND, WCHAR*, WCHAR*);
|
bool InitializeShader(ID3D11Device*, HWND, WCHAR*, WCHAR*);
|
||||||
@ -55,7 +56,7 @@ private:
|
|||||||
void OutputShaderErrorMessage(ID3D10Blob*, HWND, WCHAR*);
|
void OutputShaderErrorMessage(ID3D10Blob*, HWND, WCHAR*);
|
||||||
|
|
||||||
bool SetShaderParameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*,
|
bool SetShaderParameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*,
|
||||||
XMFLOAT3, XMFLOAT4, XMFLOAT4, XMFLOAT4);
|
XMFLOAT3, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[], XMFLOAT4);
|
||||||
void RenderShader(ID3D11DeviceContext*, int);
|
void RenderShader(ID3D11DeviceContext*, int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -364,12 +364,12 @@ bool ShaderManagerClass::RenderlightMapShader(ID3D11DeviceContext* deviceContext
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ShaderManagerClass::RenderRefractionShader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
|
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;
|
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)
|
if (!result)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
bool RenderlightShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[]);
|
bool RenderlightShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[]);
|
||||||
bool RenderlightMapShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*);
|
bool RenderlightMapShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*);
|
||||||
bool RenderRefractionShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, 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*,
|
bool RenderWaterShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*,
|
||||||
ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, float, float);
|
ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, float, float);
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user