From a947a0494682979a0e49e70af2f283d9eb9dcece Mon Sep 17 00:00:00 2001
From: GolfOcean334 <130740013+GolfOcean334@users.noreply.github.com>
Date: Mon, 8 Apr 2024 17:48:52 +0200
Subject: [PATCH] Minor: Ajout Specular map shader dans le shader manager

---
 enginecustom/applicationclass.cpp   | 70 +++++++++--------------------
 enginecustom/applicationclass.h     |  3 --
 enginecustom/shadermanagerclass.cpp | 37 ++++++++++++++-
 enginecustom/shadermanagerclass.h   |  4 ++
 4 files changed, 62 insertions(+), 52 deletions(-)

diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp
index 1ce12e9..2e78ff6 100644
--- a/enginecustom/applicationclass.cpp
+++ b/enginecustom/applicationclass.cpp
@@ -20,7 +20,6 @@ ApplicationClass::ApplicationClass()
 	m_Fps = 0;
 	m_FpsString = 0;
 	m_ShaderManager = 0;
-	m_SpecMapShader = 0;
 	m_RenderCountString = 0;
 	m_ModelList = 0;
 	m_Position = 0;
@@ -80,16 +79,6 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
 	m_Camera->Render();
 	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.
 	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].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.
 	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].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].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].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.
@@ -513,16 +510,6 @@ void ApplicationClass::Shutdown()
 		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.
 	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);
 	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());
 
 	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);
 	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());
 
 	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);
 	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());
 
 	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);
 	worldMatrix = XMMatrixMultiply(rotateMatrix, translateMatrix);
 
-	// Render the model using the Multitexture shader.
+	// Render the model using the translate shader.
 	m_Model->Render(m_Direct3D->GetDeviceContext());
 
 	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);
 	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());
 
-	
+	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
@@ -1067,26 +1060,7 @@ 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;
-	//}
-
-	//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.
 	m_Direct3D->TurnZBufferOn();
 	m_Direct3D->DisableAlphaBlending();
diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h
index 22954a0..71dbd8a 100644
--- a/enginecustom/applicationclass.h
+++ b/enginecustom/applicationclass.h
@@ -20,8 +20,6 @@
 #include "textclass.h"
 #include "fpsclass.h"
 #include "inputclass.h"
-#include "normalmapshaderclass.h"
-#include "specmapshaderclass.h"
 #include "shadermanagerclass.h"
 #include "modellistclass.h"
 #include "positionclass.h"
@@ -80,7 +78,6 @@ private:
 	FpsClass* m_Fps;
 	TextClass* m_FpsString;
 	int m_previousFps;
-	SpecMapShaderClass* m_SpecMapShader;
 	ShaderManagerClass* m_ShaderManager;
 	ModelListClass* m_ModelList;
 	PositionClass* m_Position;
diff --git a/enginecustom/shadermanagerclass.cpp b/enginecustom/shadermanagerclass.cpp
index 9b582f8..4a7a99c 100644
--- a/enginecustom/shadermanagerclass.cpp
+++ b/enginecustom/shadermanagerclass.cpp
@@ -7,6 +7,7 @@ ShaderManagerClass::ShaderManagerClass()
     m_MultitextureShader = 0;
     m_TranslateShader = 0;
     m_AlphaMapShader = 0;
+    m_SpecMapShader = 0;
 }
 
 
@@ -60,7 +61,7 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd)
         return false;
     }
 
-    // Create and initialize the translate shader object.
+    // Create and initialize the alpha map shader object.
     m_AlphaMapShader = new AlphaMapShaderClass;
 
     result = m_AlphaMapShader->Initialize(device, hwnd);
@@ -69,6 +70,15 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd)
         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;
 }
 
@@ -114,6 +124,14 @@ void ShaderManagerClass::Shutdown()
         m_AlphaMapShader = 0;
     }
 
+    // Release the specular map shader object.
+    if (m_SpecMapShader)
+    {
+        m_SpecMapShader->Shutdown();
+        delete m_SpecMapShader;
+        m_SpecMapShader = 0;
+    }
+
     return;
       
 }
@@ -190,5 +208,22 @@ bool ShaderManagerClass::RenderAlphaMapShader(ID3D11DeviceContext* deviceContext
         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;
 }
\ No newline at end of file
diff --git a/enginecustom/shadermanagerclass.h b/enginecustom/shadermanagerclass.h
index 117b5f8..23a3a50 100644
--- a/enginecustom/shadermanagerclass.h
+++ b/enginecustom/shadermanagerclass.h
@@ -10,6 +10,7 @@
 #include "Multitextureshaderclass.h"
 #include "translateshaderclass.h"
 #include "alphamapshaderclass.h"
+#include "specmapshaderclass.h"
 
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -29,6 +30,8 @@ public:
     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*);
+    bool RenderSpecMapShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*,
+        XMFLOAT3, XMFLOAT4, XMFLOAT3, XMFLOAT4, float);
 
 private:
     TextureShaderClass* m_TextureShader;
@@ -36,6 +39,7 @@ private:
     MultiTextureShaderClass* m_MultitextureShader;
     TranslateShaderClass* m_TranslateShader;
     AlphaMapShaderClass* m_AlphaMapShader;
+    SpecMapShaderClass* m_SpecMapShader;
 };
 
 #endif