Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added display for albedo gbuffer

  • Loading branch information...
commit 9b2bb03c5e1f0326c50248a8a0c2875face67bef 1 parent ea1c5df
@kingofthebongo2008 authored
View
21 test/irradiance/gx/gx_execute_draw_calls_pipeline_node.cpp
@@ -45,12 +45,13 @@ namespace gx
{
case gx::command::gbuffer_initialize:
{
- render_context->select_back_buffer_target(device_context);
+ render_context->select_gbuffer(device_context);
break;
}
case gx::command::gbuffer_finalize:
{
+ render_context->end_gbuffer(device_context);
break;
}
@@ -106,19 +107,27 @@ namespace gx
}
//2. Render test quad
- //m_render_context->select_back_buffer_target(device_context);
- /*
+
+ m_render_context->select_back_buffer_target(device_context);
+
math::vector_float4 color = color::blue();
m_render_context->m_color_pixel_shader_cbuffer.update(device_context, color);
m_render_context->m_color_pixel_shader_cbuffer.bind_as_pixel_constant_buffer(device_context);
- device_context->PSSetShader(m_render_context->m_color_pixel_shader, nullptr, 0);
+
+ ID3D11ShaderResourceView* resources[1] = {
+ m_render_context->m_gbuffer_render_data.m_render_set.m_diffuse_view.get()
+ };
+
+ device_context->PSSetShaderResources(0, 1, resources );
+
+ device_context->PSSetShader(m_render_context->m_color_texture_pixel_shader, nullptr, 0);
math::matrix_float44 m1 = math::translation(-0.5f, -0.5f, 0.0f);
math::matrix_float44 m2 = math::scaling(0.5f, 0.5f, 1.0f);
math::matrix_float44 m3 = math::mul(m2, m1);
- //draw_screen_space_quad(device_context, m_render_context, m3);
- */
+ draw_screen_space_quad(device_context, m_render_context, m3);
+
delete in_params;
return nullptr;
View
99 test/irradiance/gx/gx_render_context.cpp
@@ -1,5 +1,7 @@
#include "precompiled.h"
+#include <array>
+
#include <gx/gx_render_context.h>
#include <gx/gx_thread_render_context.h>
@@ -15,6 +17,7 @@ namespace gx
, m_screen_space_render_data ( sys_context.m_device.get() )
, m_color_pixel_shader ( sys_context.m_device.get() )
, m_color_pixel_shader_cbuffer (sys_context.m_device.get())
+ , m_color_texture_pixel_shader ( sys_context.m_device.get() )
, m_phong_vertex_shader(sys_context.m_device.get())
, m_phong_vertex_shader_cbuffer(sys_context.m_device.get())
, m_lambert_vertex_shader(sys_context.m_device.get())
@@ -65,7 +68,7 @@ namespace gx
}
dx11::id3d11devicecontext_ptr device_context = m_render_contexts.front()->get_device_context();
- clear_buffers( device_context.get() );
+ clear_state( device_context.get() );
}
void render_context::end_frame()
@@ -158,6 +161,7 @@ namespace gx
dx11::throw_if_failed< dx11::create_texture_exception> ( m_system_context.m_device->CreateTexture2D( & texture_description, 0, dx11::get_pointer(m_gbuffer_render_data.m_render_set.m_diffuse)));
dx11::throw_if_failed< dx11::create_render_target_view_exception> ( m_system_context.m_device->CreateRenderTargetView( m_gbuffer_render_data.m_render_set.m_diffuse.get(), 0, dx11::get_pointer(m_gbuffer_render_data.m_render_set.m_diffuse_target)));
+ dx11::throw_if_failed< dx11::create_resource_view_exception>( m_system_context.m_device->CreateShaderResourceView( m_gbuffer_render_data.m_render_set.m_diffuse.get(), nullptr, dx11::get_pointer(m_gbuffer_render_data.m_render_set.m_diffuse_view)));
}
void render_context::create_specular_buffer()
@@ -181,7 +185,8 @@ namespace gx
texture_description.Width = desc.BufferDesc.Width;
dx11::throw_if_failed< dx11::create_texture_exception > ( m_system_context.m_device->CreateTexture2D( &texture_description, 0, dx11::get_pointer(m_gbuffer_render_data.m_render_set.m_specular)));
- dx11::throw_if_failed< dx11::create_render_target_view_exception > ( m_system_context.m_device->CreateRenderTargetView( m_gbuffer_render_data.m_render_set.m_diffuse.get(), 0, dx11::get_pointer(m_gbuffer_render_data.m_render_set.m_specular_target)));
+ dx11::throw_if_failed< dx11::create_render_target_view_exception > ( m_system_context.m_device->CreateRenderTargetView( m_gbuffer_render_data.m_render_set.m_specular.get(), 0, dx11::get_pointer(m_gbuffer_render_data.m_render_set.m_specular_target)));
+ dx11::throw_if_failed< dx11::create_resource_view_exception>( m_system_context.m_device->CreateShaderResourceView( m_gbuffer_render_data.m_render_set.m_specular.get(), nullptr, dx11::get_pointer(m_gbuffer_render_data.m_render_set.m_specular_view)));
}
void render_context::create_normal_depth_buffer()
@@ -205,12 +210,12 @@ namespace gx
texture_description.Width = desc.BufferDesc.Width;
dx11::throw_if_failed< dx11::create_texture_exception> ( m_system_context.m_device->CreateTexture2D( &texture_description, 0, dx11::get_pointer(m_gbuffer_render_data.m_render_set.m_normal_depth)));
- dx11::throw_if_failed< dx11::create_render_target_view_exception> ( m_system_context.m_device->CreateRenderTargetView( m_gbuffer_render_data.m_render_set.m_diffuse.get(), 0, dx11::get_pointer(m_gbuffer_render_data.m_render_set.m_normal_depth_target)));
+ dx11::throw_if_failed< dx11::create_render_target_view_exception> ( m_system_context.m_device->CreateRenderTargetView( m_gbuffer_render_data.m_render_set.m_normal_depth.get(), 0, dx11::get_pointer(m_gbuffer_render_data.m_render_set.m_normal_depth_target)));
+ dx11::throw_if_failed< dx11::create_resource_view_exception>( m_system_context.m_device->CreateShaderResourceView( m_gbuffer_render_data.m_render_set.m_normal_depth.get(), nullptr, dx11::get_pointer(m_gbuffer_render_data.m_render_set.m_normal_depth_view) ) );
}
void render_context::clear_buffers(ID3D11DeviceContext* device_context)
{
-
device_context->ClearDepthStencilView( m_depth_stencil_target.get(), D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0 );
float clear_color_1[4] = { 0.449019607f, 0.449019607f, 0.449019607f, 1.0f };
@@ -223,12 +228,22 @@ namespace gx
device_context->ClearRenderTargetView( m_gbuffer_render_data.m_render_set.m_specular_target.get(), clear_color_3);
}
+ void render_context::clear_state(ID3D11DeviceContext* device_context)
+ {
+ clear_buffers(device_context);
+ reset_shader_resources(device_context);
+ reset_render_targets(device_context);
+ }
+
void render_context::select_gbuffer(ID3D11DeviceContext* device_context)
{
+ reset_render_targets(device_context);
+ reset_shader_resources(device_context);
+
ID3D11RenderTargetView* views[3] =
{
- m_gbuffer_render_data.m_render_set.m_normal_depth_target.get(),
m_gbuffer_render_data.m_render_set.m_diffuse_target.get(),
+ m_gbuffer_render_data.m_render_set.m_normal_depth_target.get(),
m_gbuffer_render_data.m_render_set.m_specular_target.get()
};
@@ -238,21 +253,57 @@ namespace gx
device_context->RSSetState(m_gbuffer_render_data.m_state.m_rasterizer.get());
device_context->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
+ ID3D11SamplerState* samplers[] = {
+ m_gbuffer_render_data.m_state.m_sampler.get(),
+ m_gbuffer_render_data.m_state.m_sampler.get(),
+ m_gbuffer_render_data.m_state.m_sampler.get(),
+ m_gbuffer_render_data.m_state.m_sampler.get()
+ };
+
+ device_context->PSSetSamplers( 0, sizeof(samplers)/sizeof(samplers[0]), &samplers[0] );
+
select_view_port(device_context);
}
-
+
+ void render_context::end_gbuffer(ID3D11DeviceContext* device_context)
+ {
+ reset_render_targets(device_context);
+ reset_shader_resources(device_context);
+ }
+
void render_context::select_back_buffer_target(ID3D11DeviceContext* device_context)
{
+ reset_render_targets(device_context);
+ reset_shader_resources(device_context);
+
device_context->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
device_context->OMSetBlendState(m_default_render_data.m_state.m_blend_opaque.get(), nullptr, 0xFFFFFFFF);
device_context->OMSetDepthStencilState(m_default_render_data.m_state.m_depth.get(), 0 );
- device_context->OMSetRenderTargets( 1, dx11::get_pointer(m_default_render_data.m_render_set.m_back_buffer_render_target), m_default_render_data.m_render_set.m_depth_stencil_target.get() );
+
+ ID3D11RenderTargetView* views[1] =
+ {
+ m_default_render_data.m_render_set.m_back_buffer_render_target.get()
+ };
+
+ device_context->OMSetRenderTargets( 1, &views[0], m_default_render_data.m_render_set.m_depth_stencil_target.get() );
device_context->RSSetState(m_default_render_data.m_state.m_rasterizer.get());
+
+ ID3D11SamplerState* samplers[] = {
+ m_default_render_data.m_state.m_sampler.get(),
+ m_default_render_data.m_state.m_sampler.get(),
+ m_default_render_data.m_state.m_sampler.get(),
+ m_default_render_data.m_state.m_sampler.get()
+ };
+
+ device_context->PSSetSamplers( 0, sizeof(samplers)/sizeof(samplers[0]), &samplers[0] );
select_view_port(device_context);
}
void render_context::select_depth_pass(ID3D11DeviceContext* device_context)
{
+ reset_render_targets(device_context);
+ reset_shader_resources(device_context);
+
device_context->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
device_context->IASetInputLayout(m_depth_render_data.m_input_layout.get());
@@ -268,6 +319,40 @@ namespace gx
select_view_port(device_context);
}
+ void render_context::end_depth_pass(ID3D11DeviceContext* device_context)
+ {
+ reset_shader_resources(device_context);
+ reset_render_targets(device_context);
+ }
+
+ void render_context::reset_shader_resources(ID3D11DeviceContext* device_context)
+ {
+ std::array<ID3D11ShaderResourceView*,6> resources =
+ {
+ nullptr,
+ nullptr,
+ nullptr,
+
+ nullptr,
+ nullptr,
+ nullptr
+ };
+
+ device_context->PSSetShaderResources(0, static_cast<uint32_t> ( resources.size() ), &resources[0] );
+ }
+
+ void render_context::reset_render_targets(ID3D11DeviceContext* device_context)
+ {
+ std::array<ID3D11RenderTargetView*,3> views =
+ {
+ nullptr,
+ nullptr,
+ nullptr
+ };
+
+ device_context->OMSetRenderTargets( static_cast<uint32_t> (views.size() ) , &views[0], nullptr );
+ }
+
void render_context::select_view_port(ID3D11DeviceContext* device_context)
{
D3D11_VIEWPORT view_port;
View
18 test/irradiance/gx/gx_render_context.h
@@ -11,6 +11,7 @@
#include <dx11/dx11_system.h>
#include <gx/gx_color_pixel_shader.h>
+#include <gx/gx_color_texture_pixel_shader.h>
#include <gx/gx_depth_shader.h>
#include <gx/gx_lambert_constant_pixel_shader.h>
#include <gx/gx_lambert_vertex_shader.h>
@@ -37,6 +38,10 @@ namespace gx
m_normal_depth.reset();
m_diffuse.reset();
m_specular.reset();
+
+ m_normal_depth_view.reset();
+ m_diffuse_view.reset();
+ m_specular_view.reset();
}
dx11::id3d11rendertargetview_ptr m_normal_depth_target;
@@ -49,6 +54,10 @@ namespace gx
dx11::id3d11texture2d_ptr m_normal_depth;
dx11::id3d11texture2d_ptr m_diffuse;
dx11::id3d11texture2d_ptr m_specular;
+
+ dx11::id3d11shaderresourceview_ptr m_normal_depth_view;
+ dx11::id3d11shaderresourceview_ptr m_diffuse_view;
+ dx11::id3d11shaderresourceview_ptr m_specular_view;
};
struct depth_render_set
@@ -160,11 +169,15 @@ namespace gx
void create_swap_chain_buffers();
void release_swap_chain_buffers();
+ void clear_state( ID3D11DeviceContext* device_context );
void clear_buffers( ID3D11DeviceContext* device_context);
void select_depth_pass(ID3D11DeviceContext* device_context);
void select_gbuffer(ID3D11DeviceContext* device_context);
void select_back_buffer_target(ID3D11DeviceContext* device_context);
+ void end_depth_pass(ID3D11DeviceContext* device_context);
+ void end_gbuffer(ID3D11DeviceContext* device_context);
+
screen_space_quad_render create_screen_space_quad_render();
inline thread_render_context_container::iterator begin()
@@ -245,6 +258,9 @@ namespace gx
void select_view_port(ID3D11DeviceContext* device_context);
+ void reset_shader_resources(ID3D11DeviceContext* device_context);
+ void reset_render_targets(ID3D11DeviceContext* device_context);
+
dx11::system_context m_system_context;
thread_render_context_container m_render_contexts;
@@ -265,6 +281,8 @@ namespace gx
color_pixel_shader m_color_pixel_shader;
color_pixel_shader_constant_buffer m_color_pixel_shader_cbuffer;
+ color_texture_pixel_shader m_color_texture_pixel_shader;
+
phong_vertex_shader m_phong_vertex_shader;
phong_vertex_shader_constant_buffer m_phong_vertex_shader_cbuffer;
View
9 test/irradiance/irradiance.vcxproj
@@ -132,6 +132,13 @@
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)shaders\%(Filename)_compiled%(Extension)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)shaders\%(Filename)_compiled%(Extension)</Outputs>
</CustomBuild>
+ <CustomBuild Include="gx\gx_shader_color_texture_ps.hlsl">
+ <FileType>Document</FileType>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(WindowsSDKDir)\bin\x64\fxc.exe" "%(FullPath)" /Fh $(IntDir)shaders\%(Filename)_compiled%(Extension) /T ps_5_0 /Vn %(FileName)</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(WindowsSDKDir)\bin\x64\fxc.exe" "%(FullPath)" /Fh $(IntDir)shaders\%(Filename)_compiled%(Extension) /T ps_5_0 /Vn %(FileName) /Qstrip_reflect /Qstrip_debug /Qstrip_priv /Ges /O3</Command>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)shaders\%(Filename)_compiled%(Extension)</Outputs>
+ <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)shaders\%(Filename)_compiled%(Extension)</Outputs>
+ </CustomBuild>
<CustomBuild Include="gx\gx_shader_lambert_constant_ps.hlsl">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(WindowsSDKDir)\bin\x64\fxc.exe" "%(FullPath)" /Fh $(IntDir)shaders\%(Filename)_compiled%(Extension) /T ps_5_0 /Vn %(FileName)</Command>
@@ -188,6 +195,7 @@
<ClInclude Include="gx\gx_color.h" />
<ClInclude Include="gx\gx_color_material.h" />
<ClInclude Include="gx\gx_color_pixel_shader.h" />
+ <ClInclude Include="gx\gx_color_texture_pixel_shader.h" />
<ClInclude Include="gx\gx_constant_buffer_helper.h" />
<ClInclude Include="gx\gx_create_draw_calls_pipeline_node.h" />
<ClInclude Include="gx\gx_draw_calls_pipeline_params.h" />
@@ -263,6 +271,7 @@
<ClCompile Include="gxu\gxu_static_mesh_entity.cpp" />
<ClCompile Include="gx\gx_color_material.cpp" />
<ClCompile Include="gx\gx_color_pixel_shader.cpp" />
+ <ClCompile Include="gx\gx_color_texture_pixel_shader.cpp" />
<ClCompile Include="gx\gx_create_draw_calls_pipeline_node.cpp" />
<ClCompile Include="gx\gx_draw_call_collector.cpp" />
<ClCompile Include="gx\gx_draw_call_collector_context.cpp" />
Please sign in to comment.
Something went wrong with that request. Please try again.