Minor: Ajout du Shader de l'eau

This commit is contained in:
GolfOcean334 2024-04-12 17:34:59 +02:00
parent df55562d59
commit 5aa2621a76
17 changed files with 577 additions and 29 deletions

View File

@ -68,13 +68,13 @@ void LightShaderClass::Shutdown()
}
bool LightShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[])
ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[], XMFLOAT4 ambientClor[])
{
bool result;
// Set the shader parameters that it will use for rendering.
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, lightPosition);
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, lightPosition, ambientClor);
if(!result)
{
return false;
@ -394,7 +394,7 @@ void LightShaderClass::OutputShaderErrorMessage(ID3D10Blob* errorMessage, HWND h
bool LightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[])
ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[], XMFLOAT4 ambientColor[])
{
HRESULT result;
D3D11_MAPPED_SUBRESOURCE mappedResource;

View File

@ -67,14 +67,14 @@ public:
bool Initialize(ID3D11Device*, HWND);
void Shutdown();
bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[]);
bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[]);
private:
bool InitializeShader(ID3D11Device*, HWND, WCHAR*, WCHAR*);
void ShutdownShader();
void OutputShaderErrorMessage(ID3D10Blob*, HWND, WCHAR*);
bool SetShaderParameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[]);
bool SetShaderParameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[]);
void RenderShader(ID3D11DeviceContext*, int);
private:

View File

