Revert "Minor - Start Shadow Map - V10.5.0"

This reverts commit d6b7626446.
This commit is contained in:
2025-05-25 16:12:39 +02:00
parent d6b7626446
commit dbd27d1fe7
18 changed files with 531 additions and 1305 deletions

View File

@@ -1,10 +0,0 @@
struct PS_INPUT
{
float4 position : SV_POSITION;
};
float4 DepthPixelShader(PS_INPUT input) : SV_TARGET
{
// Pas de couleur, juste la profondeur
return float4(0.0f, 0.0f, 0.0f, 1.0f);
}

View File

@@ -1,25 +0,0 @@
cbuffer MatrixBuffer : register(b0)
{
matrix world;
matrix view;
matrix projection;
};
struct VS_INPUT
{
float3 position : POSITION;
};
struct VS_OUTPUT
{
float4 position : SV_POSITION;
};
VS_OUTPUT DepthVertexShader(VS_INPUT input)
{
VS_OUTPUT output;
float4 worldPosition = mul(float4(input.position, 1.0f), world);
float4 viewPosition = mul(worldPosition, view);
output.position = mul(viewPosition, projection);
return output;
}

View File

@@ -3,9 +3,6 @@
/////////////
Texture2D shaderTexture : register(t0);
SamplerState SampleType : register(s0);
Texture2D shadowMap : register(t1);
SamplerState shadowSampleType : register(s1);
cbuffer SunLightBuffer
{
float4 ambientColor;
@@ -27,7 +24,6 @@ struct PixelInputType
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float4 lightPosition : TEXCOORD1;
};
////////////////////////////////////////////////////////////////////////////////
@@ -35,47 +31,23 @@ struct PixelInputType
////////////////////////////////////////////////////////////////////////////////
float4 SunLightPixelShader(PixelInputType input) : SV_TARGET
{
// temp return to check if the shader is working
return float4(1.0f, 0.0f, 0.0f, 1.0f);
float4 textureColor;
float4 color;
float lightIntensity;
float4 colorArray;
float4 colorSum;
float bias = 0.001f;
float shadowFactor = 1.0f;
// Sample the pixel color from the texture using the sampler at this coordinate
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
textureColor = shaderTexture.Sample(SampleType, input.tex);
// Calculate shadow factor
// Projection division to normalize coordinates
float2 projectTexCoord;
projectTexCoord.x = input.lightPosition.x / input.lightPosition.w / 2.0f + 0.5f;
projectTexCoord.y = -input.lightPosition.y / input.lightPosition.w / 2.0f + 0.5f;
if((saturate(projectTexCoord.x) == projectTexCoord.x) && (saturate(projectTexCoord.y) == projectTexCoord.y))
{
float depthValue = input.lightPosition.z / input.lightPosition.w;
float shadowDepth = shadowMap.Sample(shadowSampleType, projectTexCoord).r;
if(depthValue - bias > shadowDepth)
{
// Pixel est dans l'ombre
shadowFactor = 0.3f; // Ombre non totale pour un effet plus r<EFBFBD>aliste
}
}
// Calculate the different amounts of light on this pixel based on the direction of the light.
lightIntensity = saturate(dot(input.normal, -lightDirection));
// Determine the diffuse color amount of the light.
colorArray = (diffuseColor * lightIntensity) * intensity * shadowFactor;
colorArray = (diffuseColor * lightIntensity) * intensity;
// Initialize the sum of colors.
colorSum = ambientColor; // Conserver l'<27>clairage ambiant m<EFBFBD>me dans l'ombre
colorSum = float4(0.0f, 0.0f, 0.0f, 1.0f);
// Add the light color.
colorSum.r += colorArray.r;
@@ -86,4 +58,4 @@ float4 SunLightPixelShader(PixelInputType input) : SV_TARGET
color = saturate(colorSum) * textureColor;
return color;
}
}

View File

@@ -22,12 +22,6 @@ cbuffer SunLightBuffer
float intensity;
};
cbuffer LightViewMatrixBuffer : register(b2)
{
matrix lightViewMatrix;
matrix lightProjectionMatrix;
};
//////////////
// TYPEDEFS //
//////////////
@@ -43,7 +37,6 @@ struct PixelInputType
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float4 lightPosition : TEXCOORD1;
};
////////////////////////////////////////////////////////////////////////////////
@@ -52,30 +45,23 @@ struct PixelInputType
PixelInputType SunLightVertexShader(VertexInputType input)
{
PixelInputType output;
float4 worldPosition; // D<>claration de la variable manquante
// Change the position vector to be 4 units for proper matrix calculations.
input.position.w = 1.0f;
// Calculate the position of the vertex against the world matrix
worldPosition = mul(input.position, worldMatrix);
// Calculate position in light view space.
output.lightPosition = mul(worldPosition, lightViewMatrix);
output.lightPosition = mul(output.lightPosition, lightProjectionMatrix);
// Standard position calculation
output.position = mul(worldPosition, viewMatrix);
// Calculate the position of the vertex against the world, view, and projection matrices.
output.position = mul(input.position, worldMatrix);
output.position = mul(output.position, viewMatrix);
output.position = mul(output.position, projectionMatrix);
// Store the texture coordinates for the pixel shader.
output.tex = input.tex;
// Calculate the normal vector against the world matrix only.
output.normal = mul(input.normal, (float3x3)worldMatrix);
output.normal = mul(input.normal, (float3x3) worldMatrix);
// Normalize the normal vector.
output.normal = normalize(output.normal);
return output;
}
}

View File

@@ -1,37 +0,0 @@
#pragma once
#include <d3d11.h>
#include <DirectXMath.h>
using namespace DirectX;
class depth_shader_class
{
public:
depth_shader_class();
~depth_shader_class();
bool initialize(ID3D11Device* device, HWND hwnd);
void shutdown();
bool render(ID3D11DeviceContext* deviceContext, int indexCount,
XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix);
private:
struct MatrixBufferType
{
XMMATRIX world;
XMMATRIX view;
XMMATRIX projection;
};
bool initialize_shader(ID3D11Device* device, HWND hwnd, const WCHAR* vsFilename, const WCHAR* psFilename);
void shutdown_shader();
void output_shader_error_message(ID3D10Blob* errorMessage, HWND hwnd, const WCHAR* shaderFilename);
bool set_shader_parameters(ID3D11DeviceContext* deviceContext,
XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix);
void render_shader(ID3D11DeviceContext* deviceContext, int indexCount);
ID3D11VertexShader* vertex_shader_;
ID3D11PixelShader* pixel_shader_;
ID3D11InputLayout* layout_;
ID3D11Buffer* matrix_buffer_;
};

View File

@@ -19,7 +19,6 @@
#include "celshade_class.h"
#include "skybox_shader_class.h"
#include "sunlight_shader_class.h"
#include "depth_shader_class.h"
using namespace DirectX;
@@ -45,10 +44,8 @@ public:
bool render_refraction_shader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[], XMFLOAT4);
bool render_water_shader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, float, float);
bool render_cel_shading_shader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float);
bool render_sunlight_shader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float, ID3D11ShaderResourceView
* shadowMap, XMMATRIX lightViewMatrix, XMMATRIX lightProjectionMatrix);
bool render_sunlight_shader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float);
bool render_skybox_shader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float);
bool render_depth_shader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX);
private:
texture_shader_class* texture_shader_;
@@ -65,7 +62,6 @@ private:
celshade_class* cel_shading_shader_;
sunlight_shader_class* sunlight_shader_;
skybox_shader_class* skybox_shader_;
depth_shader_class* depth_shader_;
};
#endif

