The Dirtchamber
A mixed reality testing environment for real-time global illumination algorithms
skydome.h
Go to the documentation of this file.
1 /*
2  * The Dirtchamber - Tobias Alexander Franke 2013
3  * For copyright and license see LICENSE
4  * http://www.tobias-franke.eu
5  */
6 
9 #include <dune/texture_cache.h>
10 #include <dune/assimp_mesh.h>
11 #include <dune/d3d_tools.h>
12 #include <dune/common_tools.h>
13 
20 class skydome : public dune::gilga_mesh
21 {
22 protected:
23  ID3D11ShaderResourceView* envmap_;
24  ID3D11ShaderResourceView* clouds_;
25 
26  ID3D11DepthStencilState* dss_disable_depth_test_;
27  ID3D11DepthStencilState* dss_enable_depth_test_;
28 
29  // TODO: stencil depth test goes here!
30 
31 public:
32  virtual void create(ID3D11Device* device, const dune::tstring& file)
33  {
35 
36  D3D11_DEPTH_STENCIL_DESC dsd;
37  dsd.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
38  dsd.DepthFunc = D3D11_COMPARISON_LESS;
39  dsd.StencilEnable = true;
40  dsd.StencilReadMask = 0xFF;
41  dsd.StencilWriteMask = 0xFF;
42  dsd.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
43  dsd.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
44  dsd.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
45  dsd.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
46  dsd.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
47  dsd.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
48  dsd.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
49  dsd.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
50 
51  dsd.DepthEnable = FALSE;
52  dune::assert_hr(device->CreateDepthStencilState(&dsd, &dss_disable_depth_test_));
53 
54  dsd.DepthEnable = TRUE;
55  dune::assert_hr(device->CreateDepthStencilState(&dsd, &dss_enable_depth_test_));
56  }
57 
58  virtual void destroy()
59  {
61 
62  dune::safe_release(dss_disable_depth_test_);
63  dune::safe_release(dss_enable_depth_test_);
64  }
65 
66  virtual void render(ID3D11DeviceContext* context)
67  {
68  context->OMSetDepthStencilState(dss_disable_depth_test_, 0);
69  dune::gilga_mesh::render(context, nullptr);
70  context->OMSetDepthStencilState(dss_enable_depth_test_, 0);
71  }
72 
74  void set_envmap(ID3D11Device* device, const dune::tstring& file)
75  {
76  dune::load_texture(device, file, &envmap_);
77 
78  for (auto i = meshes_.begin(); i != meshes_.end(); ++i)
79  i->diffuse_tex = envmap_;
80  }
81 
83  void set_clouds(ID3D11Device* device, const dune::tstring& file)
84  {
85  dune::load_texture(device, file, &clouds_);
86 
87  for (auto i = meshes_.begin(); i != meshes_.end(); ++i)
88  i->specular_tex = clouds_;
89  }
90 };
virtual void create(ID3D11Device *device, const tstring &file)
Create a mesh from a given filename.
Definition: assimp_mesh.cpp:343
virtual void render(ID3D11DeviceContext *context, DirectX::XMFLOAT4X4 *to_clip=nullptr)
Renders the mesh using the shaders previously set.
Definition: assimp_mesh.cpp:243
A simple skydome mesh.
Definition: skydome.h:20
void set_clouds(ID3D11Device *device, const dune::tstring &file)
Set an optional cloud map (latlong format) to use for the sky.
Definition: skydome.h:83
Default implementation of assimp_mesh (pun intended).
Definition: assimp_mesh.h:113
virtual void destroy()
Destroy a mesh and free all its resources.
Definition: assimp_mesh.cpp:498
virtual void create(ID3D11Device *device, const dune::tstring &file)
Create a mesh from a given filename.
Definition: skydome.h:32
void set_envmap(ID3D11Device *device, const dune::tstring &file)
Set the environment map (latlong format) to use for the sky.
Definition: skydome.h:74
#define assert_hr(x)
An assert for HRESULTs.
Definition: d3d_tools.h:148
virtual void destroy()
Destroy a mesh and free all its resources.
Definition: skydome.h:58
tstring make_absolute_path(const tstring &relative_filename)
Return an absolute URI to a URI relative to the execution directory. Thus function is used in every l...
Definition: common_tools.cpp:67
void safe_release(T &obj)
Safely release an object of type T, setting it to nullptr afterwards.
Definition: d3d_tools.h:61