@ -19,6 +19,16 @@ ApplicationClass::ApplicationClass()
m_Position = 0;
m_Frustum = 0;
m_DisplayPlane = 0;
m_GroundModel = 0;
m_WallModel = 0;
m_BathModel = 0;
m_WaterModel = 0;
m_Light = 0;
m_RefractionTexture = 0;
m_ReflectionTexture = 0;
m_LightShader = 0;
m_RefractionShader = 0;
m_WaterShader = 0;
}
@ -191,6 +201,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
m_Light->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
m_Light->SetDirection(0.0f, 0.0f, -1.0f);
m_Light->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
m_Light->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
m_Light->SetSpecularPower(16.0f);
@ -257,6 +268,122 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
m_ModelList = new ModelListClass;
m_ModelList->Initialize(25);
// Set the file names of the ground model.
strcpy_s(modelFilename, "ground.txt");
strcpy_s(textureFilename1, "ground01.tga");
// Create and initialize the ground model object.
m_GroundModel = new ModelClass;
result = m_GroundModel->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename1, textureFilename2, textureFilename3, textureFilename4,
textureFilename5, textureFilename6);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the ground model object.", L"Error", MB_OK);
return false;
}
// Set the file names of the wall model.
strcpy_s(modelFilename, "wall.txt");
strcpy_s(textureFilename1, "wall01.tga");
// Create and initialize the wall model object.
m_WallModel = new ModelClass;
result = m_WallModel->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename1, textureFilename2, textureFilename3, textureFilename4,
textureFilename5, textureFilename6);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the wall model object.", L"Error", MB_OK);
return false;
}
// Set the file names of the bath model.
strcpy_s(modelFilename, "bath.txt");
strcpy_s(textureFilename1, "marble01.tga");
// Create and initialize the bath model object.
m_BathModel = new ModelClass;
result = m_BathModel->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename1, textureFilename2, textureFilename3, textureFilename4,
textureFilename5, textureFilename6);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the bath model object.", L"Error", MB_OK);
return false;
}
// Set the file names of the water model.
strcpy_s(modelFilename, "water.txt");
strcpy_s(textureFilename1, "water01.tga");
// Create and initialize the water model object.
m_WaterModel = new ModelClass;
result = m_WaterModel->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename1, textureFilename2, textureFilename3, textureFilename4,
textureFilename5, textureFilename6);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the water model object.", L"Error", MB_OK);
return false;
}
// Create and initialize the refraction render to texture object.
m_RefractionTexture = new RenderTextureClass;
result = m_RefractionTexture->Initialize(m_Direct3D->GetDevice(), screenWidth, screenHeight, SCREEN_DEPTH, SCREEN_NEAR, 1);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the refraction render texture object.", L"Error", MB_OK);
return false;
}
// Create and initialize the reflection render to texture object.
m_ReflectionTexture = new RenderTextureClass;
result = m_ReflectionTexture->Initialize(m_Direct3D->GetDevice(), screenWidth, screenHeight, SCREEN_DEPTH, SCREEN_NEAR, 1);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the reflection render texture object.", L"Error", MB_OK);
return false;
}
// Create and initialize the light shader object.
m_LightShader = new LightShaderClass;
result = m_LightShader->Initialize(m_Direct3D->GetDevice(), hwnd);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the light shader object.", L"Error", MB_OK);
return false;
}
// Create and initialize the refraction shader object.
m_RefractionShader = new RefractionShaderClass;
result = m_RefractionShader->Initialize(m_Direct3D->GetDevice(), hwnd);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the refraction shader object.", L"Error", MB_OK);
return false;
}
// Create and initialize the water shader object.
m_WaterShader = new WaterShaderClass;
result = m_WaterShader->Initialize(m_Direct3D->GetDevice(), hwnd);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the water shader object.", L"Error", MB_OK);
return false;
}
// Set the height of the water.
m_waterHeight = 2.75f;
// Initialize the position of the water.
m_waterTranslation = 0.0f;
// Create and initialize the timer object.
m_Timer = new TimerClass;
@ -313,6 +440,78 @@ void ApplicationClass::Shutdown()
m_ShaderManager = 0;
}
// Release the water shader object.
if (m_WaterShader)
{
m_WaterShader->Shutdown();
delete m_WaterShader;
m_WaterShader = 0;
}
// Release the refraction shader object.
if (m_RefractionShader)
{
m_RefractionShader->Shutdown();
delete m_RefractionShader;
m_RefractionShader = 0;
}
// Release the light shader object.
if (m_LightShader)
{
m_LightShader->Shutdown();
delete m_LightShader;
m_LightShader = 0;
}
// Release the reflection render texture object.
if (m_ReflectionTexture)
{
m_ReflectionTexture->Shutdown();
delete m_ReflectionTexture;
m_ReflectionTexture = 0;
}
// Release the refraction render texture object.
if (m_RefractionTexture)
{
m_RefractionTexture->Shutdown();
delete m_RefractionTexture;
m_RefractionTexture = 0;
}
// Release the water model object.
if (m_WaterModel)
{
m_WaterModel->Shutdown();
delete m_WaterModel;
m_WaterModel = 0;
}
// Release the bath model object.
if (m_BathModel)
{
m_BathModel->Shutdown();
delete m_BathModel;
m_BathModel = 0;
}
// Release the wall model object.
if (m_WallModel)
{
m_WallModel->Shutdown();
delete m_WallModel;
m_WallModel = 0;
}
// Release the ground model object.
if (m_GroundModel)
{
m_GroundModel->Shutdown();
delete m_GroundModel;
m_GroundModel = 0;
}
// Release the frustum class object.
if (m_Frustum)
{
@ -532,6 +731,28 @@ bool ApplicationClass::Frame(InputClass* Input)
rotation += 360.0f;
}
// Update the position of the water to simulate motion.
m_waterTranslation += 0.001f;
if (m_waterTranslation > 1.0f)
{
m_waterTranslation -= 1.0f;
}
// Render the refraction of the scene to a texture.
result = RenderRefractionToTexture();
if (!result)
{
return false;
}
// Render the reflection of the scene to a texture.
result = RenderReflectionToTexture();
if (!result)
{
return false;
}
//// Update the x position variable each frame.
//x -= 0.0174532925f * 0.6f;
@ -580,6 +801,88 @@ bool ApplicationClass::Frame(InputClass* Input)
return true;
}
bool ApplicationClass::RenderRefractionToTexture()
{
XMMATRIX worldMatrix, viewMatrix, projectionMatrix;
XMFLOAT4 clipPlane;
bool result;
// Setup a clipping plane based on the height of the water to clip everything above it.
clipPlane = XMFLOAT4(0.0f, -1.0f, 0.0f, m_waterHeight + 0.1f);
// Set the render target to be the refraction render to texture and clear it.
m_RefractionTexture->SetRenderTarget(m_Direct3D->GetDeviceContext());
m_RefractionTexture->ClearRenderTarget(m_Direct3D->GetDeviceContext(), 0.0f, 0.0f, 0.0f, 1.0f);
// Generate the view matrix based on the camera's position.
m_Camera->Render();
// Get the world, view, and projection matrices from the camera and d3d objects.
m_Direct3D->GetWorldMatrix(worldMatrix);
m_Camera->GetViewMatrix(viewMatrix);
m_Direct3D->GetProjectionMatrix(projectionMatrix);
// Translate to where the bath model will be rendered.
worldMatrix = XMMatrixTranslation(0.0f, 2.0f, 0.0f);
// Render the bath model using the refraction shader.
m_BathModel->Render(m_Direct3D->GetDeviceContext());
result = m_RefractionShader->Render(m_Direct3D->GetDeviceContext(), m_BathModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_BathModel->GetTexture(0),
m_Light->GetDirection(), m_Light->GetAmbientColor(), m_Light->GetDiffuseColor(), clipPlane);
if (!result)
{
return false;
}
// Reset the render target back to the original back buffer and not the render to texture anymore. And reset the viewport back to the original.
m_Direct3D->SetBackBufferRenderTarget();
m_Direct3D->ResetViewport();
return true;
}
bool ApplicationClass::RenderReflectionToTexture()
{
XMMATRIX worldMatrix, reflectionViewMatrix, projectionMatrix;
XMFLOAT4 diffuseColor[4], getDirection[4], ambientColor[4];
bool result;
// Set the render target to be the reflection render to texture and clear it.
m_ReflectionTexture->SetRenderTarget(m_Direct3D->GetDeviceContext());
m_ReflectionTexture->ClearRenderTarget(m_Direct3D->GetDeviceContext(), 0.0f, 0.0f, 0.0f, 1.0f);
// Use the camera to render the reflection and create a reflection view matrix.
m_Camera->RenderReflection(m_waterHeight);
// Get the camera reflection view matrix instead of the normal view matrix.
m_Camera->GetReflectionViewMatrix(reflectionViewMatrix);
// Get the world and projection matrices from the d3d object.
m_Direct3D->GetWorldMatrix(worldMatrix);
m_Direct3D->GetProjectionMatrix(projectionMatrix);
// Translate to where the wall model will be rendered.
worldMatrix = XMMatrixTranslation(0.0f, 6.0f, 8.0f);
// Render the wall model using the light shader and the reflection view matrix.
m_WallModel->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderlightShaderWater(m_Direct3D->GetDeviceContext(), m_WallModel->GetIndexCount(), worldMatrix, reflectionViewMatrix, projectionMatrix, m_WallModel->GetTexture(4),
getDirection, ambientColor, diffuseColor);
if (!result)
{
return false;
}
// Reset the render target back to the original back buffer and not the render to texture anymore. And reset the viewport back to the original.
m_Direct3D->SetBackBufferRenderTarget();
m_Direct3D->ResetViewport();
return true;
}
bool ApplicationClass::RenderSceneToTexture(float rotation)
{
XMMATRIX worldMatrix, viewMatrix, projectionMatrix;
@ -619,9 +922,9 @@ bool ApplicationClass::RenderSceneToTexture(float rotation)
bool ApplicationClass::Render(float rotation, float x, float y, float z, float textureTranslation)
{
XMMATRIX worldMatrix, viewMatrix, orthoMatrix, projectionMatrix, rotateMatrix, translateMatrix, scaleMatrix, srMatrix;
XMMATRIX worldMatrix, viewMatrix, orthoMatrix, projectionMatrix, rotateMatrix, translateMatrix, scaleMatrix, srMatrix, reflectionMatrix;
float positionX, positionY, positionZ, radius;
XMFLOAT4 diffuseColor[4], lightPosition[4];
XMFLOAT4 diffuseColor[4], lightPosition[4], getDirection[4], ambientColor[4];
int modelCount, renderCount, i;
bool result, renderModel;
float blendAmount;
@ -650,6 +953,9 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
// 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]->GetPosition();
}
scaleMatrix = XMMatrixScaling(0.5f, 0.5f, 0.5f); // Build the scaling matrix.
@ -665,7 +971,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
// Render the model using the light shader.
result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0),
diffuseColor, lightPosition);
diffuseColor, lightPosition, ambientColor);
for (auto cube : m_cubes)
{
@ -687,7 +993,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
cube->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0),
diffuseColor, lightPosition);
diffuseColor, lightPosition, ambientColor);
if (!result)
{
logger.Log("Could not render the cube model using the light shader", __FILE__, __LINE__, Logger::LogLevel::Error);
@ -711,7 +1017,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
object->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0),
diffuseColor, lightPosition);
diffuseColor, lightPosition, ambientColor);
if (!result)
{
@ -734,7 +1040,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
chunk->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), chunk->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, chunk->GetTexture(5),
diffuseColor, lightPosition);
diffuseColor, lightPosition, ambientColor);
if (!result)
{
@ -816,7 +1122,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0),
diffuseColor, lightPosition);
diffuseColor, lightPosition, ambientColor);
if (!result)
{
logger.Log("Could not render the model using the light shader", __FILE__, __LINE__, Logger::LogLevel::Error);
@ -925,13 +1231,78 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
}
// Translate to where the ground model will be rendered.
worldMatrix = XMMatrixTranslation(0.0f, 1.0f, 0.0f);
// Render the model using the multitexture shader.
//result = m_MultiTextureShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
// m_Model->GetTexture(0), m_Model->GetTexture(1));
// Put the ground model vertex and index buffers on the graphics pipeline to prepare them for drawing.
m_GroundModel->Render(m_Direct3D->GetDeviceContext());
//// Render the model using the multitexture shader.
//m_Model->Render(m_Direct3D->GetDeviceContext());
// Render the ground model using the light shader.
result = m_ShaderManager->RenderlightShaderWater(m_Direct3D->GetDeviceContext(), m_GroundModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_GroundModel->GetTexture(0),
getDirection, ambientColor, diffuseColor);
if (!result)
{
return false;
}
// Reset the world matrix.
m_Direct3D->GetWorldMatrix(worldMatrix);
// Translate to where the wall model will be rendered.
worldMatrix = XMMatrixTranslation(0.0f, 6.0f, 8.0f);
// Put the wall model vertex and index buffers on the graphics pipeline to prepare them for drawing.
m_WallModel->Render(m_Direct3D->GetDeviceContext());
// Render the wall model using the light shader.
result = m_ShaderManager->RenderlightShaderWater(m_Direct3D->GetDeviceContext(), m_GroundModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_GroundModel->GetTexture(0),
getDirection, ambientColor, diffuseColor);
if (!result)
{
return false;
}
// Reset the world matrix.
m_Direct3D->GetWorldMatrix(worldMatrix);
// Translate to where the bath model will be rendered.
worldMatrix = XMMatrixTranslation(0.0f, 2.0f, 0.0f);
// Put the bath model vertex and index buffers on the graphics pipeline to prepare them for drawing.
m_BathModel->Render(m_Direct3D->GetDeviceContext());
// Render the bath model using the light shader.
result = m_ShaderManager->RenderlightShaderWater(m_Direct3D->GetDeviceContext(), m_GroundModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_GroundModel->GetTexture(0),
getDirection, ambientColor, diffuseColor);
if (!result)
{
return false;
}
// Reset the world matrix.
m_Direct3D->GetWorldMatrix(worldMatrix);
// Get the camera reflection view matrix.
m_Camera->GetReflectionViewMatrix(reflectionMatrix);
// Translate to where the water model will be rendered.
worldMatrix = XMMatrixTranslation(0.0f, m_waterHeight, 0.0f);
// Put the water model vertex and index buffers on the graphics pipeline to prepare them for drawing.
m_WaterModel->Render(m_Direct3D->GetDeviceContext());
// Render the water model using the water shader.
result = m_WaterShader->Render(m_Direct3D->GetDeviceContext(), m_WaterModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, reflectionMatrix,
m_ReflectionTexture->GetShaderResourceView(), m_RefractionTexture->GetShaderResourceView(), m_WaterModel->GetTexture(0),
m_waterTranslation, 0.01f);
if (!result)
{
return false;
}
// Setup matrices.
rotateMatrix = XMMatrixRotationY(rotation);
@ -1055,7 +1426,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
// Render the model using the transparent shader.
m_Model->Render(m_Direct3D->GetDeviceContext());
result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0), diffuseColor, lightPosition);
result = m_ShaderManager->RenderlightShader(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0), diffuseColor, lightPosition, ambientColor);
if (!result)
{
return false;

View File

@ -28,9 +28,6 @@
#include "frustumclass.h"
#include "rendertextureclass.h"
#include "displayplaneclass.h"
#include "reflectionshaderclass.h"
#include "refractionshaderclass.h"
#include "watershaderclass.h"
/////////////
@ -140,6 +137,8 @@ private :
// ----------------------------------- //
ShaderManagerClass* m_ShaderManager;
LightShaderClass* m_LightShader;
RefractionShaderClass* m_RefractionShader;
WaterShaderClass* m_WaterShader;
FontShaderClass* m_FontShader;
BitmapClass* m_Bitmap;

82
enginecustom/bath.txt Normal file
View File

@ -0,0 +1,82 @@
Vertex Count: 78
Data:
4 -0.5 -4 0.998008 0.998008 0 1 -0
-4 -0.5 4 0.001992 0.00199199 0 1 -0
4 -0.5 4 0.998008 0.00199199 0 1 -0
4 -0.5 -4 0.998008 0.998008 0 1 -0
-4 -0.5 -4 0.001992 0.998008 0 1 -0
-4 -0.5 4 0.001992 0.00199199 0 1 -0
4 1 4 0.187127 0.998008 0 0 -1
-4 -0.5 4 0.000374 0.00199199 0 0 -1
-4 1 4 0.187127 0.00199199 0 0 -1
4 -0.5 4 0.000374 0.998008 0 0 -1
-4 -0.5 4 0.000374 0.00199199 0 0 -1
4 1 4 0.187127 0.998008 0 0 -1
4 1 -4 0.187126 0.998008 -1 0 -0
4 -0.5 4 0.000373 0.00199199 -1 0 -0
4 1 4 0.187126 0.00199199 -1 0 -0
4 -0.5 -4 0.000373 0.998008 -1 0 -0
4 -0.5 4 0.000373 0.00199199 -1 0 -0
4 1 -4 0.187126 0.998008 -1 0 -0
-4 1 -4 0.000374 0.00199199 0 0 1
4 -0.5 -4 0.187127 0.998008 0 0 1
4 1 -4 0.000374 0.998008 0 0 1
-4 1 -4 0.000374 0.00199199 0 0 1
-4 -0.5 -4 0.187127 0.00199199 0 0 1
4 -0.5 -4 0.187127 0.998008 0 0 1
-4 1 4 0.187127 0.998008 1 0 -0
-4 -0.5 -4 0.000374 0.00199199 1 0 -0
-4 1 -4 0.187127 0.00199199 1 0 -0
-4 -0.5 4 0.000374 0.998008 1 0 -0
-4 -0.5 -4 0.000374 0.00199199 1 0 -0
-4 1 4 0.187127 0.998008 1 0 -0
-5 1 5 0.199602 0.00199199 -1 0 -0
-5 -1 -5 0.000398 0.998008 -1 0 -0
-5 -1 5 0.000398 0.00199199 -1 0 -0
-5 1 -5 0.199602 0.998008 -1 0 -0
-5 -1 -5 0.000398 0.998008 -1 0 -0
-5 1 5 0.199602 0.00199199 -1 0 -0
5 1 -5 0.199602 0.00199199 1 0 -0
5 -1 5 0.000398 0.998008 1 0 -0
5 -1 -5 0.000398 0.00199199 1 0 -0
5 1 5 0.199602 0.998008 1 0 -0
5 -1 5 0.000398 0.998008 1 0 -0
5 1 -5 0.199602 0.00199199 1 0 -0
-5 -1 5 0.199602 0.00199199 0 0 1
5 1 5 0.000398 0.998008 0 0 1
-5 1 5 0.000398 0.00199199 0 0 1
5 -1 5 0.199602 0.998008 0 0 1
5 1 5 0.000398 0.998008 0 0 1
-5 -1 5 0.199602 0.00199199 0 0 1
-5 1 5 0.001992 0.00199199 0 1 -0
-4 1 -4 0.101594 0.898406 0 1 -0
-5 1 -5 0.001992 0.998008 0 1 -0
-5 1 5 0.001992 0.00199199 0 1 -0
-4 1 4 0.101594 0.101594 0 1 -0
-4 1 -4 0.101594 0.898406 0 1 -0
-4 1 -4 0.101594 0.898406 0 1 -0
5 1 -5 0.998008 0.998008 0 1 -0
-5 1 -5 0.001992 0.998008 0 1 -0
4 1 -4 0.898406 0.898406 0 1 -0
5 1 -5 0.998008 0.998008 0 1 -0
-4 1 -4 0.101594 0.898406 0 1 -0
4 1 -4 0.898406 0.898406 0 1 -0
5 1 5 0.998008 0.00199199 0 1 -0
5 1 -5 0.998008 0.998008 0 1 -0
4 1 4 0.898406 0.101594 0 1 -0
5 1 5 0.998008 0.00199199 0 1 -0
4 1 -4 0.898406 0.898406 0 1 -0
4 1 4 0.898406 0.101594 0 1 -0
-5 1 5 0.001992 0.00199199 0 1 -0
5 1 5 0.998008 0.00199199 0 1 -0
-5 1 5 0.001992 0.00199199 0 1 -0
4 1 4 0.898406 0.101594 0 1 -0
-4 1 4 0.101594 0.101594 0 1 -0
-5 1 -5 0.199602 0.00199199 0 0 -1
5 -1 -5 0.000398 0.998008 0 0 -1
-5 -1 -5 0.000398 0.00199199 0 0 -1
5 1 -5 0.199602 0.998008 0 0 -1
5 -1 -5 0.000398 0.998008 0 0 -1
-5 1 -5 0.199602 0.00199199 0 0 -1

10
enginecustom/ground.txt Normal file
View File

@ -0,0 +1,10 @@
Vertex Count: 6
Data:
-20 0 20 0.0 0.0 0 1 0
20 0 -20 1.0 1.0 0 1 0
-20 0 -20 0.0 1.0 0 1 0
20 0 20 1.0 0.0 0 1 0
20 0 -20 1.0 1.0 0 1 0
-20 0 20 0.0 0.0 0 1 0

BIN
enginecustom/ground01.tga Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 MiB

View File

@ -68,13 +68,13 @@ void LightShaderClass::Shutdown()
}
bool LightShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[])
ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[], XMFLOAT4 ambientClor[])
{
bool result;
// Set the shader parameters that it will use for rendering.
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, lightPosition);
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, lightPosition, ambientClor);
if(!result)
{
return false;
@ -394,7 +394,7 @@ void LightShaderClass::OutputShaderErrorMessage(ID3D10Blob* errorMessage, HWND h
bool LightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[])
ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[], XMFLOAT4 ambientColor[])
{
HRESULT result;
D3D11_MAPPED_SUBRESOURCE mappedResource;

View File

@ -67,14 +67,14 @@ public:
bool Initialize(ID3D11Device*, HWND);
void Shutdown();
bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[]);
bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[]);
private:
bool InitializeShader(ID3D11Device*, HWND, WCHAR*, WCHAR*);
void ShutdownShader();
void OutputShaderErrorMessage(ID3D10Blob*, HWND, WCHAR*);
bool SetShaderParameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[]);
bool SetShaderParameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[]);
void RenderShader(ID3D11DeviceContext*, int);
private:

