Minor - Start Shadow Map - V10.5.0
This commit is contained in:
37
enginecustom/src/inc/shader/depth_shader_class.h
Normal file
37
enginecustom/src/inc/shader/depth_shader_class.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#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_;
|
||||
};
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "celshade_class.h"
|
||||
#include "skybox_shader_class.h"
|
||||
#include "sunlight_shader_class.h"
|
||||
#include "depth_shader_class.h"
|
||||
|
||||
using namespace DirectX;
|
||||
|
||||
@@ -44,8 +45,10 @@ 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);
|
||||
bool render_sunlight_shader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float, ID3D11ShaderResourceView
|
||||
* shadowMap, XMMATRIX lightViewMatrix, XMMATRIX lightProjectionMatrix);
|
||||
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_;
|
||||
@@ -62,6 +65,7 @@ private:
|
||||
celshade_class* cel_shading_shader_;
|
||||
sunlight_shader_class* sunlight_shader_;
|
||||
skybox_shader_class* skybox_shader_;
|
||||
depth_shader_class* depth_shader_;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -38,6 +38,12 @@ 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&);
|
||||
@@ -45,14 +51,29 @@ public :
|
||||
|
||||
bool initialize(ID3D11Device*, HWND);
|
||||
void shutdown();
|
||||
bool render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3,float);
|
||||
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
|
||||
);
|
||||
|
||||
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);
|
||||
bool set_shader_parameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float, ID3D11ShaderResourceView
|
||||
* shadowMap, XMMATRIX lightViewMatrix, XMMATRIX lightProjectionMatrix);
|
||||
void render_shader(ID3D11DeviceContext*, int);
|
||||
|
||||
private:
|
||||
@@ -65,4 +86,7 @@ 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_;
|
||||
};
|
||||
@@ -43,6 +43,8 @@
|
||||
#include <DirectXMath.h>
|
||||
#include <mutex>
|
||||
|
||||
#include "shadow_map.h"
|
||||
|
||||
|
||||
/////////////
|
||||
// GLOBALS //
|
||||
@@ -185,8 +187,17 @@ 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 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
|
||||
);
|
||||
void update_skybox_position();
|
||||
|
||||
public :
|
||||
@@ -320,6 +331,18 @@ 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
|
||||
33
enginecustom/src/inc/system/shadow_map.h
Normal file
33
enginecustom/src/inc/system/shadow_map.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#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_;
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user