From 9aea925c3d43d7cc4f017404c56c46a4e5eeb1a7 Mon Sep 17 00:00:00 2001 From: GolfOcean334 <130740013+GolfOcean334@users.noreply.github.com> Date: Mon, 8 Apr 2024 00:42:39 +0200 Subject: [PATCH] Minor: Ajout de l'alpha mapping au shader manager --- enginecustom/applicationclass.cpp | 54 ++++++++++------------------- enginecustom/applicationclass.h | 2 -- enginecustom/shadermanagerclass.cpp | 45 ++++++++++++++++++++---- enginecustom/shadermanagerclass.h | 3 ++ 4 files changed, 60 insertions(+), 44 deletions(-) diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index ad2e102..b8c10c9 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -3,8 +3,7 @@ ApplicationClass::ApplicationClass() { m_Direct3D = 0; - m_Camera = 0; - m_AlphaMapShader = 0; + m_Camera = 0; m_Model = 0; m_LightShader = 0; m_LightMapShader = 0; @@ -314,16 +313,6 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) return false; } - // Create and initialize the alpha map shader object. - m_AlphaMapShader = new AlphaMapShaderClass; - - result = m_AlphaMapShader->Initialize(m_Direct3D->GetDevice(), hwnd); - if (!result) - { - MessageBox(hwnd, L"Could not initialize the alpha map shader object.", L"Error", MB_OK); - return false; - } - // Create and initialize the font shader object. m_FontShader = new FontShaderClass; @@ -566,14 +555,6 @@ void ApplicationClass::Shutdown() delete m_Model; m_Model = 0; } - - // Release the alpha map shader object. - if (m_AlphaMapShader) - { - m_AlphaMapShader->Shutdown(); - delete m_AlphaMapShader; - m_AlphaMapShader = 0; - } } @@ -983,6 +964,21 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t //// Render the model using the multitexture shader. //m_Model->Render(m_Direct3D->GetDeviceContext()); + // Setup matrices. + rotateMatrix = XMMatrixRotationY(rotation); + translateMatrix = XMMatrixTranslation(0.0f, 7.0f, 0.0f); + worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix); + + // Render the model using the Translation shader. + m_Model->Render(m_Direct3D->GetDeviceContext()); + + result = m_ShaderManager->RenderAlphaMapShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, + m_Model->GetTexture(0), m_Model->GetTexture(5), m_Model->GetTexture(3)); + if (!result) + { + return false; + } + // Setup matrices. rotateMatrix = XMMatrixRotationY(rotation); translateMatrix = XMMatrixTranslation(0.0f, 4.0f, 0.0f); @@ -1058,6 +1054,8 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t return false; } + + // Lighting, utilise plusieurs lights donc Multiple Points Lighting //result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0), // diffuseColor, lightPosition); @@ -1074,14 +1072,6 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t // return false; //} - // MultiTexturing - //result = m_MultiTextureShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, - // m_Model->GetTexture(0), m_Model->GetTexture(1)); - //if (!result) - //{ - // 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)); @@ -1129,14 +1119,6 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t //// Render the model using the multitexture shader. //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; - //} - // Enable the Z buffer and disable alpha blending now that 2D rendering is complete. m_Direct3D->TurnZBufferOn(); m_Direct3D->DisableAlphaBlending(); diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h index 9d7a90d..7fcab23 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -11,7 +11,6 @@ #include "lightshaderclass.h" #include "lightclass.h" #include "lightmapshaderclass.h" -#include "alphamapshaderclass.h" #include "bitmapclass.h" #include "spriteclass.h" #include "textureshaderclass.h" @@ -68,7 +67,6 @@ private: LightClass* m_Light; LightClass* m_Lights; LightMapShaderClass* m_LightMapShader; - AlphaMapShaderClass* m_AlphaMapShader; ModelClass* m_Model; TextureShaderClass* m_TextureShader; BitmapClass* m_Bitmap; diff --git a/enginecustom/shadermanagerclass.cpp b/enginecustom/shadermanagerclass.cpp index 4588992..b54b959 100644 --- a/enginecustom/shadermanagerclass.cpp +++ b/enginecustom/shadermanagerclass.cpp @@ -7,6 +7,7 @@ ShaderManagerClass::ShaderManagerClass() m_NormalMapShader = 0; m_MultitextureShader = 0; m_TranslateShader = 0; + m_AlphaMapShader = 0; } @@ -69,6 +70,15 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd) return false; } + // Create and initialize the translate shader object. + m_AlphaMapShader = new AlphaMapShaderClass; + + result = m_AlphaMapShader->Initialize(device, hwnd); + if (!result) + { + return false; + } + return true; } @@ -98,6 +108,14 @@ void ShaderManagerClass::Shutdown() m_TextureShader = 0; } + // Release the multitexture shader object. + if (m_MultitextureShader) + { + m_MultitextureShader->Shutdown(); + delete m_MultitextureShader; + m_MultitextureShader = 0; + } + // Release the multitexture shader object. if (m_TranslateShader) { @@ -105,13 +123,13 @@ void ShaderManagerClass::Shutdown() delete m_TranslateShader; m_TranslateShader = 0; } - - // Release the multitexture shader object. - if (m_MultitextureShader) + + // Release the alpha map shader object. + if (m_AlphaMapShader) { - m_MultitextureShader->Shutdown(); - delete m_MultitextureShader; - m_MultitextureShader = 0; + m_AlphaMapShader->Shutdown(); + delete m_AlphaMapShader; + m_AlphaMapShader = 0; } return; @@ -199,5 +217,20 @@ bool ShaderManagerClass::RenderTranslateShader(ID3D11DeviceContext* deviceContex return false; } + return true; +} + +bool ShaderManagerClass::RenderAlphaMapShader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, + ID3D11ShaderResourceView* texture1, ID3D11ShaderResourceView* texture2, ID3D11ShaderResourceView* texture3) +{ + bool result; + + + result = m_AlphaMapShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2, texture3); + if (!result) + { + return false; + } + return true; } \ No newline at end of file diff --git a/enginecustom/shadermanagerclass.h b/enginecustom/shadermanagerclass.h index d983ee0..e8ffdcd 100644 --- a/enginecustom/shadermanagerclass.h +++ b/enginecustom/shadermanagerclass.h @@ -9,6 +9,7 @@ #include "normalmapshaderclass.h" #include "Multitextureshaderclass.h" #include "translateshaderclass.h" +#include "alphamapshaderclass.h" //////////////////////////////////////////////////////////////////////////////// @@ -28,6 +29,7 @@ public: 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); + bool RenderAlphaMapShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*); private: TextureShaderClass* m_TextureShader; @@ -35,6 +37,7 @@ private: NormalMapShaderClass* m_NormalMapShader; MultiTextureShaderClass* m_MultitextureShader; TranslateShaderClass* m_TranslateShader; + AlphaMapShaderClass* m_AlphaMapShader; }; #endif