Minor: Ajout Specular map shader dans le shader manager

This commit is contained in:
GolfOcean334 2024-04-08 17:48:52 +02:00
parent e502033b89
commit a947a04946
4 changed files with 62 additions and 52 deletions

View File

@ -20,7 +20,6 @@ ApplicationClass::ApplicationClass()
m_Fps = 0; m_Fps = 0;
m_FpsString = 0; m_FpsString = 0;
m_ShaderManager = 0; m_ShaderManager = 0;
m_SpecMapShader = 0;
m_RenderCountString = 0; m_RenderCountString = 0;
m_ModelList = 0; m_ModelList = 0;
m_Position = 0; m_Position = 0;
@ -80,16 +79,6 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
m_Camera->Render(); m_Camera->Render();
m_Camera->GetViewMatrix(m_baseViewMatrix); m_Camera->GetViewMatrix(m_baseViewMatrix);
// Create and initialize the specular map shader object.
m_SpecMapShader = new SpecMapShaderClass;
result = m_SpecMapShader->Initialize(m_Direct3D->GetDevice(), hwnd);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the specular map shader object.", L"Error", MB_OK);
return false;
}
// Create and initialize the font shader object. // Create and initialize the font shader object.
m_FontShader = new FontShaderClass; m_FontShader = new FontShaderClass;
@ -270,16 +259,24 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
m_Lights[0].SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); // White m_Lights[0].SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); // White
m_Lights[0].SetPosition(10.0f, -5.0f, -15.0f); m_Lights[0].SetPosition(10.0f, -5.0f, -15.0f);
m_Lights[0].SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
m_Lights[0].SetSpecularPower(16.0f);
// Manually set the color and position of each light. // Manually set the color and position of each light.
m_Lights[1].SetDiffuseColor(1.0f, 0.0f, 0.0f, 1.0f); // Red m_Lights[1].SetDiffuseColor(1.0f, 0.0f, 0.0f, 1.0f); // Red
m_Lights[1].SetPosition(-3.0f, 1.0f, 3.0f); m_Lights[1].SetPosition(-3.0f, 1.0f, 3.0f);
m_Lights[1].SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
m_Lights[1].SetSpecularPower(16.0f);
m_Lights[2].SetDiffuseColor(0.0f, 1.0f, 0.0f, 1.0f); // Green m_Lights[2].SetDiffuseColor(0.0f, 1.0f, 0.0f, 1.0f); // Green
m_Lights[2].SetPosition(3.0f, 1.0f, 3.0f); m_Lights[2].SetPosition(3.0f, 1.0f, 3.0f);
m_Lights[2].SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
m_Lights[2].SetSpecularPower(16.0f);
m_Lights[3].SetDiffuseColor(0.0f, 0.0f, 1.0f, 1.0f); // Blue m_Lights[3].SetDiffuseColor(0.0f, 0.0f, 1.0f, 1.0f); // Blue
m_Lights[3].SetPosition(-3.0f, 1.0f, -3.0f); m_Lights[3].SetPosition(-3.0f, 1.0f, -3.0f);
m_Lights[3].SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
m_Lights[3].SetSpecularPower(16.0f);
// Create and initialize the normal map shader object. // Create and initialize the normal map shader object.
@ -513,16 +510,6 @@ void ApplicationClass::Shutdown()
m_LightShader = 0; m_LightShader = 0;
} }
// Release the specular map shader object.
if (m_SpecMapShader)
{
m_SpecMapShader->Shutdown();
delete m_SpecMapShader;
m_SpecMapShader = 0;
}
// Release the model object. // Release the model object.
if (m_Model) if (m_Model)
{ {
@ -949,7 +936,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
translateMatrix = XMMatrixTranslation(-5.0f, 1.0f, -20.0f); translateMatrix = XMMatrixTranslation(-5.0f, 1.0f, -20.0f);
worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix); worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
// Render the model using the Translation shader. // Render the model using the alpha map shader.
m_Model->Render(m_Direct3D->GetDeviceContext()); m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderAlphaMapShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, result = m_ShaderManager->RenderAlphaMapShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
@ -979,7 +966,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
translateMatrix = XMMatrixTranslation(0.0f, 1.0f, -20.0f); translateMatrix = XMMatrixTranslation(0.0f, 1.0f, -20.0f);
worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix); worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
// Render the model using the light shader. // Render the model using the render map shader.
m_Model->Render(m_Direct3D->GetDeviceContext()); m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderNormalMapShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, result = m_ShaderManager->RenderNormalMapShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
@ -995,7 +982,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
translateMatrix = XMMatrixTranslation(0.0f, -2.0f, -20.0f); translateMatrix = XMMatrixTranslation(0.0f, -2.0f, -20.0f);
worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix); worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
// Render the model using the normal map shader. // Render the model using the multitexture shader.
m_Model->Render(m_Direct3D->GetDeviceContext()); m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderMultitextureShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, result = m_ShaderManager->RenderMultitextureShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
@ -1011,7 +998,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
translateMatrix = XMMatrixTranslation(0.0f, -5.0f, -20.0f); translateMatrix = XMMatrixTranslation(0.0f, -5.0f, -20.0f);
worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix); worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
// Render the model using the Multitexture shader. // Render the model using the translate shader.
m_Model->Render(m_Direct3D->GetDeviceContext()); m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderTranslateShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, result = m_ShaderManager->RenderTranslateShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
@ -1026,10 +1013,16 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
translateMatrix = XMMatrixTranslation(-5.0f, -2.0f, -20.0f); translateMatrix = XMMatrixTranslation(-5.0f, -2.0f, -20.0f);
worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix); worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
// Render the model using the Translation shader. // Render the model using the specular map shader.
m_Model->Render(m_Direct3D->GetDeviceContext()); m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderSpecMapShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(0), m_Model->GetTexture(1), m_Model->GetTexture(2), m_Lights->GetDirection(), m_Lights->GetDiffuseColor(),
m_Camera->GetPosition(), m_Lights->GetSpecularColor(), m_Lights->GetSpecularPower());
if (!result)
{
return false;
}
// Lighting, utilise plusieurs lights donc Multiple Points Lighting // Lighting, utilise plusieurs lights donc Multiple Points Lighting
@ -1067,26 +1060,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
//// Render the model using the multitexture shader. //// Render the model using the multitexture shader.
//m_Model->Render(m_Direct3D->GetDeviceContext()); //m_Model->Render(m_Direct3D->GetDeviceContext());
////Normal Mapping
//result = m_NormalMapShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
// m_Model->GetTexture(0), m_Model->GetTexture(1), m_Light->GetDirection(), m_Light->GetDiffuseColor());
//if (!result)
//{
// return false;
//}
//scaleMatrix = XMMatrixScaling(1.0f, 1.0f, 1.0f); // Build the scaling matrix.
//rotateMatrix = XMMatrixRotationY(40); // Build the rotation matrix.
//translateMatrix = XMMatrixTranslation(0, 5.0f, -10.0f); // Build the translation matrix.
//// Multiply the scale, rotation, and translation matrices together to create the final world transformation matrix.
//srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
//worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
//// Render the model using the multitexture shader.
//m_Model->Render(m_Direct3D->GetDeviceContext());
// Enable the Z buffer and disable alpha blending now that 2D rendering is complete. // Enable the Z buffer and disable alpha blending now that 2D rendering is complete.
m_Direct3D->TurnZBufferOn(); m_Direct3D->TurnZBufferOn();
m_Direct3D->DisableAlphaBlending(); m_Direct3D->DisableAlphaBlending();

