Patch - Sun camera Depth experiment - V10.5.3
This commit is contained in:
parent
eb2cd17ec3
commit
f20adee22f
15
.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
generated
15
.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
generated
@ -5,15 +5,17 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment="">
|
<list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment="">
|
||||||
<change afterPath="$PROJECT_DIR$/enginecustom/src/inc/shader/master_shader.h" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/enginecustom/src/hlsl/depth.ps" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/enginecustom/src/src/shader/master_shader.cpp" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/enginecustom/src/hlsl/depth.vs" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/enginecustom/src/inc/shader/depth_shader_class.h" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/enginecustom/src/src/shader/depth_shader_class.cpp" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/enginecustom/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/imgui.ini" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/enginecustom/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/imgui.ini" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/application_class.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/application_class.h" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/enginecustom/shader-error.txt" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/shader-error.txt" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/input_class.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/input_class.h" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/enginecustom/src/inc/shader/shader_manager_class.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/shader/shader_manager_class.h" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/shader/shader_manager_class.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/shader/shader_manager_class.cpp" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/application_class.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/application_class.cpp" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/application_class.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/application_class.cpp" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/input_class.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/input_class.cpp" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@ -201,7 +203,8 @@
|
|||||||
<workItem from="1747258663152" duration="835000" />
|
<workItem from="1747258663152" duration="835000" />
|
||||||
<workItem from="1747826758888" duration="3587000" />
|
<workItem from="1747826758888" duration="3587000" />
|
||||||
<workItem from="1747830379222" duration="7954000" />
|
<workItem from="1747830379222" duration="7954000" />
|
||||||
<workItem from="1748254142068" duration="4725000" />
|
<workItem from="1748254142068" duration="10499000" />
|
||||||
|
<workItem from="1748267553700" duration="654000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="Minor update - viewport window tweak">
|
<task id="LOCAL-00001" summary="Minor update - viewport window tweak">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
<ClCompile Include="src\src\shader\alpha_map_shader_class.cpp" />
|
<ClCompile Include="src\src\shader\alpha_map_shader_class.cpp" />
|
||||||
<ClCompile Include="src\src\shader\celshade_class.cpp" />
|
<ClCompile Include="src\src\shader\celshade_class.cpp" />
|
||||||
<ClCompile Include="src\src\shader\color_shader_class.cpp" />
|
<ClCompile Include="src\src\shader\color_shader_class.cpp" />
|
||||||
|
<ClCompile Include="src\src\shader\depth_shader_class.cpp" />
|
||||||
<ClCompile Include="src\src\shader\font_shader_class.cpp" />
|
<ClCompile Include="src\src\shader\font_shader_class.cpp" />
|
||||||
<ClCompile Include="src\src\shader\light_map_shader_class.cpp" />
|
<ClCompile Include="src\src\shader\light_map_shader_class.cpp" />
|
||||||
<ClCompile Include="src\src\shader\light_shader_class.cpp" />
|
<ClCompile Include="src\src\shader\light_shader_class.cpp" />
|
||||||
@ -93,6 +94,7 @@
|
|||||||
<ClInclude Include="src\inc\shader\alpha_map_shader_class.h" />
|
<ClInclude Include="src\inc\shader\alpha_map_shader_class.h" />
|
||||||
<ClInclude Include="src\inc\shader\celshade_class.h" />
|
<ClInclude Include="src\inc\shader\celshade_class.h" />
|
||||||
<ClInclude Include="src\inc\shader\color_shader_class.h" />
|
<ClInclude Include="src\inc\shader\color_shader_class.h" />
|
||||||
|
<ClInclude Include="src\inc\shader\depth_shader_class.h" />
|
||||||
<ClInclude Include="src\inc\shader\font_shader_class.h" />
|
<ClInclude Include="src\inc\shader\font_shader_class.h" />
|
||||||
<ClInclude Include="src\inc\shader\light_map_shader_class.h" />
|
<ClInclude Include="src\inc\shader\light_map_shader_class.h" />
|
||||||
<ClInclude Include="src\inc\shader\light_shader_class.h" />
|
<ClInclude Include="src\inc\shader\light_shader_class.h" />
|
||||||
@ -169,6 +171,16 @@
|
|||||||
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)\src\hlsl</DestinationFolders>
|
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)\src\hlsl</DestinationFolders>
|
||||||
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)\src\hlsl</DestinationFolders>
|
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)\src\hlsl</DestinationFolders>
|
||||||
</CopyFileToFolders>
|
</CopyFileToFolders>
|
||||||
|
<CopyFileToFolders Include="src\hlsl\depth.ps">
|
||||||
|
<DestinationFolders>F:\Github_Repo\khaotic-engine-Reborn\x64\Debug\\src\hlsl</DestinationFolders>
|
||||||
|
<DestinationFileName>%(Filename)%(Extension)</DestinationFileName>
|
||||||
|
<FileType>Document</FileType>
|
||||||
|
</CopyFileToFolders>
|
||||||
|
<CopyFileToFolders Include="src\hlsl\depth.vs">
|
||||||
|
<DestinationFolders>F:\Github_Repo\khaotic-engine-Reborn\x64\Debug\\src\hlsl</DestinationFolders>
|
||||||
|
<DestinationFileName>%(Filename)%(Extension)</DestinationFileName>
|
||||||
|
<FileType>Document</FileType>
|
||||||
|
</CopyFileToFolders>
|
||||||
<CopyFileToFolders Include="src\hlsl\font.ps">
|
<CopyFileToFolders Include="src\hlsl\font.ps">
|
||||||
<FileType>Document</FileType>
|
<FileType>Document</FileType>
|
||||||
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)\src\hlsl</DestinationFolders>
|
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)\src\hlsl</DestinationFolders>
|
||||||
|
@ -16,7 +16,7 @@ Collapsed=0
|
|||||||
DockId=0x00000011,0
|
DockId=0x00000011,0
|
||||||
|
|
||||||
[Window][Terrain]
|
[Window][Terrain]
|
||||||
Pos=283,19
|
Pos=0,19
|
||||||
Size=280,842
|
Size=280,842
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000007,0
|
DockId=0x00000007,0
|
||||||
|
Binary file not shown.
28
enginecustom/src/hlsl/depth.ps
Normal file
28
enginecustom/src/hlsl/depth.ps
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/////////////
|
||||||
|
// GLOBALS //
|
||||||
|
/////////////
|
||||||
|
Texture2D shaderTexture : register(t0);
|
||||||
|
SamplerState SampleType : register(s0);
|
||||||
|
|
||||||
|
//////////////
|
||||||
|
// TYPEDEFS //
|
||||||
|
//////////////
|
||||||
|
struct PixelInputType
|
||||||
|
{
|
||||||
|
float4 position : SV_POSITION;
|
||||||
|
float2 tex : TEXCOORD0;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Pixel Shader
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
float4 DepthPixelShader(PixelInputType input) : SV_TARGET
|
||||||
|
{
|
||||||
|
float4 textureColor;
|
||||||
|
|
||||||
|
|
||||||
|
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
|
||||||
|
textureColor = shaderTexture.Sample(SampleType, input.tex);
|
||||||
|
|
||||||
|
return textureColor;
|
||||||
|
}
|
47
enginecustom/src/hlsl/depth.vs
Normal file
47
enginecustom/src/hlsl/depth.vs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/////////////
|
||||||
|
// GLOBALS //
|
||||||
|
/////////////
|
||||||
|
cbuffer MatrixBuffer
|
||||||
|
{
|
||||||
|
matrix worldMatrix;
|
||||||
|
matrix viewMatrix;
|
||||||
|
matrix projectionMatrix;
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////
|
||||||
|
// TYPEDEFS //
|
||||||
|
//////////////
|
||||||
|
struct VertexInputType
|
||||||
|
{
|
||||||
|
float4 position : POSITION;
|
||||||
|
float2 tex : TEXCOORD0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PixelInputType
|
||||||
|
{
|
||||||
|
float4 position : SV_POSITION;
|
||||||
|
float2 tex : TEXCOORD0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Vertex Shader
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
PixelInputType DepthVertexShader(VertexInputType input)
|
||||||
|
{
|
||||||
|
PixelInputType output;
|
||||||
|
|
||||||
|
|
||||||
|
// 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, 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;
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
56
enginecustom/src/inc/shader/depth_shader_class.h
Normal file
56
enginecustom/src/inc/shader/depth_shader_class.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#ifndef _DEPTH_SHADER_CLASS_H_
|
||||||
|
#define _DEPTH_SHADER_CLASS_H_
|
||||||
|
|
||||||
|
|
||||||
|
//////////////
|
||||||
|
// INCLUDES //
|
||||||
|
//////////////
|
||||||
|
#include "Logger.h"
|
||||||
|
#include <d3d11.h>
|
||||||
|
#include <d3dcompiler.h>
|
||||||
|
#include <directxmath.h>
|
||||||
|
#include <fstream>
|
||||||
|
using namespace DirectX;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Class name: depth_shader_class
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
class depth_shader_class
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
struct matrix_buffer_type
|
||||||
|
{
|
||||||
|
XMMATRIX world;
|
||||||
|
XMMATRIX view;
|
||||||
|
XMMATRIX projection;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
depth_shader_class();
|
||||||
|
depth_shader_class(const depth_shader_class&);
|
||||||
|
~depth_shader_class();
|
||||||
|
|
||||||
|
bool initialize(ID3D11Device*, HWND);
|
||||||
|
void shutdown();
|
||||||
|
bool render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*);
|
||||||
|
|
||||||
|
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*);
|
||||||
|
void render_shader(ID3D11DeviceContext*, int);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ID3D11VertexShader* vertex_shader_;
|
||||||
|
ID3D11PixelShader* pixel_shader_;
|
||||||
|
ID3D11InputLayout* layout_;
|
||||||
|
ID3D11Buffer* matrix_buffer_;
|
||||||
|
ID3D11SamplerState* sample_state_;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -17,8 +17,10 @@
|
|||||||
#include "refraction_shader_class.h"
|
#include "refraction_shader_class.h"
|
||||||
#include "water_shader_class.h"
|
#include "water_shader_class.h"
|
||||||
#include "celshade_class.h"
|
#include "celshade_class.h"
|
||||||
|
#include "depth_shader_class.h"
|
||||||
#include "skybox_shader_class.h"
|
#include "skybox_shader_class.h"
|
||||||
#include "sunlight_shader_class.h"
|
#include "sunlight_shader_class.h"
|
||||||
|
#include "depth_shader_class.h"
|
||||||
|
|
||||||
using namespace DirectX;
|
using namespace DirectX;
|
||||||
|
|
||||||
@ -46,6 +48,14 @@ public:
|
|||||||
bool render_cel_shading_shader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, 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);
|
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_skybox_shader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float);
|
||||||
|
bool render_depth_shader(
|
||||||
|
ID3D11DeviceContext* context,
|
||||||
|
int indexCount,
|
||||||
|
XMMATRIX worldMatrix,
|
||||||
|
XMMATRIX viewMatrix,
|
||||||
|
XMMATRIX projectionMatrix,
|
||||||
|
ID3D11ShaderResourceView* texture
|
||||||
|
);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
texture_shader_class* texture_shader_;
|
texture_shader_class* texture_shader_;
|
||||||
@ -62,6 +72,7 @@ private:
|
|||||||
celshade_class* cel_shading_shader_;
|
celshade_class* cel_shading_shader_;
|
||||||
sunlight_shader_class* sunlight_shader_;
|
sunlight_shader_class* sunlight_shader_;
|
||||||
skybox_shader_class* skybox_shader_;
|
skybox_shader_class* skybox_shader_;
|
||||||
|
depth_shader_class* depth_shader_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
378
enginecustom/src/src/shader/depth_shader_class.cpp
Normal file
378
enginecustom/src/src/shader/depth_shader_class.cpp
Normal file
@ -0,0 +1,378 @@
|
|||||||
|
#include "depth_shader_class.h"
|
||||||
|
|
||||||
|
|
||||||
|
depth_shader_class::depth_shader_class()
|
||||||
|
{
|
||||||
|
vertex_shader_ = 0;
|
||||||
|
pixel_shader_ = 0;
|
||||||
|
layout_ = 0;
|
||||||
|
matrix_buffer_ = 0;
|
||||||
|
sample_state_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
depth_shader_class::depth_shader_class(const depth_shader_class& other)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
depth_shader_class::~depth_shader_class()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool depth_shader_class::initialize(ID3D11Device* device, HWND hwnd)
|
||||||
|
{
|
||||||
|
Logger::Get().Log("Initializing texture shader", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||||
|
|
||||||
|
bool result;
|
||||||
|
wchar_t vsFilename[128];
|
||||||
|
wchar_t psFilename[128];
|
||||||
|
int error;
|
||||||
|
// Set the filename of the vertex shader.
|
||||||
|
error = wcscpy_s(vsFilename, 128, L"src/hlsl/depth.vs");
|
||||||
|
if (error != 0)
|
||||||
|
{
|
||||||
|
Logger::Get().Log("Error copying stirng", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the filename of the pixel shader.
|
||||||
|
error = wcscpy_s(psFilename, 128, L"src/hlsl/depth.ps");
|
||||||
|
if (error != 0)
|
||||||
|
{
|
||||||
|
Logger::Get().Log("Error copying stirng", __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("Error initializing shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::Get().Log("Texture shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void depth_shader_class::shutdown()
|
||||||
|
{
|
||||||
|
// shutdown the vertex and pixel shaders as well as the related objects.
|
||||||
|
shutdown_shader();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool depth_shader_class::render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix,
|
||||||
|
XMMATRIX projectionMatrix, ID3D11ShaderResourceView* texture)
|
||||||
|
{
|
||||||
|
bool result;
|
||||||
|
|
||||||
|
|
||||||
|
// Set the shader parameters that it will use for rendering.
|
||||||
|
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
Logger::Get().Log("Error setting shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now render the prepared buffers with the shader.
|
||||||
|
render_shader(deviceContext, indexCount);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool depth_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
|
||||||
|
{
|
||||||
|
Logger::Get().Log("Initializing shader", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||||
|
|
||||||
|
HRESULT result;
|
||||||
|
ID3D10Blob* errorMessage;
|
||||||
|
ID3D10Blob* vertexShaderBuffer;
|
||||||
|
ID3D10Blob* pixelShaderBuffer;
|
||||||
|
D3D11_INPUT_ELEMENT_DESC polygonLayout[2];
|
||||||
|
unsigned int numElements;
|
||||||
|
D3D11_BUFFER_DESC matrixBufferDesc;
|
||||||
|
D3D11_SAMPLER_DESC samplerDesc;
|
||||||
|
|
||||||
|
|
||||||
|
// initialize the pointers this function will use to null.
|
||||||
|
errorMessage = 0;
|
||||||
|
vertexShaderBuffer = 0;
|
||||||
|
pixelShaderBuffer = 0;
|
||||||
|
// Compile the vertex shader code.
|
||||||
|
result = D3DCompileFromFile(vsFilename, NULL, NULL, "DepthVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0,
|
||||||
|
&vertexShaderBuffer, &errorMessage);
|
||||||
|
if (FAILED(result))
|
||||||
|
{
|
||||||
|
// If the shader failed to compile it should have writen something to the error message.
|
||||||
|
if (errorMessage)
|
||||||
|
{
|
||||||
|
output_shader_error_message(errorMessage, hwnd, vsFilename);
|
||||||
|
}
|
||||||
|
// If there was nothing in the error message then it simply could not find the shader file itself.
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compile the pixel shader code.
|
||||||
|
result = D3DCompileFromFile(psFilename, NULL, NULL, "DepthPixelShader", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0,
|
||||||
|
&pixelShaderBuffer, &errorMessage);
|
||||||
|
if (FAILED(result))
|
||||||
|
{
|
||||||
|
// If the shader failed to compile it should have writen something to the error message.
|
||||||
|
if (errorMessage)
|
||||||
|
{
|
||||||
|
output_shader_error_message(errorMessage, hwnd, psFilename);
|
||||||
|
}
|
||||||
|
// If there was nothing in the error message then it simply could not find the file itself.
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger::Get().Log("Error compiling 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("Error creating vertex 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("Error creating pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Create the vertex input layout description.
|
||||||
|
// This setup needs to match the VertexType stucture in the ModelClass and in the shader.
|
||||||
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Get a count of the elements in the layout.
|
||||||
|
numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]);
|
||||||
|
|
||||||
|
// Create the vertex input layout.
|
||||||
|
result = device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(),
|
||||||
|
vertexShaderBuffer->GetBufferSize(), &layout_);
|
||||||
|
if (FAILED(result))
|
||||||
|
{
|
||||||
|
Logger::Get().Log("Error creating input layout", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
|
||||||
|
vertexShaderBuffer->Release();
|
||||||
|
vertexShaderBuffer = 0;
|
||||||
|
|
||||||
|
pixelShaderBuffer->Release();
|
||||||
|
pixelShaderBuffer = 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;
|
||||||
|
|
||||||
|
// 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("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// Create the texture sampler state.
|
||||||
|
result = device->CreateSamplerState(&samplerDesc, &sample_state_);
|
||||||
|
if (FAILED(result))
|
||||||
|
{
|
||||||
|
Logger::Get().Log("Error creating sampler state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::Get().Log("Shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void depth_shader_class::shutdown_shader()
|
||||||
|
{
|
||||||
|
Logger::Get().Log("Shutting down shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
||||||
|
|
||||||
|
// Release the sampler state.
|
||||||
|
if (sample_state_)
|
||||||
|
{
|
||||||
|
sample_state_->Release();
|
||||||
|
sample_state_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release the matrix constant buffer.
|
||||||
|
if (matrix_buffer_)
|
||||||
|
{
|
||||||
|
matrix_buffer_->Release();
|
||||||
|
matrix_buffer_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release the layout.
|
||||||
|
if (layout_)
|
||||||
|
{
|
||||||
|
layout_->Release();
|
||||||
|
layout_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release the pixel shader.
|
||||||
|
if (pixel_shader_)
|
||||||
|
{
|
||||||
|
pixel_shader_->Release();
|
||||||
|
pixel_shader_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release the vertex shader.
|
||||||
|
if (vertex_shader_)
|
||||||
|
{
|
||||||
|
vertex_shader_->Release();
|
||||||
|
vertex_shader_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::Get().Log("Shader shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void depth_shader_class::output_shader_error_message(ID3D10Blob* errorMessage, HWND hwnd, WCHAR* shaderFilename)
|
||||||
|
{
|
||||||
|
char* compileErrors;
|
||||||
|
unsigned long long bufferSize, i;
|
||||||
|
ofstream fout;
|
||||||
|
|
||||||
|
|
||||||
|
// Get a pointer to the error message text buffer.
|
||||||
|
compileErrors = (char*)(errorMessage->GetBufferPointer());
|
||||||
|
|
||||||
|
// Get the length of the message.
|
||||||
|
bufferSize = errorMessage->GetBufferSize();
|
||||||
|
|
||||||
|
// Open a file to write the error message to.
|
||||||
|
fout.open("shader-error.txt");
|
||||||
|
|
||||||
|
// Write out the error message.
|
||||||
|
for (i = 0; i < bufferSize; i++)
|
||||||
|
{
|
||||||
|
fout << compileErrors[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the file.
|
||||||
|
fout.close();
|
||||||
|
|
||||||
|
// Release the error message.
|
||||||
|
errorMessage->Release();
|
||||||
|
errorMessage = 0;
|
||||||
|
|
||||||
|
// 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 depth_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix,
|
||||||
|
XMMATRIX projectionMatrix, ID3D11ShaderResourceView* texture)
|
||||||
|
{
|
||||||
|
HRESULT result;
|
||||||
|
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
||||||
|
matrix_buffer_type* dataPtr;
|
||||||
|
unsigned int bufferNumber;
|
||||||
|
|
||||||
|
|
||||||
|
// Transpose the matrices to prepare them for the shader.
|
||||||
|
worldMatrix = XMMatrixTranspose(worldMatrix);
|
||||||
|
viewMatrix = XMMatrixTranspose(viewMatrix);
|
||||||
|
projectionMatrix = XMMatrixTranspose(projectionMatrix);
|
||||||
|
|
||||||
|
// 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))
|
||||||
|
{
|
||||||
|
Logger::Get().Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a pointer to the data in the constant buffer.
|
||||||
|
dataPtr = (matrix_buffer_type*)mappedResource.pData;
|
||||||
|
|
||||||
|
// Copy the matrices into the constant buffer.
|
||||||
|
dataPtr->world = worldMatrix;
|
||||||
|
dataPtr->view = viewMatrix;
|
||||||
|
dataPtr->projection = projectionMatrix;
|
||||||
|
|
||||||
|
// Unlock the constant buffer.
|
||||||
|
deviceContext->Unmap(matrix_buffer_, 0);
|
||||||
|
|
||||||
|
// Set the position of the constant buffer in the vertex shader.
|
||||||
|
bufferNumber = 0;
|
||||||
|
|
||||||
|
// Finanly set the constant buffer in the vertex shader with the updated values.
|
||||||
|
deviceContext->VSSetConstantBuffers(bufferNumber, 1, &matrix_buffer_);
|
||||||
|
// Set shader texture resource in the pixel shader.
|
||||||
|
deviceContext->PSSetShaderResources(0, 1, &texture);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void depth_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount)
|
||||||
|
{
|
||||||
|
// Set the vertex input layout.
|
||||||
|
deviceContext->IASetInputLayout(layout_);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
// Set the sampler state in the pixel shader.
|
||||||
|
deviceContext->PSSetSamplers(0, 1, &sample_state_);
|
||||||
|
|
||||||
|
// render the triangle.
|
||||||
|
deviceContext->DrawIndexed(indexCount, 0, 0);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
@ -14,6 +14,10 @@ shader_manager_class::shader_manager_class()
|
|||||||
refraction_shader_ = 0;
|
refraction_shader_ = 0;
|
||||||
water_shader_ = 0;
|
water_shader_ = 0;
|
||||||
cel_shading_shader_ = 0;
|
cel_shading_shader_ = 0;
|
||||||
|
sunlight_shader_ = 0;
|
||||||
|
skybox_shader_ = 0;
|
||||||
|
refraction_shader_ = 0;
|
||||||
|
depth_shader_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
shader_manager_class::shader_manager_class(const shader_manager_class& other)
|
shader_manager_class::shader_manager_class(const shader_manager_class& other)
|
||||||
@ -149,6 +153,14 @@ bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
|
|||||||
return false;
|
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);
|
Logger::Get().Log("shader_manager_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -268,6 +280,13 @@ void shader_manager_class::shutdown()
|
|||||||
skybox_shader_ = 0;
|
skybox_shader_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (depth_shader_)
|
||||||
|
{
|
||||||
|
depth_shader_->shutdown();
|
||||||
|
delete depth_shader_;
|
||||||
|
depth_shader_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
Logger::Get().Log("shader_manager_class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
Logger::Get().Log("shader_manager_class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -477,3 +496,23 @@ bool shader_manager_class::render_skybox_shader(ID3D11DeviceContext* deviceConte
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool shader_manager_class::render_depth_shader(
|
||||||
|
ID3D11DeviceContext* context,
|
||||||
|
int indexCount,
|
||||||
|
XMMATRIX worldMatrix,
|
||||||
|
XMMATRIX viewMatrix,
|
||||||
|
XMMATRIX projectionMatrix,
|
||||||
|
ID3D11ShaderResourceView* texture
|
||||||
|
)
|
||||||
|
{
|
||||||
|
bool result;
|
||||||
|
|
||||||
|
result = depth_shader_->render(context, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
#include "application_class.h"
|
#include "application_class.h"
|
||||||
|
|
||||||
|
#include "depth_shader_class.h"
|
||||||
#include "system_class.h"
|
#include "system_class.h"
|
||||||
|
|
||||||
application_class::application_class() : should_quit_(false)
|
application_class::application_class() : should_quit_(false)
|
||||||
@ -1108,11 +1109,47 @@ bool application_class::render(float rotation, float x, float y, float z, float
|
|||||||
// -------------------------------------------------------- //
|
// -------------------------------------------------------- //
|
||||||
// ------------ render the object in the queue ------------ //
|
// ------------ render the object in the queue ------------ //
|
||||||
// -------------------------------------------------------- //
|
// -------------------------------------------------------- //
|
||||||
result = render_pass(render_queues_, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix);
|
|
||||||
if (!result)
|
if (active_camera_ == sun_camera_)
|
||||||
{
|
{
|
||||||
Logger::Get().Log("Could not render the model using any shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
for (auto& render : render_queues_)
|
||||||
return false;
|
{
|
||||||
|
|
||||||
|
bool isSkybox = (&render.get() == &skybox_);
|
||||||
|
if (isSkybox)
|
||||||
|
{
|
||||||
|
direct_3d_->turn_z_buffer_off();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& item : render.get())
|
||||||
|
{
|
||||||
|
|
||||||
|
item->Render(direct_3d_->get_device_context());
|
||||||
|
// render the item using depth shader
|
||||||
|
result = shader_manager_->render_depth_shader(
|
||||||
|
direct_3d_->get_device_context(),
|
||||||
|
item->GetIndexCount(),
|
||||||
|
worldMatrix,
|
||||||
|
viewMatrix,
|
||||||
|
projectionMatrix,
|
||||||
|
item->GetTexture(TextureType::Diffuse,0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSkybox)
|
||||||
|
{
|
||||||
|
direct_3d_->turn_z_buffer_on();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = render_pass(render_queues_, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
Logger::Get().Log("Could not render the model using any shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1970,7 +2007,7 @@ void application_class::construct_frustum()
|
|||||||
{
|
{
|
||||||
XMMATRIX projectionMatrix = direct_3d_->get_projection_matrix();
|
XMMATRIX projectionMatrix = direct_3d_->get_projection_matrix();
|
||||||
XMMATRIX viewMatrix;
|
XMMATRIX viewMatrix;
|
||||||
camera_->get_view_matrix(viewMatrix);
|
active_camera_->get_view_matrix(viewMatrix);
|
||||||
|
|
||||||
frustum_culling_.ConstructFrustum(screen_depth, projectionMatrix, viewMatrix);
|
frustum_culling_.ConstructFrustum(screen_depth, projectionMatrix, viewMatrix);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user