View File

@@ -38,12 +38,6 @@ private :
XMFLOAT4 sun_color;
};
struct light_view_matrix_buffer_type
{
XMMATRIX light_view;
XMMATRIX light_projection;
};
public :
sunlight_shader_class();
sunlight_shader_class(const sunlight_shader_class&);
@@ -51,29 +45,14 @@ public :
bool initialize(ID3D11Device*, HWND);
void shutdown();
bool render(
ID3D11DeviceContext* device_context,
int index_count,
XMMATRIX world_matrix,
XMMATRIX view_matrix,
XMMATRIX projection_matrix,
ID3D11ShaderResourceView* texture,
XMFLOAT4 diffuse_color,
XMFLOAT4 ambient_color,
XMFLOAT3 sun_direction,
float sun_intensity,
ID3D11ShaderResourceView* shadow_map,
XMMATRIX light_view_matrix,
XMMATRIX light_projection_matrix
);
bool render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3,float);
private:
bool initialize_shader(ID3D11Device*, HWND, WCHAR*, WCHAR*);
void shutdown_shader();
void output_shader_error_message(ID3D10Blob*, HWND, WCHAR*);
bool set_shader_parameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float, ID3D11ShaderResourceView
* shadowMap, XMMATRIX lightViewMatrix, XMMATRIX lightProjectionMatrix);
bool set_shader_parameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float);
void render_shader(ID3D11DeviceContext*, int);
private:
@@ -86,7 +65,4 @@ private:
ID3D11Buffer* sunlight_buffer_;
ID3D11Buffer* sunlight_color_buffer_;
ID3D11Buffer* sunlight_position_buffer_;
ID3D11Buffer* light_view_matrix_buffer_;
ID3D11ShaderResourceView* shadow_map_texture_;
ID3D11SamplerState* shadow_sampler_state_;
};

View File

@@ -43,8 +43,6 @@
#include <DirectXMath.h>
#include <mutex>
#include "shadow_map.h"
/////////////
// GLOBALS //
@@ -187,17 +185,8 @@ private:
bool render_scene_to_texture(float);
bool render_refraction_to_texture();
bool render_reflection_to_texture();
bool render_pass(
const std::vector<std::reference_wrapper<std::vector<object*>>>& RenderQueues,
XMFLOAT4* diffuse,
XMFLOAT4* position,
XMFLOAT4* ambient,
XMMATRIX view,
XMMATRIX projection
);
bool create_shadow_map(
const std::vector<std::reference_wrapper<std::vector<object*>>>& RenderQueues
);
bool render_pass(const std::vector<std::reference_wrapper<std::vector<object*>>>& RenderQueues, XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection);
void update_skybox_position();
public :
@@ -331,18 +320,6 @@ private :
// ------------------------------------------------- //
input inputs_;
// ------------------------------------------------- //
// -------------------- Shadows -------------------- //
// ------------------------------------------------- //
shadow_map* shadow_map_;
camera_class* light_camera_;
XMFLOAT4 light_position_buffer_;
XMFLOAT3 light_rotation_buffer_;
XMMATRIX light_view_matrix_;
XMMATRIX light_projection_matrix_;
ID3D11ShaderResourceView* shadow_srv_;
};
#endif

View File

@@ -1,33 +0,0 @@
#pragma once
#include <d3d11.h>
class shadow_map
{
public:
shadow_map();
shadow_map(const shadow_map&) = delete;
shadow_map& operator=(const shadow_map&) = delete;
~shadow_map();
bool initialize(
ID3D11Device* device,
int shadow_map_width,
int shadow_map_height
);
void set_render_target(ID3D11DeviceContext* context);
void clear_render_target(ID3D11DeviceContext* context, float depth);
ID3D11ShaderResourceView* get_shader_resource_view() const;
void shutdown();
private:
ID3D11Texture2D* depth_texture_;
ID3D11DepthStencilView* depth_stencil_view_;
ID3D11ShaderResourceView* shader_resource_view_;
D3D11_VIEWPORT viewport_;
};

View File

@@ -1,224 +0,0 @@
#include "depth_shader_class.h"
#include <d3dcompiler.h>
#include "logger.h"
depth_shader_class::depth_shader_class()
{
vertex_shader_ = nullptr;
pixel_shader_ = nullptr;
layout_ = nullptr;
matrix_buffer_ = nullptr;
}
depth_shader_class::~depth_shader_class()
{
shutdown();
}
bool depth_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{
Logger::Get().Log("Initializing depth shader class", __FILE__, __LINE__, Logger::LogLevel::Initialize);
// Charger et compiler les shaders (remplacez les chemins par les v<>tres)
bool result = initialize_shader(device, hwnd, L"src/hlsl/depth.vs", L"src/hlsl/depth.ps");
if (!result)
{
Logger::Get().Log("Failed to initialize depth shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
Logger::Get().Log("Initialized depth shader class", __FILE__, __LINE__, Logger::LogLevel::Info);
return true;
}
void depth_shader_class::shutdown()
{
shutdown_shader();
}
bool depth_shader_class::render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix)
{
if (!set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix))
return false;
render_shader(deviceContext, indexCount);
return true;
}
bool depth_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, const WCHAR* vsFilename, const WCHAR* psFilename)
{
HRESULT result;
ID3DBlob* vertexShaderBuffer = nullptr;
ID3DBlob* pixelShaderBuffer = nullptr;
ID3DBlob* errorMessage = nullptr;
// Compiler le vertex shader
result = D3DCompileFromFile(vsFilename, nullptr, nullptr, "DepthVertexShader", "vs_5_0", 0, 0, &vertexShaderBuffer, &errorMessage);
if (FAILED(result))
{
if (errorMessage)
{
output_shader_error_message(errorMessage, hwnd, vsFilename);
errorMessage->Release();
}
else
{
Logger::Get().Log("Fichier de vertex shader introuvable: " + std::to_string(reinterpret_cast<uintptr_t>(vsFilename)), __FILE__, __LINE__, Logger::LogLevel::Error);
}
return false;
}
// Compiler le pixel shader
errorMessage = nullptr;
result = D3DCompileFromFile(psFilename, nullptr, nullptr, "DepthPixelShader", "ps_5_0", 0, 0, &pixelShaderBuffer, &errorMessage);
if (FAILED(result))
{
if (errorMessage)
{
output_shader_error_message(errorMessage, hwnd, psFilename);
errorMessage->Release();
}
else
{
Logger::Get().Log("Fichier de pixel shader introuvable: " + std::to_string(reinterpret_cast<uintptr_t>(psFilename)), __FILE__, __LINE__, Logger::LogLevel::Error);
}
if (vertexShaderBuffer)
{
vertexShaderBuffer->Release();
}
return false;
}
// Cr<43>er les shaders
device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), nullptr, &vertex_shader_);
device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), nullptr, &pixel_shader_);
// D<>finir la description du layout d'entr<74>e
D3D11_INPUT_ELEMENT_DESC polygonLayout[1];
polygonLayout[0].SemanticName = "POSITION";
polygonLayout[0].SemanticIndex = 0;
polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
polygonLayout[0].InputSlot = 0;
polygonLayout[0].AlignedByteOffset = 0;
polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[0].InstanceDataStepRate = 0;
// Cr<43>er le layout
device->CreateInputLayout(polygonLayout, 1, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &layout_);
// Lib<69>rer les buffers
vertexShaderBuffer->Release();
pixelShaderBuffer->Release();
// Cr<43>er le buffer de matrices
D3D11_BUFFER_DESC matrixBufferDesc = {};
matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
matrixBufferDesc.ByteWidth = sizeof(MatrixBufferType);
matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
device->CreateBuffer(&matrixBufferDesc, nullptr, &matrix_buffer_);
return true;
}
bool depth_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix)
{
D3D11_MAPPED_SUBRESOURCE mappedResource;
MatrixBufferType* dataPtr;
// Transposer les matrices pour le shader
worldMatrix = XMMatrixTranspose(worldMatrix);
viewMatrix = XMMatrixTranspose(viewMatrix);
projectionMatrix = XMMatrixTranspose(projectionMatrix);
// Mapper le buffer
HRESULT result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result))
return false;
dataPtr = (MatrixBufferType*)mappedResource.pData;
dataPtr->world = worldMatrix;
dataPtr->view = viewMatrix;
dataPtr->projection = projectionMatrix;
deviceContext->Unmap(matrix_buffer_, 0);
// D<>finir le buffer de constantes pour le vertex shader
deviceContext->VSSetConstantBuffers(0, 1, &matrix_buffer_);
return true;
}
void depth_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount)
{
// D<>finir le layout d'entr<74>e
deviceContext->IASetInputLayout(layout_);
// D<>finir les shaders
deviceContext->VSSetShader(vertex_shader_, nullptr, 0);
deviceContext->PSSetShader(pixel_shader_, nullptr, 0);
// Dessiner
deviceContext->DrawIndexed(indexCount, 0, 0);
}
void depth_shader_class::shutdown_shader()
{
// Lib<69>rer le buffer de matrice
if (matrix_buffer_)
{
matrix_buffer_->Release();
matrix_buffer_ = nullptr;
}
// Lib<69>rer le layout
if (layout_)
{
layout_->Release();
layout_ = nullptr;
}
// Lib<69>rer le pixel shader
if (pixel_shader_)
{
pixel_shader_->Release();
pixel_shader_ = nullptr;
}
// Lib<69>rer le vertex shader
if (vertex_shader_)
{
vertex_shader_->Release();
vertex_shader_ = nullptr;
}
}
void depth_shader_class::output_shader_error_message(ID3DBlob* errorMessage, HWND hwnd, const WCHAR* shaderFilename)
{
// Obtenir un pointeur vers le message d'erreur
char* compileErrors = (char*)(errorMessage->GetBufferPointer());
// Obtenir la taille du message
SIZE_T bufferSize = errorMessage->GetBufferSize();
// Allouer de la m<>moire pour le message d'erreur format<61>
char* message = new char[bufferSize + 100];
// D<>finir le message d'erreur format<61>
sprintf_s(message, bufferSize + 100, "Erreur de compilation du shader %ls :\n%s",
shaderFilename, compileErrors);
// Afficher le message d'erreur dans la console
Logger::Get().Log(message, __FILE__, __LINE__, Logger::LogLevel::Error);
// Afficher une bo<62>te de dialogue avec l'erreur
MessageBoxA(hwnd, message, "Erreur de Shader", MB_OK);
// Lib<69>rer la m<>moire
delete[] message;
}