View File

@ -20,8 +20,6 @@
#include "textclass.h" #include "textclass.h"
#include "fpsclass.h" #include "fpsclass.h"
#include "inputclass.h" #include "inputclass.h"
#include "normalmapshaderclass.h"
#include "specmapshaderclass.h"
#include "shadermanagerclass.h" #include "shadermanagerclass.h"
#include "modellistclass.h" #include "modellistclass.h"
#include "positionclass.h" #include "positionclass.h"
@ -80,7 +78,6 @@ private:
FpsClass* m_Fps; FpsClass* m_Fps;
TextClass* m_FpsString; TextClass* m_FpsString;
int m_previousFps; int m_previousFps;
SpecMapShaderClass* m_SpecMapShader;
ShaderManagerClass* m_ShaderManager; ShaderManagerClass* m_ShaderManager;
ModelListClass* m_ModelList; ModelListClass* m_ModelList;
PositionClass* m_Position; PositionClass* m_Position;

View File

@ -7,6 +7,7 @@ ShaderManagerClass::ShaderManagerClass()
m_MultitextureShader = 0; m_MultitextureShader = 0;
m_TranslateShader = 0; m_TranslateShader = 0;
m_AlphaMapShader = 0; m_AlphaMapShader = 0;
m_SpecMapShader = 0;
} }
@ -60,7 +61,7 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd)
return false; return false;
} }
// Create and initialize the translate shader object. // Create and initialize the alpha map shader object.
m_AlphaMapShader = new AlphaMapShaderClass; m_AlphaMapShader = new AlphaMapShaderClass;
result = m_AlphaMapShader->Initialize(device, hwnd); result = m_AlphaMapShader->Initialize(device, hwnd);
@ -69,6 +70,15 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd)
return false; return false;
} }
// Create and initialize the specular map shader object.
m_SpecMapShader = new SpecMapShaderClass;
result = m_SpecMapShader->Initialize(device, hwnd);
if (!result)
{
return false;
}
return true; return true;
} }
@ -114,6 +124,14 @@ void ShaderManagerClass::Shutdown()
m_AlphaMapShader = 0; m_AlphaMapShader = 0;
} }
// Release the specular map shader object.
if (m_SpecMapShader)
{
m_SpecMapShader->Shutdown();
delete m_SpecMapShader;
m_SpecMapShader = 0;
}
return; return;
} }
@ -190,5 +208,22 @@ bool ShaderManagerClass::RenderAlphaMapShader(ID3D11DeviceContext* deviceContext
return false; return false;
} }
return true;
}
bool ShaderManagerClass::RenderSpecMapShader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
ID3D11ShaderResourceView* texture1, ID3D11ShaderResourceView* texture2, ID3D11ShaderResourceView* texture3,
XMFLOAT3 lightDirection, XMFLOAT4 diffuseColor, XMFLOAT3 cameraPosition, XMFLOAT4 specularColor, float specularPower)
{
bool result;
result = m_SpecMapShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2, texture3, lightDirection,
diffuseColor, cameraPosition, specularColor, specularPower);
if (!result)
{
return false;
}
return true; return true;
} }

