The Dirtchamber
A mixed reality testing environment for real-time global illumination algorithms
sparse_voxel_octree.h
Go to the documentation of this file.
1 /*
2  * Dune D3D library - Tobias Alexander Franke 2013
3  * For copyright and license see LICENSE
4  * http://www.tobias-franke.eu
5  */
6 
9 #ifndef DUNE_SPARSE_VOXEL_OCTREE
10 #define DUNE_SPARSE_VOXEL_OCTREE
11 
12 #include <D3D11.h>
13 
14 #include "render_target.h"
15 #include "shader_resource.h"
16 #include "cbuffer.h"
17 #include "d3d_tools.h"
18 #include "composite_mesh.h"
19 #include "deferred_renderer.h"
20 #include "light.h"
21 
22 namespace dune
23 {
24  struct d3d_mesh;
25  class gilga_mesh;
26 
43  {
44  public:
45  struct param
46  {
47  float gi_scale;
48  float glossiness;
49  UINT num_vpls;
50  BOOL debug_gi;
51  };
52 
53  protected:
54  ID3D11BlendState* bs_voxelize_;
55  ID3D11SamplerState* ss_visualize_;
56 
57  ID3D11VertexShader* vs_voxelize_;
58  ID3D11GeometryShader* gs_voxelize_;
59  ID3D11PixelShader* ps_voxelize_;
60 
61  ID3D11VertexShader* vs_inject_;
62  ID3D11PixelShader* ps_inject_;
63 
64  INT inject_rsm_rho_start_slot_;
65 
66  ID3D11Texture3D* v_normal_;
67  ID3D11Texture3D* v_rho_;
68 
69  ID3D11ShaderResourceView* srv_v_normal_;
70  ID3D11ShaderResourceView* srv_v_rho_;
71 
72  ID3D11UnorderedAccessView* uav_v_normal_;
73  ID3D11UnorderedAccessView* uav_v_rho_;
74 
75  ID3D11RasterizerState* no_culling_;
76 
77  UINT volume_size_;
78 
79  DirectX::XMFLOAT4X4 world_to_svo_;
80  DirectX::XMFLOAT3 svo_min_, svo_max_;
81 
82  struct cbs_parameters
83  {
84  DirectX::XMFLOAT4X4 world_to_svo;
85  DirectX::XMFLOAT4 bb_min;
86  DirectX::XMFLOAT4 bb_max;
87  };
88 
89  cbuffer<cbs_parameters> cb_parameters_;
90 
91  dune::profile_query profiler_;
92 
94  cb_gi_parameters cb_gi_parameters_;
95 
96  UINT last_bound_;
97 
98  protected:
99  virtual void clear_ps(ID3D11DeviceContext* context);
100 
101  public:
102  float time_voxelize_;
103  float time_inject_;
104  float time_mip_;
105 
106  public:
108  virtual ~sparse_voxel_octree() {}
109 
111 
112  cb_gi_parameters& parameters() { return cb_gi_parameters_; }
113  const cb_gi_parameters& parameters() const { return cb_gi_parameters_; }
115 
116  virtual void create(ID3D11Device* device, UINT volume_size);
117  virtual void destroy();
118 
129  void set_shader_voxelize(ID3D11VertexShader* vs, ID3D11GeometryShader* gs, ID3D11PixelShader* ps);
130 
142  void set_shader_inject(ID3D11VertexShader* vs, ID3D11PixelShader* ps, UINT rsm_start_slot);
143 
145  void voxelize(ID3D11DeviceContext* context, gilga_mesh& mesh, bool clear = true);
146 
148  virtual void inject(ID3D11DeviceContext* context, directional_light& light);
149 
151  void filter(ID3D11DeviceContext* context);
152 
154 
155  void set_model_matrix(ID3D11DeviceContext* context, const DirectX::XMFLOAT4X4& model, const DirectX::XMFLOAT3& svo_min, const DirectX::XMFLOAT3& svo_max, UINT svo_parameters_slot);
156  const DirectX::XMFLOAT4X4& world_to_svo() const { return world_to_svo_; }
158 
159  virtual void to_ps(ID3D11DeviceContext* context, UINT volume_start_slot);
160  };
161 
179  {
180  protected:
181  ID3D11Texture3D* v_delta_;
182  ID3D11ShaderResourceView* srv_v_delta_;
183  ID3D11UnorderedAccessView* uav_v_delta_;
184 
185  INT inject_rsm_mu_start_slot_;
186 
187  protected:
188  virtual void clear_ps(ID3D11DeviceContext* context);
189 
190  public:
192  virtual ~delta_sparse_voxel_octree() {}
193 
194  virtual void create(ID3D11Device* device, UINT volume_size);
195  virtual void destroy();
196 
197  void set_shader_inject(ID3D11VertexShader* vs, ID3D11PixelShader* ps, UINT mu_start_slot, UINT rho_start_slot);
198 
199  virtual void inject(ID3D11DeviceContext* context, differential_directional_light& light);
200  virtual void to_ps(ID3D11DeviceContext* context, UINT volume_start_slot);
201  };
202 }
203 
204 #endif
void set_shader_voxelize(ID3D11VertexShader *vs, ID3D11GeometryShader *gs, ID3D11PixelShader *ps)
Set the complete voxelization shader.
Definition: sparse_voxel_octree.cpp:269
void voxelize(ID3D11DeviceContext *context, gilga_mesh &mesh, bool clear=true)
Voxelize a mesh into a volume with normals and an occupied marker. If clear is true, the volume is cleared before voxelization.
Definition: sparse_voxel_octree.cpp:284
const cb_gi_parameters & parameters() const
Return local cbuffer parameters.
Definition: sparse_voxel_octree.h:113
virtual void destroy()
Destroy the shader_resource and free all memory.
Definition: sparse_voxel_octree.cpp:165
A shader resource wrapper.
Definition: shader_resource.h:24
void set_shader_inject(ID3D11VertexShader *vs, ID3D11PixelShader *ps, UINT rsm_start_slot)
Set the complete injection shader.
Definition: sparse_voxel_octree.cpp:276
virtual void to_ps(ID3D11DeviceContext *context, UINT volume_start_slot)
Upload the shader resource to register slot of a pixel shader.
Definition: sparse_voxel_octree.cpp:258
void filter(ID3D11DeviceContext *context)
Pre-filter (i.e. mip-map) the SVO.
Definition: sparse_voxel_octree.cpp:242
virtual void inject(ID3D11DeviceContext *context, directional_light &light)
Inject a bounce from directional_light into the SVO.
Definition: sparse_voxel_octree.cpp:198
A simple directional light source with an RSM.
Definition: light.h:28
Default implementation of assimp_mesh (pun intended).
Definition: assimp_mesh.h:113
cb_gi_parameters & parameters()
Return local cbuffer parameters.
Definition: sparse_voxel_octree.h:112
virtual void destroy()
Destroy the shader_resource and free all memory.
Definition: sparse_voxel_octree.cpp:434
A differential directional light source.
Definition: light.h:82
virtual void to_ps(ID3D11DeviceContext *context, UINT volume_start_slot)
Upload the shader resource to register slot of a pixel shader.
Definition: sparse_voxel_octree.cpp:391
void set_model_matrix(ID3D11DeviceContext *context, const DirectX::XMFLOAT4X4 &model, const DirectX::XMFLOAT3 &svo_min, const DirectX::XMFLOAT3 &svo_max, UINT svo_parameters_slot)
Set/get the world -> SVO matrix, which transforms world coordinates to SVO volume coordinates...
Definition: sparse_voxel_octree.cpp:125
A GPU profiler.
Definition: d3d_tools.h:23
A Delta Radiance Field of an SVO necessary for Delta Voxel Cone Tracing (DVCT)
Definition: sparse_voxel_octree.h:178
Basic interface of a mesh.
Definition: mesh.h:102
A sparse voxel octree (SVO).
Definition: sparse_voxel_octree.h:42
const DirectX::XMFLOAT4X4 & world_to_svo() const
Set/get the world -> SVO matrix, which transforms world coordinates to SVO volume coordinates...
Definition: sparse_voxel_octree.h:156