From e502033b895eb15a06623e6c413a8a147a9474c7 Mon Sep 17 00:00:00 2001 From: GolfOcean334 <130740013+GolfOcean334@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:11:58 +0200 Subject: [PATCH] Fix: Normal Shader --- enginecustom/Light.vs | 4 -- enginecustom/applicationclass.cpp | 106 ++++++++++------------------ enginecustom/applicationclass.h | 4 +- enginecustom/light.vs | 4 -- enginecustom/shadermanagerclass.cpp | 42 ----------- enginecustom/shadermanagerclass.h | 2 - 6 files changed, 38 insertions(+), 124 deletions(-) diff --git a/enginecustom/Light.vs b/enginecustom/Light.vs index 81923e6..8e32839 100644 --- a/enginecustom/Light.vs +++ b/enginecustom/Light.vs @@ -1,7 +1,3 @@ -//////////////////////////////////////////////////////////////////////////////// -// Filename: light.vs -//////////////////////////////////////////////////////////////////////////////// - ///////////// // DEFINES // ///////////// diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index b8c10c9..1ce12e9 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -6,7 +6,6 @@ ApplicationClass::ApplicationClass() m_Camera = 0; m_Model = 0; m_LightShader = 0; - m_LightMapShader = 0; m_Light = 0; m_TextureShader = 0; m_Bitmap = 0; @@ -21,7 +20,6 @@ ApplicationClass::ApplicationClass() m_Fps = 0; m_FpsString = 0; m_ShaderManager = 0; - m_NormalMapShader = 0; m_SpecMapShader = 0; m_RenderCountString = 0; m_ModelList = 0; @@ -92,16 +90,6 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) return false; } - // Create and initialize the normal map shader object. - m_NormalMapShader = new NormalMapShaderClass; - - result = m_NormalMapShader->Initialize(m_Direct3D->GetDevice(), hwnd); - if (!result) - { - MessageBox(hwnd, L"Could not initialize the normal map shader object.", L"Error", MB_OK); - return false; - } - // Create and initialize the font shader object. m_FontShader = new FontShaderClass; @@ -280,20 +268,20 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) // Create and initialize the light objects array. m_Lights = new LightClass[m_numLights]; + m_Lights[0].SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); // White + m_Lights[0].SetPosition(10.0f, -5.0f, -15.0f); + // Manually set the color and position of each light. - m_Lights[0].SetDiffuseColor(1.0f, 0.0f, 0.0f, 1.0f); // Red - m_Lights[0].SetPosition(-3.0f, 1.0f, 3.0f); + 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].SetDiffuseColor(0.0f, 1.0f, 0.0f, 1.0f); // Green - m_Lights[1].SetPosition(3.0f, 1.0f, 3.0f); - - m_Lights[2].SetDiffuseColor(0.0f, 0.0f, 1.0f, 1.0f); // Blue - m_Lights[2].SetPosition(-3.0f, 1.0f, -3.0f); - - m_Lights[3].SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); // White - m_Lights[3].SetPosition(3.0f, 1.0f, -3.0f); + 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[3].SetDiffuseColor(0.0f, 0.0f, 1.0f, 1.0f); // Blue + m_Lights[3].SetPosition(-3.0f, 1.0f, -3.0f); + // Create and initialize the normal map shader object. m_ShaderManager = new ShaderManagerClass; @@ -303,15 +291,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) return false; } - // Create and initialize the light map shader object. - m_LightMapShader = new LightMapShaderClass; - - result = m_LightMapShader->Initialize(m_Direct3D->GetDevice(), hwnd); - if (!result) - { - MessageBox(hwnd, L"Could not initialize the light map shader object.", L"Error", MB_OK); - return false; - } + // Create and initialize the font shader object. m_FontShader = new FontShaderClass; @@ -386,6 +366,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) void ApplicationClass::Shutdown() { + // Release the shader manager object. if (m_ShaderManager) { @@ -532,13 +513,7 @@ void ApplicationClass::Shutdown() m_LightShader = 0; } - // Release the normal map shader object. - if (m_NormalMapShader) - { - m_NormalMapShader->Shutdown(); - delete m_NormalMapShader; - m_NormalMapShader = 0; - } + // Release the specular map shader object. if (m_SpecMapShader) @@ -759,6 +734,11 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t // Render the display plane using the texture shader and the render texture resource. m_DisplayPlane->Render(m_Direct3D->GetDeviceContext()); + result = m_TextureShader->Render(m_Direct3D->GetDeviceContext(), m_DisplayPlane->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_RenderTexture->GetShaderResourceView()); + if (!result) + { + return false; + } // Setup matrices - Bottom left display plane. worldMatrix = XMMatrixTranslation(-1.5f, -1.5f, 0.0f); @@ -966,7 +946,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t // Setup matrices. rotateMatrix = XMMatrixRotationY(rotation); - translateMatrix = XMMatrixTranslation(0.0f, 7.0f, 0.0f); + translateMatrix = XMMatrixTranslation(-5.0f, 1.0f, -20.0f); worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix); // Render the model using the Translation shader. @@ -981,7 +961,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t // Setup matrices. rotateMatrix = XMMatrixRotationY(rotation); - translateMatrix = XMMatrixTranslation(0.0f, 4.0f, 0.0f); + translateMatrix = XMMatrixTranslation(-5.0f, -5.0f, -20.0f); worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix); // Render the model using the texture shader. @@ -996,55 +976,42 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t // Setup matrices. rotateMatrix = XMMatrixRotationY(rotation); - translateMatrix = XMMatrixTranslation(0.0f, 1.0f, 0.0f); + translateMatrix = XMMatrixTranslation(0.0f, 1.0f, -20.0f); worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix); // Render the model using the light shader. m_Model->Render(m_Direct3D->GetDeviceContext()); - result = m_ShaderManager->RenderLightShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, - m_Model->GetTexture(0), m_Light->GetDirection(), m_Light->GetDiffuseColor()); + result = m_ShaderManager->RenderNormalMapShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, + m_Model->GetTexture(0), m_Model->GetTexture(1), m_Lights->GetDirection(), m_Lights->GetDiffuseColor()); if (!result) { return false; } + // Setup matrices. rotateMatrix = XMMatrixRotationY(rotation); - translateMatrix = XMMatrixTranslation(0.0f, -2.0f, 0.0f); + translateMatrix = XMMatrixTranslation(0.0f, -2.0f, -20.0f); worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix); // Render the model using the normal map shader. m_Model->Render(m_Direct3D->GetDeviceContext()); - result = m_ShaderManager->RenderNormalMapShader(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; - } - - // Setup matrices. - rotateMatrix = XMMatrixRotationY(rotation); - translateMatrix = XMMatrixTranslation(0.0f, -5.0f, 0.0f); - worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix); - - // Render the model using the Multitexture shader. - m_Model->Render(m_Direct3D->GetDeviceContext()); - result = m_ShaderManager->RenderMultitextureShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0), m_Model->GetTexture(5)); if (!result) { return false; } + // Setup matrices. rotateMatrix = XMMatrixRotationY(rotation); - translateMatrix = XMMatrixTranslation(0.0f, -8.0f, 0.0f); + translateMatrix = XMMatrixTranslation(0.0f, -5.0f, -20.0f); worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix); - // Render the model using the Translation shader. + // Render the model using the Multitexture shader. m_Model->Render(m_Direct3D->GetDeviceContext()); result = m_ShaderManager->RenderTranslateShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, @@ -1054,6 +1021,15 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t return false; } + // Setup matrices. + rotateMatrix = XMMatrixRotationY(rotation); + translateMatrix = XMMatrixTranslation(-5.0f, -2.0f, -20.0f); + worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix); + + // Render the model using the Translation shader. + m_Model->Render(m_Direct3D->GetDeviceContext()); + + // Lighting, utilise plusieurs lights donc Multiple Points Lighting @@ -1072,14 +1048,6 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t // return false; //} - // Alphamapping - /*result = m_AlphaMapShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, - m_Model->GetTexture(0), m_Model->GetTexture(1), m_Model->GetTexture(2)); - if (!result) - { - return false; - }*/ - ////Specular Mapping //result = m_SpecMapShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, // m_Model->GetTexture(0), m_Model->GetTexture(1), m_Model->GetTexture(2), m_Light->GetDirection(), m_Light->GetDiffuseColor(), diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h index 7fcab23..22954a0 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -66,14 +66,13 @@ private: LightShaderClass* m_LightShader; LightClass* m_Light; LightClass* m_Lights; - LightMapShaderClass* m_LightMapShader; + int m_numLights; ModelClass* m_Model; TextureShaderClass* m_TextureShader; BitmapClass* m_Bitmap; SpriteClass* m_Sprite; TimerClass* m_Timer; TextClass* m_MouseStrings; - int m_numLights; FontShaderClass* m_FontShader; TextClass* m_RenderCountString; FontClass* m_Font; @@ -81,7 +80,6 @@ private: FpsClass* m_Fps; TextClass* m_FpsString; int m_previousFps; - NormalMapShaderClass* m_NormalMapShader; SpecMapShaderClass* m_SpecMapShader; ShaderManagerClass* m_ShaderManager; ModelListClass* m_ModelList; diff --git a/enginecustom/light.vs b/enginecustom/light.vs index 81923e6..8e32839 100644 --- a/enginecustom/light.vs +++ b/enginecustom/light.vs @@ -1,7 +1,3 @@ -//////////////////////////////////////////////////////////////////////////////// -// Filename: light.vs -//////////////////////////////////////////////////////////////////////////////// - ///////////// // DEFINES // ///////////// diff --git a/enginecustom/shadermanagerclass.cpp b/enginecustom/shadermanagerclass.cpp index b54b959..9b582f8 100644 --- a/enginecustom/shadermanagerclass.cpp +++ b/enginecustom/shadermanagerclass.cpp @@ -3,7 +3,6 @@ ShaderManagerClass::ShaderManagerClass() { m_TextureShader = 0; - m_LightShader = 0; m_NormalMapShader = 0; m_MultitextureShader = 0; m_TranslateShader = 0; @@ -34,15 +33,6 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd) return false; } - // Create and initialize the light shader object. - m_LightShader = new LightShaderClass; - - result = m_LightShader->Initialize(device, hwnd); - if (!result) - { - return false; - } - // Create and initialize the normal map shader object. m_NormalMapShader = new NormalMapShaderClass; @@ -92,14 +82,6 @@ void ShaderManagerClass::Shutdown() m_NormalMapShader = 0; } - // Release the light shader object. - if (m_LightShader) - { - m_LightShader->Shutdown(); - delete m_LightShader; - m_LightShader = 0; - } - // Release the texture shader object. if (m_TextureShader) { @@ -151,30 +133,6 @@ bool ShaderManagerClass::RenderTextureShader(ID3D11DeviceContext* deviceContext, return true; } -bool ShaderManagerClass::RenderLightShader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, - ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 diffuseColor) -{ - bool result; - - // Allouer de la mémoire pour stocker XMFLOAT4 pour la direction de la lumière - XMFLOAT4* lightDirection4Ptr = new XMFLOAT4(lightDirection.x, lightDirection.y, lightDirection.z, 1.0f); - - // Allouer de la mémoire pour stocker XMFLOAT4 pour la couleur diffuse - XMFLOAT4* diffuseColorPtr = new XMFLOAT4(diffuseColor); - - result = m_LightShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection4Ptr, diffuseColorPtr); - if (!result) - { - delete lightDirection4Ptr; - delete diffuseColorPtr; - return false; - } - - delete lightDirection4Ptr; - delete diffuseColorPtr; - return true; -} - bool ShaderManagerClass::RenderNormalMapShader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, ID3D11ShaderResourceView* colorTexture, ID3D11ShaderResourceView* normalTexture, XMFLOAT3 lightDirection, XMFLOAT4 diffuseColor) { diff --git a/enginecustom/shadermanagerclass.h b/enginecustom/shadermanagerclass.h index e8ffdcd..117b5f8 100644 --- a/enginecustom/shadermanagerclass.h +++ b/enginecustom/shadermanagerclass.h @@ -25,7 +25,6 @@ public: bool Initialize(ID3D11Device*, HWND); void Shutdown(); bool RenderTextureShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*); - bool RenderLightShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4); bool RenderNormalMapShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4); bool RenderMultitextureShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*); bool RenderTranslateShader(ID3D11DeviceContext*,int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, float); @@ -33,7 +32,6 @@ public: private: TextureShaderClass* m_TextureShader; - LightShaderClass* m_LightShader; NormalMapShaderClass* m_NormalMapShader; MultiTextureShaderClass* m_MultitextureShader; TranslateShaderClass* m_TranslateShader;