Patch - Deth Shader integration for shadow map - V10.6.1
This commit is contained in:
parent
1af71960c3
commit
0e11ead55b
@ -5,8 +5,11 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/shadow_map.h" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/enginecustom/src/src/system/shadow_map.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$/enginecustom/src/hlsl/depth.ps" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/hlsl/depth.ps" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" 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/src/src/system/application_class.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/application_class.cpp" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@ -197,7 +200,7 @@
|
||||
<workItem from="1747830379222" duration="7954000" />
|
||||
<workItem from="1748254142068" duration="10499000" />
|
||||
<workItem from="1748267553700" duration="654000" />
|
||||
<workItem from="1748429087202" duration="2377000" />
|
||||
<workItem from="1748429087202" duration="7421000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Minor update - viewport window tweak">
|
||||
<option name="closed" value="true" />
|
||||
|
@ -69,6 +69,7 @@
|
||||
<ClCompile Include="src\src\system\physics.cpp" />
|
||||
<ClCompile Include="src\src\system\position_class.cpp" />
|
||||
<ClCompile Include="src\src\system\render_texture_class.cpp" />
|
||||
<ClCompile Include="src\src\system\shadow_map.cpp" />
|
||||
<ClCompile Include="src\src\system\Skybox.cpp" />
|
||||
<ClCompile Include="src\src\system\sprite_class.cpp" />
|
||||
<ClCompile Include="src\src\system\system_class.cpp" />
|
||||
@ -132,6 +133,7 @@
|
||||
<ClInclude Include="src\inc\system\position_class.h" />
|
||||
<ClInclude Include="src\inc\system\render_texture_class.h" />
|
||||
<ClInclude Include="src\inc\system\sceneManager.h" />
|
||||
<ClInclude Include="src\inc\system\shadow_map.h" />
|
||||
<ClInclude Include="src\inc\system\Skybox.h" />
|
||||
<ClInclude Include="src\inc\system\sprite_class.h" />
|
||||
<ClInclude Include="src\inc\system\system_class.h" />
|
||||
|
@ -43,6 +43,8 @@
|
||||
#include <DirectXMath.h>
|
||||
#include <mutex>
|
||||
|
||||
#include "shadow_map.h"
|
||||
|
||||
|
||||
/////////////
|
||||
// GLOBALS //
|
||||
@ -236,6 +238,9 @@ private :
|
||||
position_class* position_;
|
||||
int drawcalls_;
|
||||
|
||||
shadow_map* shadow_map_;
|
||||
ID3D11ShaderResourceView* shadow_map_srv_;
|
||||
|
||||
// ------------------------------------ //
|
||||
// ------------- OBJECTS -------------- //
|
||||
// ------------------------------------ //
|
||||
@ -258,7 +263,6 @@ private :
|
||||
std::vector<light_class*> lights_;
|
||||
int num_lights_;
|
||||
light_class* sun_light_;
|
||||
|
||||
XMFLOAT3 true_light_position_;
|
||||
model_class* light_model_;
|
||||
|
||||
@ -270,7 +274,6 @@ private :
|
||||
font_shader_class* font_shader_;
|
||||
bitmap_class* bitmap_;
|
||||
sprite_class* sprite_;
|
||||
|
||||
bool enable_cel_shading_;
|
||||
|
||||
// ----------------------------------- //
|
||||
|
23
enginecustom/src/inc/system/shadow_map.h
Normal file
23
enginecustom/src/inc/system/shadow_map.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include <d3d11.h>
|
||||
#include <directxmath.h>
|
||||
|
||||
class shadow_map {
|
||||
public:
|
||||
shadow_map();
|
||||
~shadow_map();
|
||||
|
||||
bool initialize(ID3D11Device* device, int width, int height);
|
||||
void shutdown();
|
||||
|
||||
void set_render_target(ID3D11DeviceContext* context);
|
||||
void clear_render_target(ID3D11DeviceContext* context, float depth = 1.0f);
|
||||
|
||||
ID3D11ShaderResourceView* get_shader_resource_view();
|
||||
|
||||
private:
|
||||
ID3D11Texture2D* depth_texture_;
|
||||
ID3D11DepthStencilView* depth_stencil_view_;
|
||||
ID3D11ShaderResourceView* shader_resource_view_;
|
||||
int width_, height_;
|
||||
};
|
@ -485,6 +485,13 @@ 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(), 2048, 2048))
|
||||
{
|
||||
Logger::Get().Log("Could not initialize the shadow map object", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
physics_ = new physics;
|
||||
|
||||
physics_thread_ = std::thread(&application_class::physics_thread_function, this);
|
||||
@ -741,6 +748,12 @@ void application_class::shutdown()
|
||||
Logger::Get().Log("Sun camera object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
||||
}
|
||||
|
||||
if (shadow_map_) {
|
||||
shadow_map_->shutdown();
|
||||
delete shadow_map_;
|
||||
shadow_map_ = nullptr;
|
||||
}
|
||||
|
||||
Logger::Get().Log("Application class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
||||
}
|
||||
|
||||
@ -839,11 +852,11 @@ bool application_class::frame(input_class* Input)
|
||||
camera_->set_rotation(rotationX, rotationY, 0.0f);
|
||||
} else {
|
||||
// Update the sun camera position and rotation based on the light position.
|
||||
// sun_camera_->set_position(sun_light_->GetPosition().x, sun_light_->GetPosition().y, sun_light_->GetPosition().z);
|
||||
// sun_camera_->set_rotation(pitch, yaw, roll);
|
||||
sun_camera_->set_position(sun_light_->GetPosition().x, sun_light_->GetPosition().y, sun_light_->GetPosition().z);
|
||||
sun_camera_->set_rotation(pitch, yaw, roll);
|
||||
|
||||
sun_camera_->set_position(positionX, positionY, positionZ);
|
||||
sun_camera_->set_rotation(rotationX, rotationY, 0.0f);
|
||||
// sun_camera_->set_position(positionX, positionY, positionZ);
|
||||
// sun_camera_->set_rotation(rotationX, rotationY, 0.0f);
|
||||
}
|
||||
|
||||
active_camera_->render();
|
||||
@ -1113,7 +1126,11 @@ bool application_class::render(float rotation, float x, float y, float z, float
|
||||
// ------------ render the object in the queue ------------ //
|
||||
// -------------------------------------------------------- //
|
||||
|
||||
|
||||
// set the active camera to the sun camera for rendering the shadow map.
|
||||
// active_camera_ = sun_camera_;
|
||||
// active_camera_->render();
|
||||
// // Render the objects in the render queues. with depth only pass.
|
||||
// active_camera_->get_view_matrix(viewMatrix);
|
||||
result = render_pass(render_queues_, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix);
|
||||
if (!result)
|
||||
{
|
||||
@ -1121,6 +1138,19 @@ bool application_class::render(float rotation, float x, float y, float z, float
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reset the active camera to the main camera.
|
||||
// active_camera_ = camera_;
|
||||
// active_camera_->render();
|
||||
// active_camera_->get_view_matrix(viewMatrix);
|
||||
//
|
||||
// // render the objects in the render queues. with standard pass.
|
||||
// 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;
|
||||
// }
|
||||
|
||||
|
||||
// Update the render count text.
|
||||
result = update_render_count_string(get_render_count());
|
||||
@ -1730,7 +1760,17 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
|
||||
|
||||
int renderCount = 0;
|
||||
|
||||
//construct_frustum();
|
||||
if (RenderQueues.empty())
|
||||
{
|
||||
Logger::Get().Log("RenderQueues is empty", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
// if (active_camera_ == sun_camera_)
|
||||
// {
|
||||
// shadow_map_->set_render_target(direct_3d_->get_device_context());
|
||||
// shadow_map_->clear_render_target(direct_3d_->get_device_context());
|
||||
// }
|
||||
|
||||
for (const auto& RenderQueue : RenderQueues)
|
||||
{
|
||||
@ -1942,6 +1982,7 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
|
||||
sun_light_->GetAmbientColor(),
|
||||
sun_light_->GetDirection(),
|
||||
sun_light_->GetIntensity()
|
||||
//shadow_map_srv_
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
@ -1977,7 +2018,12 @@ bool application_class::render_pass(const std::vector<std::reference_wrapper<std
|
||||
direct_3d_->turn_z_buffer_on();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if (active_camera_ == sun_camera_)
|
||||
// {
|
||||
// direct_3d_->set_back_buffer_render_target();
|
||||
// direct_3d_->reset_viewport();
|
||||
// }
|
||||
|
||||
set_render_count(renderCount);
|
||||
|
||||
|
62
enginecustom/src/src/system/shadow_map.cpp
Normal file
62
enginecustom/src/src/system/shadow_map.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
#include "shadow_map.h"
|
||||
|
||||
shadow_map::shadow_map()
|
||||
: depth_texture_(nullptr), depth_stencil_view_(nullptr), shader_resource_view_(nullptr), width_(0), height_(0) {}
|
||||
|
||||
shadow_map::~shadow_map() {
|
||||
shutdown();
|
||||
}
|
||||
|
||||
bool shadow_map::initialize(ID3D11Device* device, int width, int height) {
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
|
||||
D3D11_TEXTURE2D_DESC texDesc = {};
|
||||
texDesc.Width = width;
|
||||
texDesc.Height = height;
|
||||
texDesc.MipLevels = 1;
|
||||
texDesc.ArraySize = 1;
|
||||
texDesc.Format = DXGI_FORMAT_R24G8_TYPELESS;
|
||||
texDesc.SampleDesc.Count = 1;
|
||||
texDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
texDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
|
||||
|
||||
if (FAILED(device->CreateTexture2D(&texDesc, nullptr, &depth_texture_)))
|
||||
return false;
|
||||
|
||||
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc = {};
|
||||
dsvDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
||||
dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
|
||||
dsvDesc.Texture2D.MipSlice = 0;
|
||||
|
||||
if (FAILED(device->CreateDepthStencilView(depth_texture_, &dsvDesc, &depth_stencil_view_)))
|
||||
return false;
|
||||
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
|
||||
srvDesc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
|
||||
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
srvDesc.Texture2D.MipLevels = 1;
|
||||
|
||||
if (FAILED(device->CreateShaderResourceView(depth_texture_, &srvDesc, &shader_resource_view_)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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; }
|
||||
}
|
||||
|
||||
void shadow_map::set_render_target(ID3D11DeviceContext* context) {
|
||||
context->OMSetRenderTargets(0, nullptr, depth_stencil_view_);
|
||||
}
|
||||
|
||||
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() {
|
||||
return shader_resource_view_;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user