View File

@@ -149,14 +149,6 @@ bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
return false;
}
depth_shader_ = new depth_shader_class;
result = depth_shader_->initialize(device, hwnd);
if (!result)
{
Logger::Get().Log("Error initializing depth_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
Logger::Get().Log("shader_manager_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true;
@@ -276,13 +268,6 @@ void shader_manager_class::shutdown()
skybox_shader_ = 0;
}
if (depth_shader_)
{
skybox_shader_->Shutdown();
delete depth_shader_;
depth_shader_ = 0;
}
Logger::Get().Log("shader_manager_class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
@@ -465,39 +450,12 @@ bool shader_manager_class::render_cel_shading_shader(ID3D11DeviceContext* device
return true;
}
bool shader_manager_class::render_sunlight_shader(
ID3D11DeviceContext* deviceContext,
int indexCount,
XMMATRIX worldMatrix,
XMMATRIX viewMatrix,
XMMATRIX projectionMatrix,
ID3D11ShaderResourceView* texture,
XMFLOAT4 diffuseColor,
XMFLOAT4 ambientColor,
XMFLOAT3 sunDirection,
float sunIntensity,
ID3D11ShaderResourceView* shadowMap,
XMMATRIX lightViewMatrix,
XMMATRIX lightProjectionMatrix
)
bool shader_manager_class::render_sunlight_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor, XMFLOAT4 ambientColor, XMFLOAT3 sunDirection, float sunIntensity)
{
bool result;
result = sunlight_shader_->render(
deviceContext,
indexCount,
worldMatrix,
viewMatrix,
projectionMatrix,
texture,
diffuseColor,
ambientColor,
sunDirection,
sunIntensity,
shadowMap,
lightViewMatrix,
lightProjectionMatrix
);
result = sunlight_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity);
if (!result)
{
return false;
@@ -519,16 +477,3 @@ bool shader_manager_class::render_skybox_shader(ID3D11DeviceContext* deviceConte
return true;
}
bool shader_manager_class::render_depth_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix)
{
bool result;
result = depth_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix);
if (!result)
{
return false;
}
return true;
}

View File

@@ -1,552 +1,462 @@
////////////////////////////////////////////////////////////////////////////////
// Filename: lightshaderclass.cpp
////////////////////////////////////////////////////////////////////////////////
#include "sunlight_shader_class.h"
sunlight_shader_class::sunlight_shader_class()
{
vertex_shader_ = nullptr;
pixel_shader_ = nullptr;
layout_ = nullptr;
sample_state_ = nullptr;
matrix_buffer_ = nullptr;
camera_buffer_ = nullptr;
sunlight_buffer_ = nullptr;
sunlight_color_buffer_ = nullptr;
sunlight_position_buffer_ = nullptr;
light_view_matrix_buffer_ = nullptr;
shadow_map_texture_ = nullptr;
shadow_sampler_state_ = nullptr;
vertex_shader_ = 0;
pixel_shader_ = 0;
layout_ = 0;
sample_state_ = 0;
matrix_buffer_ = 0;
camera_buffer_ = 0;
sunlight_buffer_ = 0;
sunlight_color_buffer_ = 0;
sunlight_position_buffer_ = 0;
}
sunlight_shader_class::sunlight_shader_class(const sunlight_shader_class&)
sunlight_shader_class::sunlight_shader_class(const sunlight_shader_class& other)
{
}
sunlight_shader_class::~sunlight_shader_class()
{
}
bool sunlight_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{
bool result;
WCHAR vs_filename[128];
WCHAR ps_filename[128];
Logger::Get().Log("Initializing LightShaderClass", __FILE__, __LINE__, Logger::LogLevel::Initialize);
// D<>finir les fichiers des shaders vertex et pixel
wcscpy_s(vs_filename, 128, L"./src/hlsl/sunlight.vs");
wcscpy_s(ps_filename, 128, L"./src/hlsl/sunlight.ps");
wchar_t vsFilename[128];
wchar_t psFilename[128];
int error;
bool result;
// Initialiser les shaders
result = initialize_shader(device, hwnd, vs_filename, ps_filename);
if (!result)
{
Logger::Get().Log("<EFBFBD>chec d'initialisation des shaders sunlight", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the filename of the vertex shader.
error = wcscpy_s(vsFilename, 128, L"src/hlsl/sunlight.vs");
if (error != 0)
{
Logger::Get().Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
return true;
// Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/sunlight.ps");
if (error != 0)
{
Logger::Get().Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result)
{
Logger::Get().Log("Failed to initialize shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
Logger::Get().Log("SunLightShaderClass initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true;
}
void sunlight_shader_class::shutdown()
{
shutdown_shader();
return;
// shutdown the vertex and pixel shaders as well as the related objects.
shutdown_shader();
return;
}
bool sunlight_shader_class::render(ID3D11DeviceContext* device_context, int index_count, XMMATRIX world_matrix, XMMATRIX view_matrix, XMMATRIX projection_matrix, ID3D11ShaderResourceView* texture, XMFLOAT4 diffuse_color, XMFLOAT4 ambient_color, XMFLOAT3 sun_direction, float sun_intensity, ID3D11ShaderResourceView* shadow_map, XMMATRIX light_view_matrix, XMMATRIX light_projection_matrix)
bool sunlight_shader_class::render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor, XMFLOAT4 ambientColor, XMFLOAT3 sunDirection, float sunIntensity)
{
bool result;
bool result;
// D<>finir les param<61>tres du shader
result = set_shader_parameters(device_context, world_matrix, view_matrix, projection_matrix, texture, diffuse_color, ambient_color, sun_direction, sun_intensity, shadow_map, light_view_matrix, light_projection_matrix);
if (!result)
{
Logger::Get().Log("<EFBFBD>chec de d<>finition des param<61>tres du shader sunlight", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Rendre le shader
render_shader(device_context, index_count);
// Set the shader parameters that it will use for rendering.
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity);
if (!result)
{
Logger::Get().Log("Failed to set shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
return true;
// Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount);
return true;
}
bool sunlight_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vs_filename, WCHAR* ps_filename)
bool sunlight_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{
HRESULT result;
ID3D10Blob* error_message = nullptr;
ID3D10Blob* vertex_shader_buffer = nullptr;
ID3D10Blob* pixel_shader_buffer = nullptr;
D3D11_INPUT_ELEMENT_DESC polygon_layout[3];
unsigned int num_elements;
D3D11_BUFFER_DESC matrix_buffer_desc;
D3D11_BUFFER_DESC camera_buffer_desc;
D3D11_BUFFER_DESC light_buffer_desc;
D3D11_BUFFER_DESC light_color_buffer_desc;
D3D11_BUFFER_DESC light_view_matrix_buffer_desc;
D3D11_SAMPLER_DESC sampler_desc;
D3D11_SAMPLER_DESC shadow_sampler_desc;
Logger::Get().Log("Initializing shader", __FILE__, __LINE__, Logger::LogLevel::Initialize);
// Compiler le vertex shader
result = D3DCompileFromFile(vs_filename, NULL, NULL, "SunLightVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, &vertex_shader_buffer, &error_message);
if (FAILED(result))
{
if (error_message)
{
output_shader_error_message(error_message, hwnd, vs_filename);
}
else
{
MessageBox(hwnd, vs_filename, L"Fichier shader manquant", MB_OK);
}
HRESULT result;
ID3D10Blob* errorMessage;
ID3D10Blob* vertexShaderBuffer;
ID3D10Blob* pixelShaderBuffer;
D3D11_INPUT_ELEMENT_DESC polygonLayout[3];
unsigned int numElements;
D3D11_SAMPLER_DESC samplerDesc;
D3D11_BUFFER_DESC matrixBufferDesc;
D3D11_BUFFER_DESC sunlightBufferDesc;
return false;
}
// initialize the pointers this function will use to null.
errorMessage = 0;
vertexShaderBuffer = 0;
pixelShaderBuffer = 0;
// Compiler le pixel shader
result = D3DCompileFromFile(ps_filename, NULL, NULL, "SunLightPixelShader", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, &pixel_shader_buffer, &error_message);
if (FAILED(result))
{
if (error_message)
{
output_shader_error_message(error_message, hwnd, ps_filename);
}
else
{
MessageBox(hwnd, ps_filename, L"Fichier shader manquant", MB_OK);
}
// Compile the vertex shader code.
result = D3DCompileFromFile(vsFilename, NULL, NULL, "SunLightVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, &vertexShaderBuffer, &errorMessage);
if (FAILED(result))
{
if (errorMessage)
{
output_shader_error_message(errorMessage, hwnd, vsFilename);
}
else
{
Logger::Get().Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error);
}
return false;
}
return false;
}
// Compile the pixel shader code.
result = D3DCompileFromFile(psFilename, NULL, NULL, "SunLightPixelShader", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, &pixelShaderBuffer, &errorMessage);
if (FAILED(result))
{
if (errorMessage)
{
output_shader_error_message(errorMessage, hwnd, psFilename);
}
else
{
Logger::Get().Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error);
}
return false;
}
// Cr<EFBFBD>er le vertex shader <EFBFBD> partir du buffer
result = device->CreateVertexShader(vertex_shader_buffer->GetBufferPointer(), vertex_shader_buffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result))
{
Logger::Get().Log("<EFBFBD>chec de cr<EFBFBD>ation du vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result))
{
Logger::Get().Log("Failed to create vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Cr<EFBFBD>er le pixel shader <EFBFBD> partir du buffer
result = device->CreatePixelShader(pixel_shader_buffer->GetBufferPointer(), pixel_shader_buffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result))
{
Logger::Get().Log("<EFBFBD>chec de cr<EFBFBD>ation du pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result))
{
Logger::Get().Log("Failed to create pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Cr<EFBFBD>er le layout d'entr<74>e du vertex shader
polygon_layout[0].SemanticName = "POSITION";
polygon_layout[0].SemanticIndex = 0;
polygon_layout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
polygon_layout[0].InputSlot = 0;
polygon_layout[0].AlignedByteOffset = 0;
polygon_layout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygon_layout[0].InstanceDataStepRate = 0;
// Create the vertex input layout description.
polygonLayout[0].SemanticName = "POSITION";
polygonLayout[0].SemanticIndex = 0;
polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
polygonLayout[0].InputSlot = 0;
polygonLayout[0].AlignedByteOffset = 0;
polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[0].InstanceDataStepRate = 0;
polygon_layout[1].SemanticName = "TEXCOORD";
polygon_layout[1].SemanticIndex = 0;
polygon_layout[1].Format = DXGI_FORMAT_R32G32_FLOAT;
polygon_layout[1].InputSlot = 0;
polygon_layout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
polygon_layout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygon_layout[1].InstanceDataStepRate = 0;
polygonLayout[1].SemanticName = "TEXCOORD";
polygonLayout[1].SemanticIndex = 0;
polygonLayout[1].Format = DXGI_FORMAT_R32G32_FLOAT;
polygonLayout[1].InputSlot = 0;
polygonLayout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[1].InstanceDataStepRate = 0;
polygon_layout[2].SemanticName = "NORMAL";
polygon_layout[2].SemanticIndex = 0;
polygon_layout[2].Format = DXGI_FORMAT_R32G32B32_FLOAT;
polygon_layout[2].InputSlot = 0;
polygon_layout[2].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
polygon_layout[2].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygon_layout[2].InstanceDataStepRate = 0;
polygonLayout[2].SemanticName = "NORMAL";
polygonLayout[2].SemanticIndex = 0;
polygonLayout[2].Format = DXGI_FORMAT_R32G32B32_FLOAT;
polygonLayout[2].InputSlot = 0;
polygonLayout[2].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
polygonLayout[2].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[2].InstanceDataStepRate = 0;
// Obtenir le nombre d'<27>l<EFBFBD>ments dans le layout
num_elements = sizeof(polygon_layout) / sizeof(polygon_layout[0]);
// Get a count of the elements in the layout.
numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]);
// Cr<EFBFBD>er le layout d'entr<74>e du vertex
result = device->CreateInputLayout(polygon_layout, num_elements, vertex_shader_buffer->GetBufferPointer(), vertex_shader_buffer->GetBufferSize(), &layout_);
if (FAILED(result))
{
Logger::Get().Log("<EFBFBD>chec de cr<EFBFBD>ation du layout d'entr<74>e", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create the vertex input layout.
result = device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result))
{
Logger::Get().Log("Failed to create input layout", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Lib<69>rer les buffers des shaders
vertex_shader_buffer->Release();
vertex_shader_buffer = nullptr;
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
vertexShaderBuffer->Release();
vertexShaderBuffer = 0;
pixel_shader_buffer->Release();
pixel_shader_buffer = nullptr;
pixelShaderBuffer->Release();
pixelShaderBuffer = 0;
// Configurer les descripteurs des buffers constants
// Descripteur du buffer de matrices
matrix_buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
matrix_buffer_desc.ByteWidth = sizeof(matrix_buffer_type);
matrix_buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
matrix_buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
matrix_buffer_desc.MiscFlags = 0;
matrix_buffer_desc.StructureByteStride = 0;
// Create a texture sampler state description.
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.MipLODBias = 0.0f;
samplerDesc.MaxAnisotropy = 1;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
samplerDesc.BorderColor[0] = 0;
samplerDesc.BorderColor[1] = 0;
samplerDesc.BorderColor[2] = 0;
samplerDesc.BorderColor[3] = 0;
samplerDesc.MinLOD = 0;
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
// Cr<EFBFBD>er le buffer constant de matrices
result = device->CreateBuffer(&matrix_buffer_desc, NULL, &matrix_buffer_);
if (FAILED(result))
{
Logger::Get().Log("<EFBFBD>chec de cr<EFBFBD>ation du buffer constant de matrices", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create the texture sampler state.
result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result))
{
Logger::Get().Log("Failed to create sampler state", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Descripteur du buffer de cam<61>ra
camera_buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
camera_buffer_desc.ByteWidth = sizeof(camera_buffer_type);
camera_buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
camera_buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
camera_buffer_desc.MiscFlags = 0;
camera_buffer_desc.StructureByteStride = 0;
// Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
matrixBufferDesc.ByteWidth = sizeof(matrix_buffer_type);
matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
matrixBufferDesc.MiscFlags = 0;
matrixBufferDesc.StructureByteStride = 0;
// Cr<EFBFBD>er le buffer constant de cam<EFBFBD>ra
result = device->CreateBuffer(&camera_buffer_desc, NULL, &camera_buffer_);
if (FAILED(result))
{
Logger::Get().Log("<EFBFBD>chec de cr<EFBFBD>ation du buffer constant de cam<61>ra", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create the constant buffer pointer so we can access the vertex shader constant buffer from within this class.
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result))
{
Logger::Get().Log("Failed to create matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Descripteur du buffer de lumi<6D>re du soleil
light_buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
light_buffer_desc.ByteWidth = sizeof(sun_light_buffer_type);
light_buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
light_buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
light_buffer_desc.MiscFlags = 0;
light_buffer_desc.StructureByteStride = 0;
// Setup the description of the dynamic sunlight constant buffer that is in the pixel shader.
sunlightBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
sunlightBufferDesc.ByteWidth = sizeof(sun_light_buffer_type);
sunlightBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
sunlightBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
sunlightBufferDesc.MiscFlags = 0;
sunlightBufferDesc.StructureByteStride = 0;
// Cr<EFBFBD>er le buffer constant de lumi<6D>re du soleil
result = device->CreateBuffer(&light_buffer_desc, NULL, &sunlight_buffer_);
if (FAILED(result))
{
Logger::Get().Log("<EFBFBD>chec de cr<EFBFBD>ation du buffer constant de lumi<6D>re du soleil", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create the constant buffer pointer so we can access the pixel shader constant buffer from within this class.
result = device->CreateBuffer(&sunlightBufferDesc, NULL, &sunlight_buffer_);
if (FAILED(result))
{
Logger::Get().Log("Failed to create sunlight buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Descripteur du buffer de couleur de lumi<6D>re du soleil
light_color_buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
light_color_buffer_desc.ByteWidth = sizeof(sun_light_color_buffer_type);
light_color_buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
light_color_buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
light_color_buffer_desc.MiscFlags = 0;
light_color_buffer_desc.StructureByteStride = 0;
Logger::Get().Log("Shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
// Cr<43>er le buffer constant de couleur de lumi<6D>re du soleil
result = device->CreateBuffer(&light_color_buffer_desc, NULL, &sunlight_color_buffer_);
if (FAILED(result))
{
Logger::Get().Log("<EFBFBD>chec de cr<63>ation du buffer constant de couleur de lumi<6D>re du soleil", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Descripteur du buffer de matrices de vue de lumi<6D>re
light_view_matrix_buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
light_view_matrix_buffer_desc.ByteWidth = sizeof(light_view_matrix_buffer_type);
light_view_matrix_buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
light_view_matrix_buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
light_view_matrix_buffer_desc.MiscFlags = 0;
light_view_matrix_buffer_desc.StructureByteStride = 0;
// Cr<43>er le buffer constant de matrices de vue de lumi<6D>re
result = device->CreateBuffer(&light_view_matrix_buffer_desc, NULL, &light_view_matrix_buffer_);
if (FAILED(result))
{
Logger::Get().Log("<EFBFBD>chec de cr<63>ation du buffer constant de matrices de vue de lumi<6D>re", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Cr<43>er un sampler state pour la texture
sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
sampler_desc.MipLODBias = 0.0f;
sampler_desc.MaxAnisotropy = 1;
sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
sampler_desc.BorderColor[0] = 0;
sampler_desc.BorderColor[1] = 0;
sampler_desc.BorderColor[2] = 0;
sampler_desc.BorderColor[3] = 0;
sampler_desc.MinLOD = 0;
sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
// Cr<43>er le sampler state
result = device->CreateSamplerState(&sampler_desc, &sample_state_);
if (FAILED(result))
{
Logger::Get().Log("<EFBFBD>chec de cr<63>ation du sampler state", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Cr<43>er un sampler state pour la shadow map
shadow_sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
shadow_sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_BORDER;
shadow_sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_BORDER;
shadow_sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
shadow_sampler_desc.MipLODBias = 0.0f;
shadow_sampler_desc.MaxAnisotropy = 1;
shadow_sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
shadow_sampler_desc.BorderColor[0] = 1.0f;
shadow_sampler_desc.BorderColor[1] = 1.0f;
shadow_sampler_desc.BorderColor[2] = 1.0f;
shadow_sampler_desc.BorderColor[3] = 1.0f;
shadow_sampler_desc.MinLOD = 0;
shadow_sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
// Cr<43>er le sampler state pour la shadow map
result = device->CreateSamplerState(&shadow_sampler_desc, &shadow_sampler_state_);
if (FAILED(result))
{
Logger::Get().Log("<EFBFBD>chec de cr<63>ation du sampler state pour la shadow map", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
return true;
return true;
}
void sunlight_shader_class::shutdown_shader()
{
// Lib<69>rer tous les objets
if (shadow_sampler_state_)
{
shadow_sampler_state_->Release();
shadow_sampler_state_ = nullptr;
}
Logger::Get().Log("Shutting down SunLightShaderClass", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
if (light_view_matrix_buffer_)
{
light_view_matrix_buffer_->Release();
light_view_matrix_buffer_ = nullptr;
}
// Release the light constant buffers.
if (sunlight_color_buffer_)
{
sunlight_color_buffer_->Release();
sunlight_color_buffer_ = 0;
}
if (sunlight_color_buffer_)
{
sunlight_color_buffer_->Release();
sunlight_color_buffer_ = nullptr;
}
if (sunlight_position_buffer_)
{
sunlight_position_buffer_->Release();
sunlight_position_buffer_ = 0;
}
if (sunlight_buffer_)
{
sunlight_buffer_->Release();
sunlight_buffer_ = nullptr;
}
// Release the light constant buffer.
if (sunlight_buffer_)
{
sunlight_buffer_->Release();
sunlight_buffer_ = 0;
}
if (camera_buffer_)
{
camera_buffer_->Release();
camera_buffer_ = nullptr;
}
// Release the camera constant buffer.
if (camera_buffer_)
{
camera_buffer_->Release();
camera_buffer_ = 0;
}
if (matrix_buffer_)
{
matrix_buffer_->Release();
matrix_buffer_ = nullptr;
}
// Release the matrix constant buffer.
if (matrix_buffer_)
{
matrix_buffer_->Release();
matrix_buffer_ = 0;
}
if (sample_state_)
{
sample_state_->Release();
sample_state_ = nullptr;
}
// Release the sampler state.
if (sample_state_)
{
sample_state_->Release();
sample_state_ = 0;
}
if (layout_)
{
layout_->Release();
layout_ = nullptr;
}
// Release the layout.
if (layout_)
{
layout_->Release();
layout_ = 0;
}
if (pixel_shader_)
{
pixel_shader_->Release();
pixel_shader_ = nullptr;
}
// Release the pixel shader.
if (pixel_shader_)
{
pixel_shader_->Release();
pixel_shader_ = 0;
}
if (vertex_shader_)
{
vertex_shader_->Release();
vertex_shader_ = nullptr;
}
// Release the vertex shader.
if (vertex_shader_)
{
vertex_shader_->Release();
vertex_shader_ = 0;
}
return;
Logger::Get().Log("SunLightShaderClass shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
return;
}
void sunlight_shader_class::output_shader_error_message(ID3D10Blob* error_message, HWND hwnd, WCHAR* shader_filename)
void sunlight_shader_class::output_shader_error_message(ID3D10Blob* errorMessage, HWND hwnd, WCHAR* shaderFilename)
{
char* compile_errors;
unsigned long long buffer_size;
ofstream fout;
char* compileErrors;
unsigned __int64 bufferSize, i;
ofstream fout;
// Obtenir un pointeur vers le texte d'erreur dans le buffer d'erreur
compile_errors = (char*)(error_message->GetBufferPointer());
// Obtenir la taille du message
buffer_size = error_message->GetBufferSize();
// Get a pointer to the error message text buffer.
compileErrors = (char*)(errorMessage->GetBufferPointer());
// Ouvrir un fichier pour <20>crire les messages d'erreur
fout.open("shader-error.txt");
// Get the length of the message.
bufferSize = errorMessage->GetBufferSize();
// <20>crire le message d'erreur
for (unsigned long long i = 0; i < buffer_size; i++)
{
fout << compile_errors[i];
}
// Open a file to write the error message to.
fout.open("shader-error.txt");
// Fermer le fichier
fout.close();
// Write out the error message.
for (i = 0; i < bufferSize; i++)
{
fout << compileErrors[i];
}
// Lib<69>rer le buffer d'erreur
error_message->Release();
error_message = nullptr;
// Close the file.
fout.close();
// Afficher un message d'erreur
MessageBox(hwnd, L"Erreur de compilation du shader. Voir shader-error.txt pour plus de d<>tails.", shader_filename, MB_OK);
// Release the error message.
errorMessage->Release();
errorMessage = 0;
return;
// Pop a message up on the screen to notify the user to check the text file for compile errors.
MessageBox(hwnd, L"Error compiling shader. Check shader-error.txt for message.", shaderFilename, MB_OK);
return;
}
bool sunlight_shader_class::set_shader_parameters(ID3D11DeviceContext* device_context, XMMATRIX world_matrix, XMMATRIX view_matrix, XMMATRIX projection_matrix, ID3D11ShaderResourceView* texture, XMFLOAT4 diffuse_color, XMFLOAT4 ambient_color, XMFLOAT3 sun_direction, float sun_intensity, ID3D11ShaderResourceView* shadow_map, XMMATRIX light_view_matrix, XMMATRIX light_projection_matrix)
bool sunlight_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, ID3D11ShaderResourceView* texture, XMFLOAT4 ambientColor, XMFLOAT4 diffuseColor, XMFLOAT3 lightDirection, float sunIntensity)
{
HRESULT result;
D3D11_MAPPED_SUBRESOURCE mapped_resource;
matrix_buffer_type* data_ptr;
camera_buffer_type* camera_data_ptr;
sun_light_buffer_type* light_data_ptr;
sun_light_color_buffer_type* light_color_data_ptr;
light_view_matrix_buffer_type* light_view_data_ptr;
HRESULT result;
D3D11_MAPPED_SUBRESOURCE mappedResource;
matrix_buffer_type* dataPtr;
camera_buffer_type* dataPtr2;
sun_light_buffer_type* dataPtr3;
unsigned int bufferNumber;
// Transposer les matrices pour qu'elles soient pr<70>tes pour le shader
world_matrix = XMMatrixTranspose(world_matrix);
view_matrix = XMMatrixTranspose(view_matrix);
projection_matrix = XMMatrixTranspose(projection_matrix);
light_view_matrix = XMMatrixTranspose(light_view_matrix);
light_projection_matrix = XMMatrixTranspose(light_projection_matrix);
// Transpose the matrices to prepare them for the shader.
worldMatrix = XMMatrixTranspose(worldMatrix);
viewMatrix = XMMatrixTranspose(viewMatrix);
projectionMatrix = XMMatrixTranspose(projectionMatrix);
// Verrouiller le buffer constant pour l'<27>criture
result = device_context->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource);
if (FAILED(result))
{
Logger::Get().Log("<EFBFBD>chec du verrouillage du buffer constant de matrices", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Lock the constant buffer so it can be written to.
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result))
{
return false;
}
// Obtenir un pointeur vers les donn<6E>es
data_ptr = (matrix_buffer_type*)mapped_resource.pData;
// Get a pointer to the data in the constant buffer.
dataPtr = (matrix_buffer_type*)mappedResource.pData;
// Copier les matrices dans le buffer constant
data_ptr->world = world_matrix;
data_ptr->view = view_matrix;
data_ptr->projection = projection_matrix;
// Copy the matrices into the constant buffer.
dataPtr->world = worldMatrix;
dataPtr->view = viewMatrix;
dataPtr->projection = projectionMatrix;
// D<>verrouiller le buffer constant
device_context->Unmap(matrix_buffer_, 0);
// Unlock the constant buffer.
deviceContext->Unmap(matrix_buffer_, 0);
// D<>finir la position du buffer constant dans le vertex shader
unsigned int buffer_number = 0;
// Set the position of the constant buffer in the vertex shader.
bufferNumber = 0;
// D<>finir le buffer constant du vertex shader
device_context->VSSetConstantBuffers(buffer_number, 1, &matrix_buffer_);
// Finally set the constant buffer in the vertex shader with the updated values.
deviceContext->VSSetConstantBuffers(bufferNumber, 1, &matrix_buffer_);
// Verrouiller le buffer constant de cam<61>ra
result = device_context->Map(camera_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource);
if (FAILED(result))
{
Logger::Get().Log("<EFBFBD>chec du verrouillage du buffer constant de cam<61>ra", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Lock the sunlight constant buffer so it can be written to.
result = deviceContext->Map(sunlight_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result))
{
return false;
}
// Obtenir un pointeur vers les donn<6E>es
camera_data_ptr = (camera_buffer_type*)mapped_resource.pData;
// Get a pointer to the data in the constant buffer.
dataPtr3 = (sun_light_buffer_type*)mappedResource.pData;
// TODO: Ajouter la position de la cam<61>ra ici si n<>cessaire
camera_data_ptr->camera_position = XMFLOAT3(0.0f, 0.0f, 0.0f);
camera_data_ptr->padding = 0.0f;
// Copy the lighting variables into the constant buffer.
dataPtr3->ambient_color = ambientColor;
dataPtr3->diffuse_color = diffuseColor;
dataPtr3->sun_direction = lightDirection;
dataPtr3->intensity = sunIntensity;
// D<>verrouiller le buffer constant
device_context->Unmap(camera_buffer_, 0);
// Unlock the constant buffer.
deviceContext->Unmap(sunlight_buffer_, 0);
// D<>finir la position du buffer constant dans le vertex shader
buffer_number = 1;
// Set the position of the sunlight constant buffer in the pixel shader.
bufferNumber = 0;
// D<>finir le buffer constant du vertex shader
device_context->VSSetConstantBuffers(buffer_number, 1, &camera_buffer_);
// Finally set the sunlight constant buffer in the pixel shader with the updated values.
deviceContext->PSSetConstantBuffers(bufferNumber, 1, &sunlight_buffer_);
// Verrouiller le buffer constant de lumi<6D>re
result = device_context->Map(sunlight_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource);
if (FAILED(result))
{
Logger::Get().Log("<EFBFBD>chec du verrouillage du buffer constant de lumi<6D>re", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set shader texture resource in the pixel shader.
deviceContext->PSSetShaderResources(0, 1, &texture);
// Obtenir un pointeur vers les donn<6E>es
light_data_ptr = (sun_light_buffer_type*)mapped_resource.pData;
// Copier les param<61>tres de lumi<6D>re dans le buffer constant
light_data_ptr->ambient_color = ambient_color;
light_data_ptr->diffuse_color = diffuse_color;
light_data_ptr->sun_direction = sun_direction;
light_data_ptr->intensity = sun_intensity;
// D<>verrouiller le buffer constant
device_context->Unmap(sunlight_buffer_, 0);
// D<>finir la position du buffer constant dans le pixel shader
buffer_number = 0;
// D<>finir le buffer constant du pixel shader
device_context->PSSetConstantBuffers(buffer_number, 1, &sunlight_buffer_);
device_context->VSSetConstantBuffers(buffer_number, 1, &sunlight_buffer_);
// Verrouiller le buffer constant de matrices de vue de lumi<6D>re
result = device_context->Map(light_view_matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource);
if (FAILED(result))
{
Logger::Get().Log("<EFBFBD>chec du verrouillage du buffer constant de matrices de vue de lumi<6D>re", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Obtenir un pointeur vers les donn<6E>es
light_view_data_ptr = (light_view_matrix_buffer_type*)mapped_resource.pData;
// Copier les matrices de vue de lumi<6D>re dans le buffer constant
light_view_data_ptr->light_view = light_view_matrix;
light_view_data_ptr->light_projection = light_projection_matrix;
// D<>verrouiller le buffer constant
device_context->Unmap(light_view_matrix_buffer_, 0);
// D<>finir la position du buffer constant dans le vertex shader
buffer_number = 2;
// D<>finir le buffer constant du vertex shader
device_context->VSSetConstantBuffers(buffer_number, 1, &light_view_matrix_buffer_);
// D<>finir la ressource de texture du shader
device_context->PSSetShaderResources(0, 1, &texture);
// D<>finir la ressource de shadow map du shader
device_context->PSSetShaderResources(1, 1, &shadow_map);
// D<>finir les sampler states dans le pixel shader
device_context->PSSetSamplers(0, 1, &sample_state_);
device_context->PSSetSamplers(1, 1, &shadow_sampler_state_);
return true;
return true;
}
void sunlight_shader_class::render_shader(ID3D11DeviceContext* device_context, int index_count)
void sunlight_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount)
{
// D<>finir le layout du vertex input
device_context->IASetInputLayout(layout_);
// Set the vertex input layout.
deviceContext->IASetInputLayout(layout_);
// D<>finir les shaders vertex et pixel
device_context->VSSetShader(vertex_shader_, NULL, 0);
device_context->PSSetShader(pixel_shader_, NULL, 0);
// Set the vertex and pixel shaders that will be used to render this triangle.
deviceContext->VSSetShader(vertex_shader_, NULL, 0);
deviceContext->PSSetShader(pixel_shader_, NULL, 0);
// Rendre la g<>om<6F>trie
device_context->DrawIndexed(index_count, 0, 0);
// Set the sampler state in the pixel shader.
deviceContext->PSSetSamplers(0, 1, &sample_state_);
return;
}
// render the triangle.
deviceContext->DrawIndexed(indexCount, 0, 0);
return;
}

View File

@@ -126,14 +126,6 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
camera_->set_rotation(0.0f, 0.0f, 0.0f);
camera_->render();
camera_->get_view_matrix(base_view_matrix_);
// create the ligth camera
light_camera_ = new camera_class;
if (!light_camera_)
{
Logger::Get().Log("Could not create the light camera object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the font shader object.
font_shader_ = new font_shader_class;
@@ -473,13 +465,6 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
return false;
}
shadow_map_ = new shadow_map();
if (!shadow_map_->initialize(direct_3d_->get_device(), screenWidth, screenHeight))
{
Logger::Get().Log("Could not create the shadow map object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
physics_ = new physics;
physics_thread_ = std::thread(&application_class::physics_thread_function, this);
@@ -508,12 +493,6 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
void application_class::shutdown()
{
Logger::Get().Log("Shutting down application class", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
if (shadow_map_) {
shadow_map_->shutdown();
delete shadow_map_;
shadow_map_ = nullptr;
}
// Release the shader manager object.
if (shader_manager_)
@@ -1039,11 +1018,11 @@ bool application_class::render(float rotation, float x, float y, float z, float
// Redimensionner la texture de rendu si n<>cessaire
if (DEBUG_MODE)
{
// if ((float)scene_texture_->GetTextureWidth() != window_size_.x || (float)scene_texture_->GetTextureHeight() != window_size_.y)
// {
// scene_texture_->Shutdown();
// scene_texture_->Initialize(direct_3d_->get_device(), (int)window_size_.x, (int)window_size_.y, screen_depth, screen_near, 1);
// }
if ((float)scene_texture_->GetTextureWidth() != window_size_.x || (float)scene_texture_->GetTextureHeight() != window_size_.y)
{
scene_texture_->Shutdown();
scene_texture_->Initialize(direct_3d_->get_device(), (int)window_size_.x, (int)window_size_.y, screen_depth, screen_near, 1);
}
direct_3d_->set_back_buffer_render_target();
direct_3d_->reset_viewport();
@@ -1074,51 +1053,9 @@ bool application_class::render(float rotation, float x, float y, float z, float
direct_3d_->turn_z_buffer_on(); // Enable the Z buffer after rendering the skybox.
// --------------------------------------------------------- //
// ------------------ shadow map creation ------------------ //
// --------------------------------------------------------- //
shadow_map_->set_render_target(direct_3d_->get_device_context());
shadow_map_->clear_render_target(direct_3d_->get_device_context(), 1.0f);
// Configuration de la cam<61>ra de lumi<6D>re
light_position_buffer_ = sun_light_->GetPosition();
light_rotation_buffer_ = sun_light_->GetDirection();
// Positionnez la cam<61>ra de lumi<6D>re <20> une position appropri<72>e pour votre sc<73>ne
float lightDistance = 100.0f;
light_camera_->set_position(-light_rotation_buffer_.x * lightDistance, -light_rotation_buffer_.y * lightDistance, -light_rotation_buffer_.z * lightDistance);
light_camera_->set_rotation(light_rotation_buffer_.x, light_rotation_buffer_.y, light_rotation_buffer_.z);
light_camera_->render();
// R<>cup<75>ration explicite de la matrice de vue
light_camera_->get_view_matrix(light_view_matrix_);
// Cr<43>ation d'une matrice de projection orthographique avec des valeurs adapt<70>es
float lightViewWidth = 200.0f; // Agrandir la zone couverte par l'ombre
float lightViewHeight = 200.0f;
float lightNearPlane = 1.0f;
float lightFarPlane = 300.0f; // Augmenter la profondeur
light_projection_matrix_ = XMMatrixOrthographicLH(lightViewWidth, lightViewHeight, lightNearPlane, lightFarPlane);
// Rendu de la scene sans texture juste geometrie.
if (!create_shadow_map(render_queues_))
{
Logger::Get().Log("Error creating shadow map", __FILE__, __LINE__, Logger::LogLevel::Error);
}
shadow_srv_ = shadow_map_->get_shader_resource_view();
// 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.
direct_3d_->set_back_buffer_render_target();
direct_3d_->reset_viewport();
// -------------------------------------------------------- //
// ------------ render the object in the queue ------------ //
// -------------------------------------------------------- //
result = render_pass(render_queues_, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix);
if (!result)
{
@@ -1934,11 +1871,8 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
sun_light_->GetDiffuseColor(),
sun_light_->GetAmbientColor(),
sun_light_->GetDirection(),
sun_light_->GetIntensity(),
shadow_srv_,
light_view_matrix_,
light_projection_matrix_
);
sun_light_->GetIntensity()
);
if (!result)
{
Logger::Get().Log("Could not render the object model using the sunlight shader", __FILE__, __LINE__, Logger::LogLevel::Error);
@@ -1980,76 +1914,6 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
return true;
}
bool application_class::create_shadow_map(const std::vector<std::reference_wrapper<std::vector<object*>>>& RenderQueues)
{
for (auto& RenderQueue : RenderQueues)
{
if (&RenderQueue.get() == &skybox_)
{
continue; // Skip rendering the skybox_ for shadow mapping
}
for (auto& object : RenderQueue.get())
{
// V<>rification des ressources critiques
if (shadow_map_ == nullptr) {
Logger::Get().Log("shadow_map_ est nul!", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
if (light_camera_ == nullptr) {
Logger::Get().Log("light_camera_ est nul!", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
bool hasNaN = false;
for (int i = 0; i < 4; i++) {
XMVECTOR row = light_view_matrix_.r[i];
if (XMComparisonAnyTrue(XMVector4IsNaN(row))) {
hasNaN = true;
break;
}
}
if (hasNaN) {
Logger::Get().Log("light_view_matrix_ contient des valeurs invalides!", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
if (object == nullptr)
{
Logger::Get().Log("object is null", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
if (!object->IsVisible())
{
continue;
}
object->Render(direct_3d_->get_device_context());
bool result = shader_manager_->render_depth_shader(
direct_3d_->get_device_context(),
object->GetIndexCount(),
object->GetTranslateMatrix(),
light_view_matrix_,
light_projection_matrix_
);
if (!result)
{
Logger::Get().Log("Could not render the object model using the shadow map shader", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
}
}
return true;
}
void application_class::construct_frustum()
{
XMMATRIX projectionMatrix = direct_3d_->get_projection_matrix();

View File

@@ -1,105 +0,0 @@
#include "shadow_map.h"
#include "Logger.h"
shadow_map::shadow_map() :
depth_texture_(nullptr),
depth_stencil_view_(nullptr),
shader_resource_view_(nullptr)
{
ZeroMemory(&viewport_, sizeof(viewport_));
}
shadow_map::~shadow_map()
{
shutdown();
}
bool shadow_map::initialize(ID3D11Device* device, int shadow_map_width, int shadow_map_height)
{
D3D11_TEXTURE2D_DESC text_desc = {};
text_desc.Width = shadow_map_width;
text_desc.Height = shadow_map_height;
text_desc.MipLevels = 1;
text_desc.ArraySize = 1;
text_desc.Format = DXGI_FORMAT_R32_TYPELESS;
text_desc.SampleDesc.Count = 1;
text_desc.Usage = D3D11_USAGE_DEFAULT;
text_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
if (FAILED(device->CreateTexture2D(&text_desc, nullptr, &depth_texture_)))
{
Logger::Get().Log("Failed to create depth texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
D3D11_DEPTH_STENCIL_VIEW_DESC dsv_Desc = {};
dsv_Desc.Format = DXGI_FORMAT_D32_FLOAT;
dsv_Desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
dsv_Desc.Texture2D.MipSlice = 0;
if (FAILED(device->CreateDepthStencilView(depth_texture_, &dsv_Desc, &depth_stencil_view_)))
{
Logger::Get().Log("Failed to create depth texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc = {};
srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srv_desc.Texture2D.MostDetailedMip = 0;
srv_desc.Texture2D.MipLevels = 1;
if (FAILED(device->CreateShaderResourceView(depth_texture_, &srv_desc, &shader_resource_view_)))
{
Logger::Get().Log("Failed to create shader resource view", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
viewport_.Width = static_cast<FLOAT>(shadow_map_width);
viewport_.Height = static_cast<FLOAT>(shadow_map_height);
viewport_.MinDepth = 0.0f;
viewport_.MaxDepth = 1.0f;
viewport_.TopLeftX = 0.0f;
viewport_.TopLeftY = 0.0f;
Logger::Get().Log("Shadow map initialized", __FILE__, __LINE__, Logger::LogLevel::Info);
return true;
}
void shadow_map::set_render_target(ID3D11DeviceContext* context)
{
context->OMSetRenderTargets(0, nullptr, depth_stencil_view_);
context->RSSetViewports(1, &viewport_);
}
void shadow_map::clear_render_target(ID3D11DeviceContext* context, float depth)
{
context->ClearDepthStencilView(depth_stencil_view_, D3D11_CLEAR_DEPTH, depth, 0);
}
ID3D11ShaderResourceView* shadow_map::get_shader_resource_view() const
{
return shader_resource_view_;
}
void shadow_map::shutdown()
{
if (shader_resource_view_) {
shader_resource_view_->Release();
shader_resource_view_ = nullptr;
}
if (depth_stencil_view_) {
depth_stencil_view_->Release();
depth_stencil_view_ = nullptr;
}
if (depth_texture_) {
depth_texture_->Release();
depth_texture_ = nullptr;
}
Logger::Get().Log("Shadow map shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}