View File

@ -0,0 +1 @@
#pragma once

BIN
enginecustom/marble01.tga Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 MiB

View File

@ -10,6 +10,7 @@ ShaderManagerClass::ShaderManagerClass()
m_SpecMapShader = 0;
m_TransparentShader = 0;
m_LightShader = 0;
m_LightShaderWater = 0;
m_LightMapShader = 0;
m_RefractionShader = 0;
m_WaterShader = 0;
@ -102,6 +103,15 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd)
return false;
}
// Create and initialize the light shader object.
m_LightShaderWater = new LightShaderClass;
result = m_LightShaderWater->Initialize(device, hwnd);
if (!result)
{
return false;
}
// Create and initialize the light map shader object.
m_LightMapShader = new LightMapShaderClass;
@ -198,6 +208,14 @@ void ShaderManagerClass::Shutdown()
m_LightShader = 0;
}
// Release the light shader object.
if (m_LightShaderWater)
{
m_LightShaderWater->Shutdown();
delete m_LightShaderWater;
m_LightShaderWater = 0;
}
// Release the light map shader object.
if (m_LightMapShader)
{
@ -334,12 +352,27 @@ bool ShaderManagerClass::RenderTransparentShader(ID3D11DeviceContext* deviceCont
}
bool ShaderManagerClass::RenderlightShader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[])
ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor[], XMFLOAT4 lightPosition[], XMFLOAT4 ambientColor[])
{
bool result;
result = m_LightShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, lightPosition);
result = m_LightShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, lightPosition, ambientColor);
if (!result)
{
return false;
}
return true;
}
bool ShaderManagerClass::RenderlightShaderWater(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
ID3D11ShaderResourceView* texture, XMFLOAT4 getDirection[], XMFLOAT4 ambientColor[], XMFLOAT4 diffuseColor[])
{
bool result;
result = m_LightShaderWater->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, getDirection, ambientColor, diffuseColor);
if (!result)
{
return false;

View File

@ -37,7 +37,8 @@ public:
bool RenderSpecMapShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*,
XMFLOAT3, XMFLOAT4, XMFLOAT3, XMFLOAT4, float);
bool RenderTransparentShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, float);
bool RenderlightShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[]);
bool RenderlightShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[]);
bool RenderlightShaderWater(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[]);
bool RenderlightMapShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*);
bool RenderRefractionShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*,
XMFLOAT3, XMFLOAT4, XMFLOAT4, XMFLOAT4);
@ -52,6 +53,7 @@ private:
SpecMapShaderClass* m_SpecMapShader;
TransparentShaderClass* m_TransparentShader;
LightShaderClass* m_LightShader;
LightShaderClass* m_LightShaderWater;
LightMapShaderClass* m_LightMapShader;
RefractionShaderClass* m_RefractionShader;
WaterShaderClass* m_WaterShader;

