9 #ifndef COMMON_RENDERER_H
10 #define COMMON_RENDERER_H
16 #include "../shader/common.h"
21 extern std::vector<dune::tstring> files_scene;
50 DirectX::XMFLOAT2 pad0;
55 DirectX::XMFLOAT4 scene_dim_max;
56 DirectX::XMFLOAT4 scene_dim_min;
68 DirectX::XMFLOAT3 bb_min_;
69 DirectX::XMFLOAT3 bb_max_;
72 ID3D11ShaderResourceView* noise_srv_;
89 void update_scene(ID3D11DeviceContext* context,
const DirectX::XMMATRIX& world );
95 void render_scene(ID3D11DeviceContext* context,
float* clear_color, ID3D11DepthStencilView* dsv);
98 virtual void create(ID3D11Device* device);
99 virtual void destroy();
100 virtual void resize(UINT width, UINT height);
101 virtual void render(ID3D11DeviceContext* context, ID3D11RenderTargetView* backbuffer, ID3D11DepthStencilView* dsv);
107 virtual void update_frame(ID3D11DeviceContext* context,
double time,
float elapsed_time);
110 virtual void update_camera(ID3D11DeviceContext* context, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
113 virtual void reload_shader(ID3D11Device* device, ID3D11DeviceContext* context) {}
134 ID3DBlob* input_binary,
135 ID3D11VertexShader* vs_deferred,
136 ID3D11PixelShader* ps_deferred,
137 ID3D11PixelShader* ps_overlay,
140 UINT postprocessing_slot);
142 inline pppipe& postprocessor() {
return postprocessor_; }
160 template<
typename L = dune::directional_light>
175 XMStoreFloat4x4(&cb->vp,
176 DirectX::XMLoadFloat4x4(&l.
parameters().data().vp));
178 XMStoreFloat4x4(&cb->vp_inv,
179 XMLoadFloat4x4(&l.
parameters().data().vp_inv));
181 cb->camera_pos = DirectX::XMFLOAT3
197 ID3D11RenderTargetView* rsm_views[] = {
198 rsm[L
"colors"]->rtv(),
199 rsm[L
"normals"]->rtv(),
200 rsm[L
"lineardepth"]->rtv(),
204 ID3D11DepthStencilView* dsv = rsm_depth_.dsv();
206 context->ClearDepthStencilView(dsv, D3D11_CLEAR_DEPTH, 1.0, 0);
209 float cc[4] = { z_far, z_far, z_far, z_far };
212 DirectX::XMFLOAT2 size = rsm[L
"colors"]->size();
214 static_cast<size_t>(size.x),
215 static_cast<size_t>(size.y));
217 context->OMSetRenderTargets(4, rsm_views, dsv);
229 for (
size_t x = 0; x < scene_.
size(); ++x)
239 virtual void create(ID3D11Device* device)
241 common_renderer::create(device);
243 auto ld_color = def_[L
"colors"]->desc();
244 auto ld_normal = def_[L
"normals"]->desc();
245 auto ld_ldepth = def_[L
"lineardepth"]->desc();
246 auto ld_spec = def_[L
"specular"]->desc();
249 ld_color.Width = ld_normal.Width = ld_ldepth.Width = ld_spec.Width =
250 ld_color.Height = ld_normal.Height = ld_ldepth.Height = ld_spec.Height = 1024;
252 dummy_spec_.
create(device, ld_spec);
254 main_light_.create(device, L
"rsm", ld_color, ld_normal, ld_ldepth);
256 DXGI_SURFACE_DESC ld_rsmdepth;
257 ld_rsmdepth.Format = DXGI_FORMAT_R32_TYPELESS;
258 ld_rsmdepth.Width = 1024;
259 ld_rsmdepth.Height = 1024;
260 ld_rsmdepth.SampleDesc.Count = 1;
261 ld_rsmdepth.SampleDesc.Quality = 0;
262 rsm_depth_.
create(device, ld_rsmdepth);
265 add_buffer(*main_light_.rsm()[L
"lineardepth"], SLOT_TEX_SVO_RSM_RHO_START);
271 DirectX::XMMATRIX world = DirectX::XMLoadFloat4x4(&scene_.
world());
274 DirectX::XMVECTOR up = { -1.f, 0.f, 0.f, 0.f };
275 DirectX::XMVECTOR upt;
276 upt = DirectX::XMVector4Transform(up, world);
277 upt = DirectX::XMVector4Normalize(upt);
279 DirectX::XMFLOAT4 upt_vec;
280 DirectX::XMStoreFloat4(&upt_vec, upt);
283 auto light_proj = dune::make_projection(z_near, z_far);
285 l.
update(upt_vec, light_proj);
292 virtual void destroy()
294 common_renderer::destroy();
295 main_light_.destroy();
void set_alpha_slot(INT alpha_tex=-1)
Set the texture register for alpha textures.
Definition: assimp_mesh.h:212
cb_param & parameters()
Return local cbuffer parameters.
Definition: camera.h:47
void update_bbox(ID3D11DeviceContext *context, dune::d3d_mesh &mesh)
Upload the bounding box of a mesh to the pixel shader.
Definition: common_renderer.cpp:136
A common_renderer also rendering an RSM.
Definition: common_renderer.h:161
virtual void update_camera(ID3D11DeviceContext *context, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Update function called for the camera.
Definition: common_renderer.cpp:206
Seralizer to read/write Dune objects from/into JSON/XML.
Definition: serializer.h:41
virtual void resize(UINT width, UINT height)
Resize the deferred_renderer's output to a new width/height .
Definition: common_renderer.cpp:113
The deferred renderer base class.
Definition: deferred_renderer.h:40
virtual void load(ID3D11DeviceContext *context, const dune::serializer &s)
Load dune objects used in the common_renderer. Overload to add more.
Definition: common_renderer.cpp:281
void create(ID3D11Device *device, D3D11_TEXTURE2D_DESC desc, D3D11_SUBRESOURCE_DATA *subresource=nullptr)
Create an empty texture from given descriptor, other resource or single parameters.
Definition: texture.cpp:58
virtual void update_postprocessing_parameters(ID3D11DeviceContext *context)
Upload postprocessing paraemters from the postporcessing pipeline.
Definition: common_renderer.cpp:123
A mesh composed from other meshes.
Definition: composite_mesh.h:28
void update_rsm_camera_parameters(ID3D11DeviceContext *context, dune::directional_light &l)
Update and upload RSM camera parameters (i.e. light view projection matrix etc.). ...
Definition: common_renderer.h:171
A simple skydome mesh.
Definition: skydome.h:20
void set_shader(ID3D11Device *device, ID3DBlob *input_binary, ID3D11VertexShader *vs_deferred, ID3D11PixelShader *ps_deferred, ID3D11PixelShader *ps_overlay, UINT start_slot, UINT overlay_slot, UINT postprocessing_slot)
Set deferred rendering shaders.
Definition: common_renderer.cpp:82
void update(const DirectX::XMFLOAT4 &upt, const DirectX::XMMATRIX &light_proj)
Update the view-projection matrix in the parameter cbuffer for shadowmap/RSM rendering.
Definition: light.cpp:14
void to_ps(ID3D11DeviceContext *context, UINT start_slot)
Upload the shader resource to register slot of a pixel shader.
Definition: cbuffer.h:98
A simple directional light source with an RSM.
Definition: light.h:28
Default implementation of assimp_mesh (pun intended).
Definition: assimp_mesh.h:113
void reset_omrtv(ID3D11DeviceContext *context)
Resets all render target views to nullptr.
Definition: common_renderer.cpp:269
void render(ID3D11DeviceContext *context, DirectX::XMFLOAT4X4 *to_clip=nullptr)
Renders the mesh using the shaders previously set.
Definition: composite_mesh.cpp:80
virtual void save(dune::serializer &s)
Saves dune objects used in the common_renderer. Overload to add more.
Definition: common_renderer.h:305
void clear_rtvs(ID3D11DeviceContext *context, ID3D11RenderTargetView **rtvs, size_t num_rtvs, FLOAT *clear_color)
Clear a list of render targets with a color.
Definition: d3d_tools.cpp:154
void update_camera_parameters(ID3D11DeviceContext *context)
Upload camera parameters to the respective shaders.
Definition: common_renderer.cpp:128
void update_onetime_parameters(ID3D11DeviceContext *context, dune::d3d_mesh &mesh)
Upload one-time parameters (really just once) such as noise textures.
Definition: common_renderer.cpp:167
void set_viewport(ID3D11DeviceContext *context, size_t w, size_t h)
Resize the current viewport.
Definition: d3d_tools.cpp:112
const DirectX::XMFLOAT4X4 & world()
Returns the current world matrix of this mesh.
Definition: mesh.h:79
cb_param & parameters()
Return local cbuffer parameters.
Definition: light.h:60
size_t size()
Returns the number of submeshes.
Definition: composite_mesh.h:66
A simple perspective camera.
Definition: camera.h:26
virtual void destroy()
Destroy the shader_resource and free all memory.
Definition: render_target.cpp:98
void add_buffer(gbuffer &buffer, UINT slot)
Add a gbuffer to the deferred renderer buffer map.
Definition: deferred_renderer.cpp:370
void render_scene(ID3D11DeviceContext *context, float *clear_color, ID3D11DepthStencilView *dsv)
Clear the GBufer and render the scene.
Definition: common_renderer.cpp:225
virtual void do_render_scene(ID3D11DeviceContext *context)
Derived classes can overload this method to call render() on more dune objects. Buffers etc...
Definition: common_renderer.cpp:252
A common, simple deferred renderer.
Definition: common_renderer.h:43
virtual void set_shader_slots(INT diffuse_tex=-1, INT specular_tex=-1, INT normal_tex=-1)
Sets three register numbers to identify the slots the pixel shader is looking for surface textures...
Definition: composite_mesh.cpp:112
virtual void save(dune::serializer &s)
Saves dune objects used in the common_renderer. Overload to add more.
Definition: common_renderer.cpp:275
virtual void do_render_rsm(ID3D11DeviceContext *context)
Virtual function to render more stuff for the RSM.
Definition: common_renderer.h:225
A render target wrapper.
Definition: render_target.h:30
A default implementation of the postprocessor.
Definition: pppipe.h:27
void render_rsm(ID3D11DeviceContext *context, float *clear_color, dune::gbuffer &rsm)
Render a scene from a directional_light position into an RSM.
Definition: common_renderer.h:194
virtual void reload_shader(ID3D11Device *device, ID3D11DeviceContext *context)
A function called if the shaders should be reloaded.
Definition: common_renderer.h:113
A geometry buffer (collection of render_target objects).
Definition: gbuffer.h:30
virtual void update_frame(ID3D11DeviceContext *context, double time, float elapsed_time)
Update function for everything called once a frame.
Definition: common_renderer.cpp:187
void update_light_parameters(ID3D11DeviceContext *context, dune::directional_light &l)
Update and upload parameters (view projection matrix, flux etc.) of a directional light...
Definition: common_renderer.h:269
Main D3D mesh interface class.
Definition: mesh.h:129
void update_scene(ID3D11DeviceContext *context, const DirectX::XMMATRIX &world)
Update the scene with a new model matrix to move/scale/... stuff.
Definition: common_renderer.cpp:174
void to_vs(ID3D11DeviceContext *context, UINT start_slot)
Upload the shader resource to register slot of a vertex shader.
Definition: cbuffer.h:86
virtual void load(ID3D11DeviceContext *context, const dune::serializer &s)
Load dune objects used in the common_renderer. Overload to add more.
Definition: common_renderer.h:311