View File

@ -10,6 +10,7 @@
#include "Multitextureshaderclass.h" #include "Multitextureshaderclass.h"
#include "translateshaderclass.h" #include "translateshaderclass.h"
#include "alphamapshaderclass.h" #include "alphamapshaderclass.h"
#include "specmapshaderclass.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -29,6 +30,8 @@ public:
bool RenderMultitextureShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*); bool RenderMultitextureShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*);
bool RenderTranslateShader(ID3D11DeviceContext*,int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, float); bool RenderTranslateShader(ID3D11DeviceContext*,int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, float);
bool RenderAlphaMapShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*); bool RenderAlphaMapShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*);
bool RenderSpecMapShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*,
XMFLOAT3, XMFLOAT4, XMFLOAT3, XMFLOAT4, float);
private: private:
TextureShaderClass* m_TextureShader; TextureShaderClass* m_TextureShader;
@ -36,6 +39,7 @@ private:
MultiTextureShaderClass* m_MultitextureShader; MultiTextureShaderClass* m_MultitextureShader;
TranslateShaderClass* m_TranslateShader; TranslateShaderClass* m_TranslateShader;
AlphaMapShaderClass* m_AlphaMapShader; AlphaMapShaderClass* m_AlphaMapShader;
SpecMapShaderClass* m_SpecMapShader;
}; };
#endif #endif