40
enginecustom/wall.txt Normal file
View File

@ -0,0 +1,40 @@
Vertex Count: 36
Data:
-5 5 -0.5 0.001992 0.00199199 0 0 -1
5 -5 -0.5 0.998008 0.998008 0 0 -1
-5 -5 -0.5 0.001992 0.998008 0 0 -1
5 5 -0.5 0.998008 0.00199199 0 0 -1
5 -5 -0.5 0.998008 0.998008 0 0 -1
-5 5 -0.5 0.001992 0.00199199 0 0 -1
-5 5 0.5 0.099801 0.00199199 0 1 -0
5 5 -0.5 0.000199 0.998008 0 1 -0
-5 5 -0.5 0.000199 0.00199199 0 1 -0
5 5 0.5 0.099801 0.998008 0 1 -0
5 5 -0.5 0.000199 0.998008 0 1 -0
-5 5 0.5 0.099801 0.00199199 0 1 -0
-5 -5 0.5 0.001992 0.00199199 0 0 1
5 5 0.5 0.998008 0.998008 0 0 1
-5 5 0.5 0.001992 0.998008 0 0 1
5 -5 0.5 0.998008 0.00199199 0 0 1
5 5 0.5 0.998008 0.998008 0 0 1
-5 -5 0.5 0.001992 0.00199199 0 0 1
-5 -5 -0.5 0.099801 0.00199199 0 -1 -0
5 -5 0.5 0.000199 0.998008 0 -1 -0
-5 -5 0.5 0.000199 0.00199199 0 -1 -0
5 -5 -0.5 0.099801 0.998008 0 -1 -0
5 -5 0.5 0.000199 0.998008 0 -1 -0
-5 -5 -0.5 0.099801 0.00199199 0 -1 -0
5 5 -0.5 0.000199 0.00199199 1 0 -0
5 -5 0.5 0.099801 0.998008 1 0 -0
5 -5 -0.5 0.000199 0.998008 1 0 -0
5 5 0.5 0.099801 0.00199199 1 0 -0
5 -5 0.5 0.099801 0.998008 1 0 -0
5 5 -0.5 0.000199 0.00199199 1 0 -0
-5 5 0.5 0.000199 0.00199199 -1 0 -0
-5 -5 -0.5 0.099801 0.998008 -1 0 -0
-5 -5 0.5 0.000199 0.998008 -1 0 -0
-5 5 -0.5 0.099801 0.00199199 -1 0 -0
-5 -5 -0.5 0.099801 0.998008 -1 0 -0
-5 5 0.5 0.000199 0.00199199 -1 0 -0

BIN
enginecustom/wall01.tga Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 MiB

10
enginecustom/water.txt Normal file
View File

@ -0,0 +1,10 @@
Vertex Count: 6
Data:
-4 0 4 0.0 0.0 0 1 0
4 0 -4 1.0 1.0 0 1 0
-4 0 -4 0.0 1.0 0 1 0
4 0 4 1.0 0.0 0 1 0
4 0 -4 1.0 1.0 0 1 0
-4 0 4 0.0 0.0 0 1 0

BIN
enginecustom/water01.tga Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB