├── UI
├── Font.dds
└── dxutcontrols.dds
├── doc
└── logo.png
├── data
├── marker.png
├── noise.dds
├── real_static_scene.png
├── skydome
│ └── sunny_day.jpg
├── tracked
│ ├── plane.mtl
│ ├── happy.mtl
│ └── plane.obj
├── box.obj
├── camera_parameters.xml
├── cornellbox
│ └── cornellbox.mtl
├── demo_gi_mr.xml
└── demo_gi.xml
├── cmake
├── cpack
│ ├── banner.png
│ ├── dialog.png
│ ├── license.txt
│ └── Package.cmake
├── FindWMF.cmake
├── FindKinectSDK.cmake
├── FindAssimp.cmake
├── FindDXUT.cmake
├── FindOpenCV.cmake
└── FindD3D.cmake
├── src
├── dune
│ ├── logger.h
│ ├── dune.h
│ ├── math_tools.h
│ ├── common_tools.h
│ ├── unicode.h
│ ├── exception.h
│ ├── camera.cpp
│ ├── record_tools.h
│ ├── camera.h
│ ├── serializer_tools.h
│ ├── shader_resource.cpp
│ ├── postprocess.cpp
│ ├── sdk_mesh.h
│ ├── serializer.cpp
│ ├── shader_resource.h
│ ├── composite_mesh.h
│ ├── texture.h
│ ├── texture_cache.h
│ ├── common_tools.cpp
│ ├── gbuffer.h
│ ├── render_target.h
│ ├── shader_tools.h
│ ├── summed_area_tables.h
│ ├── serializer.h
│ ├── video_gbuffer.h
│ ├── light.h
│ ├── composite_mesh.cpp
│ ├── postprocess.h
│ ├── math_tools.cpp
│ ├── simple_mesh.h
│ ├── cbuffer.h
│ ├── render_target.cpp
│ ├── mesh.cpp
│ ├── gbuffer.cpp
│ ├── light.cpp
│ ├── tracker.h
│ └── kinect_gbuffer.h
├── idc.h
├── common_dxut.h
├── skydome.h
├── ext
│ └── dds
│ │ └── PlatformHelpers.h
├── pppipe.h
├── common_dxut.cpp
└── main_gi.cpp
├── shader
├── pp_dof.hlsl
├── fs_triangle.hlsl
├── pp_film_grain.hlsl
├── overlay.hlsl
├── lpv_normalize.hlsl
├── tonemapping.hlsl
├── common.h
├── pp_fxaa.hlsl
├── pp_bloom.hlsl
├── pp_crt.hlsl
├── pp_ssao.hlsl
├── lpv_tools.hlsl
├── fuse_buffers.hlsl
├── deferred_vct.hlsl
├── postprocessing.hlsl
├── d3d_mesh_skydome.hlsl
├── deferred.hlsl
├── lpv_rendervol.hlsl
├── deferred_dlpv_kinect.hlsl
├── deferred_lpv.hlsl
├── pp_godrays.hlsl
├── pp_blur.hlsl
├── deferred_dvct_kinect.hlsl
└── brdf.hlsl
└── LICENSE
/UI/Font.dds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thefranke/dirtchamber/HEAD/UI/Font.dds
--------------------------------------------------------------------------------
/doc/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thefranke/dirtchamber/HEAD/doc/logo.png
--------------------------------------------------------------------------------
/data/marker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thefranke/dirtchamber/HEAD/data/marker.png
--------------------------------------------------------------------------------
/data/noise.dds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thefranke/dirtchamber/HEAD/data/noise.dds
--------------------------------------------------------------------------------
/UI/dxutcontrols.dds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thefranke/dirtchamber/HEAD/UI/dxutcontrols.dds
--------------------------------------------------------------------------------
/cmake/cpack/banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thefranke/dirtchamber/HEAD/cmake/cpack/banner.png
--------------------------------------------------------------------------------
/cmake/cpack/dialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thefranke/dirtchamber/HEAD/cmake/cpack/dialog.png
--------------------------------------------------------------------------------
/data/real_static_scene.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thefranke/dirtchamber/HEAD/data/real_static_scene.png
--------------------------------------------------------------------------------
/data/skydome/sunny_day.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thefranke/dirtchamber/HEAD/data/skydome/sunny_day.jpg
--------------------------------------------------------------------------------
/cmake/FindWMF.cmake:
--------------------------------------------------------------------------------
1 | # Find WMF
2 |
3 | set(WMF_LIBRARIES "mf.lib;mfplat.lib;mfuuid.lib;Mfreadwrite.lib;shlwapi.lib" CACHE STRING "")
4 |
--------------------------------------------------------------------------------
/data/tracked/plane.mtl:
--------------------------------------------------------------------------------
1 | newmtl plane
2 | Ns 92.156863
3 | Ka 0.800000 0.800000 0.800000
4 | Kd 0.8 0.8 0.8
5 | Ks 0 0 0
6 | Ni 1.000000
7 | d 1.000000
8 | illum 2
--------------------------------------------------------------------------------
/data/tracked/happy.mtl:
--------------------------------------------------------------------------------
1 | newmtl virtualobject
2 | Ns 92.156863
3 | Ka 0.000000 0.000000 0.000000
4 | #Kd 1.0 0.71 0.29
5 | Kd 1.0 0.2 0.1
6 | Ks 0.500000 0.500000 0.500000
7 | Ni 1.000000
8 | d 1.000000
9 | illum 2
10 |
--------------------------------------------------------------------------------
/data/tracked/plane.obj:
--------------------------------------------------------------------------------
1 | mtllib plane.mtl
2 |
3 | o Plane
4 | v -2.500000 0.000000 -2.500000
5 | v -2.500000 -0.000000 2.500000
6 | v 2.500000 -0.000000 2.500000
7 | v 2.500000 0.000000 -2.500000
8 |
9 | usemtl plane
10 | s off
11 | f 4 3 2 1
12 |
--------------------------------------------------------------------------------
/data/box.obj:
--------------------------------------------------------------------------------
1 | # Vertices: 8
2 | # Points: 0
3 | # Lines: 0
4 | # Faces: 6
5 | # Materials: 1
6 |
7 | o 1
8 |
9 | # Vertex list
10 |
11 | v -0.1 -0.1 0.1
12 | v -0.1 -0.1 -0.1
13 | v -0.1 0.1 -0.1
14 | v -0.1 0.1 0.1
15 | v 0.1 -0.1 0.1
16 | v 0.1 -0.1 -0.1
17 | v 0.1 0.1 -0.1
18 | v 0.1 0.1 0.1
19 |
20 | # Point/Line/Face list
21 |
22 | usemtl Default
23 | f 4 3 2 1
24 | f 2 6 5 1
25 | f 3 7 6 2
26 | f 8 7 3 4
27 | f 5 8 4 1
28 | f 6 7 8 5
29 |
30 | # End of file
31 |
--------------------------------------------------------------------------------
/data/camera_parameters.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1
5 | 5
6 | f
7 | -4.1802327176423804e-001 5.0715244063187526e-001 0. 0. -5.7843597214487474e-001
8 |
9 |
10 |
11 | 3
12 | 3
13 | f
14 |
15 | 6.5746697944293521e+002 0. 3.1950000000000000e+002
16 | 0. 6.5746697944293521e+002 2.3950000000000000e+002
17 | 0. 0. 1.
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/cmake/FindKinectSDK.cmake:
--------------------------------------------------------------------------------
1 | # Find the Microsoft Kinect SDK
2 |
3 | include(FindPackageHandleStandardArgs)
4 |
5 | if (CMAKE_CL_64)
6 | set(LIBPATH "amd64;lib/amd64")
7 | else()
8 | set(LIBPATH "x86;lib/x86")
9 | endif()
10 |
11 | find_library(KinectSDK_LIBRARY
12 | NAMES Kinect10
13 | PATHS $ENV{KINECTSDK10_DIR}/lib
14 | PATH_SUFFIXES ${LIBPATH})
15 |
16 | find_path(KinectSDK_INCLUDE_DIR
17 | NAMES NuiApi.h
18 | PATHS $ENV{KINECTSDK10_DIR}/inc
19 | PATH_SUFFIXES inc)
20 |
21 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(KinectSDK
22 | DEFAULT_MSG
23 | KinectSDK_LIBRARY
24 | KinectSDK_INCLUDE_DIR)
25 |
--------------------------------------------------------------------------------
/src/dune/logger.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2011
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #ifndef DUNE_LOGGER
10 | #define DUNE_LOGGER
11 |
12 | #include "unicode.h"
13 |
14 | namespace dune
15 | {
16 | namespace logger
17 | {
18 | /*! \brief Initialize the logging mechanism for dune. All cout/clog/cerr commands will reroute their output into a file identified by filename. */
19 | void init(const tstring& filename);
20 |
21 | /*! \brief Show all warnings up to the call of this function collected by the logger with a popup. */
22 | void show_warnings();
23 | };
24 | }
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/shader/pp_dof.hlsl:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2012
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | #include "postprocessing.hlsl"
8 |
9 | float blur_factor(in float depth)
10 | {
11 | return smoothstep(0, dof_focal_plane, abs(depth));
12 | }
13 |
14 | float4 ps_depth_of_field(in PS_INPUT inp) : SV_Target
15 | {
16 | float4 blurred = frontbuffer_blurred.Sample(StandardFilter, inp.tex_coord);
17 | float4 full = frontbuffer.Sample(StandardFilter, inp.tex_coord);
18 | float depth = rt_lineardepth.Sample(StandardFilter, inp.tex_coord).x;
19 |
20 | if (!dof_enabled)
21 | return full;
22 |
23 | // TODO: a should be 0 or 1, but gets interpolated in between somewhere
24 | if (full.a < 0.5)
25 | return full;
26 |
27 | return lerp(full, blurred, saturate(blur_factor(depth)));
28 | }
29 |
--------------------------------------------------------------------------------
/cmake/FindAssimp.cmake:
--------------------------------------------------------------------------------
1 | # Find the Open Asset Import Library
2 |
3 | include(FindPackageHandleStandardArgs)
4 |
5 | find_path(Assimp_INCLUDE_DIR
6 | NAMES assimp.h)
7 |
8 | find_file(Assimp_BINARY_RELEASE
9 | NAMES assimp.dll
10 | PATHS ${Assimp_INCLUDE_DIR}/../bin)
11 |
12 | find_library(Assimp_LIBRARY_RELEASE
13 | NAMES assimp
14 | PATHS ${Assimp_INCLUDE_DIR}/../lib)
15 |
16 | find_library(Assimp_LIBRARY_DEBUG
17 | NAMES assimpD
18 | PATHS ${Assimp_INCLUDE_DIR}/../lib)
19 |
20 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Assimp
21 | DEFAULT_MSG
22 | Assimp_INCLUDE_DIR
23 | Assimp_LIBRARY_RELEASE
24 | Assimp_LIBRARY_DEBUG)
25 |
26 | if(ASSIMP_FOUND)
27 | set(Assimp_LIBRARY optimized ${Assimp_LIBRARY_RELEASE} debug ${Assimp_LIBRARY_DEBUG} CACHE STRING "")
28 | mark_as_advanced(Assimp_LIBRARY_RELEASE Assimp_LIBRARY_DEBUG Assimp_BINARY_RELEASE)
29 | endif()
--------------------------------------------------------------------------------
/shader/fs_triangle.hlsl:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2011
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | struct PS_INPUT
8 | {
9 | float4 position : SV_POSITION;
10 | float2 tex_coord : TEXCOORD0;
11 | float3 view_ray : TEXCOORD1;
12 | };
13 |
14 | cbuffer camera_vs : register(b0)
15 | {
16 | float4x4 vp : packoffset(c0);
17 | float4x4 vp_inv : packoffset(c4);
18 | float3 camera_pos : packoffset(c8);
19 | float pad0 : packoffset(c8.w);
20 | }
21 |
22 | // Note: could do way easier with SV_VertexID, but stupid HLSL debugger won't have it
23 | PS_INPUT vs_fs_triangle(in float3 pos : POSITION)
24 | {
25 | PS_INPUT outp;
26 |
27 | float4 position = float4(pos, 1.f);
28 |
29 | outp.position = position;
30 | outp.tex_coord = position.xy * float2(0.5, -0.5) + 0.5;
31 | outp.view_ray = mul(vp_inv, position).xyz;
32 |
33 | return outp;
34 | }
35 |
--------------------------------------------------------------------------------
/shader/pp_film_grain.hlsl:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2014
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | #include "postprocessing.hlsl"
8 |
9 | float grain(in float2 tc, in float3 value)
10 | {
11 | const float intensity = 0.2;
12 |
13 | float l = luminance(value);
14 |
15 | // add noise
16 | float x = tc.x * tc.y * time * 1000.0;
17 | x = fmod(x, 13.0) * fmod(x, 123.0);
18 | float dx = fmod(x, 0.01);
19 |
20 | float y = clamp(0.1 + dx * 100.0, 0.0, 1.0) * intensity;
21 | float r = 0.5 * intensity - y;
22 |
23 | return 1.0 + r;
24 | }
25 |
26 | float4 ps_film_grain(in PS_INPUT inp) : SV_Target
27 | {
28 | float4 value = frontbuffer.Sample(StandardFilter, inp.tex_coord);
29 |
30 | if (!film_grain_enabled || value.a < 0.5)
31 | return value;
32 | else
33 | {
34 | float g = grain(inp.tex_coord, value.rgb);
35 | float3 ggg = float3(g, g, g);
36 | return float4(value.rgb * ggg, value.a);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/data/cornellbox/cornellbox.mtl:
--------------------------------------------------------------------------------
1 | # Blender MTL File: 'cornellbox.blend'
2 | # Material Count: 5
3 | newmtl bluewall
4 | Ns 96.078431
5 | Ka 0.000000 0.000000 0.000000
6 | Kd 0.383844 0.505843 0.687189
7 | Ks 0.000000 0.000000 0.000000
8 | Ni 1.000000
9 | d 1.000000
10 | illum 1
11 |
12 |
13 | newmtl whitewall
14 | Ns 96.078431
15 | Ka 0.000000 0.000000 0.000000
16 | Kd 0.800000 0.800000 0.800000
17 | Ks 0.000000 0.000000 0.000000
18 | Ni 1.000000
19 | d 1.000000
20 | illum 1
21 |
22 |
23 | newmtl redwall
24 | Ns 96.078431
25 | Ka 0.000000 0.000000 0.000000
26 | Kd 0.800000 0.265540 0.232816
27 | Ks 0.000000 0.000000 0.000000
28 | Ni 1.000000
29 | d 1.000000
30 | illum 1
31 |
32 |
33 | newmtl yellow_box
34 | Ns 96.078431
35 | Ka 0.000000 0.000000 0.000000
36 | Kd 0.800000 0.800000 0.000000
37 | Ks 0.000000 0.000000 0.000000
38 | Ni 1.000000
39 | d 1.000000
40 | illum 1
41 |
42 |
43 | newmtl whitelight
44 | Ns 96.078431
45 | Ka 0.000000 0.000000 0.000000
46 | Kd 0.800000 0.800000 0.800000
47 | Ks 0.000000 0.000000 0.000000
48 | Ni 1.000000
49 | d 1.000000
50 | illum 1
51 |
52 |
53 |
--------------------------------------------------------------------------------
/cmake/cpack/license.txt:
--------------------------------------------------------------------------------
1 | The Dirtchamber
2 |
3 | Copyright (c) 2014 Tobias Alexander Franke
4 | http://www.tobias-franke.eu
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7 |
8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 |
10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/src/dune/dune.h:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * The Dune D3D library - Tobias Alexander Franke 2011
4 | * For copyright and license see LICENSE
5 | * http://www.tobias-franke.eu
6 | *
7 | * "God created Arrakis to train the faithful."
8 | *
9 | */
10 |
11 | /*! \file */
12 |
13 | /// Direct3D helper library
14 | namespace dune {}
15 |
16 | #include "assimp_mesh.h"
17 | #include "exception.h"
18 | #include "camera.h"
19 | #include "cbuffer.h"
20 | #include "common_tools.h"
21 | #include "composite_mesh.h"
22 | #include "deferred_renderer.h"
23 | #include "d3d_tools.h"
24 | #include "gbuffer.h"
25 | #include "light.h"
26 | #include "light_propagation_volume.h"
27 | #include "logger.h"
28 | #include "math_tools.h"
29 | #include "mesh.h"
30 | #include "postprocess.h"
31 | #include "record_tools.h"
32 | #include "render_target.h"
33 | #include "sdk_mesh.h"
34 | #include "shader_resource.h"
35 | #include "shader_tools.h"
36 | #include "sparse_voxel_octree.h"
37 | #include "serializer.h"
38 | #include "serializer_tools.h"
39 | #include "texture.h"
40 | #include "texture_cache.h"
41 | #include "unicode.h"
42 |
43 | #include "kinect_gbuffer.h"
44 | #include "tracker.h"
45 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The Dirtchamber
2 |
3 | Copyright (c) 2014 Tobias Alexander Franke
4 | http://www.tobias-franke.eu
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
--------------------------------------------------------------------------------
/src/dune/math_tools.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2011
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #ifndef DUNE_MATH_TOOLS
10 | #define DUNE_MATH_TOOLS
11 |
12 | #include
13 |
14 | namespace dune
15 | {
16 | const float PI = 3.1415926f;
17 | const float DEG_TO_RAD = PI/180.f;
18 |
19 | /*! \brief Get a number of the Halton sequence. */
20 | float halton(int index, int base);
21 |
22 | /*! \brief Get a number-pair of the Hammersley sequence. */
23 | DirectX::XMFLOAT2 hammersley2d(unsigned int i, unsigned int N);
24 |
25 | DirectX::XMMATRIX make_projection(float z_near, float z_far);
26 |
27 | /*! \brief Approximate functions namespace. */
28 | namespace approx
29 | {
30 | inline double sin(double x);
31 | inline double exp(double x);
32 | }
33 |
34 | /*! \brief Helper functions to convert PBRT matrix operations. */
35 | namespace pbrt
36 | {
37 | DirectX::XMMATRIX translate(float x, float y, float z);
38 | DirectX::XMMATRIX rotate(float angle, float x, float y, float z);
39 | }
40 | }
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/src/dune/common_tools.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2011
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #ifndef DUNE_COMMON_TOOLS
10 | #define DUNE_COMMON_TOOLS
11 |
12 | #include "unicode.h"
13 | #include
14 |
15 | namespace dune
16 | {
17 | /*! \brief Extract a path from a given pattern, e.g. "C:/foo" from "C:/foo/\*.bar". */
18 | tstring extract_path(const tstring& pattern);
19 |
20 | /*! \brief Returns true if the supplied path p was a relative URI. */
21 | bool path_is_relative(const tstring& p);
22 |
23 | /*! \brief Returns an absolute path of the current execution directory. */
24 | tstring absolute_path();
25 |
26 | /*! \brief Return an absolute URI to a URI relative to the execution directory. Thus function is used in every loader. */
27 | tstring make_absolute_path(const tstring& relative_filename);
28 |
29 | /*! \brief Return a vector of strings from a given argument string. A default file will be pushed to the vector if args was empty. */
30 | std::vector files_from_args(const tstring& args, const tstring& default_file = L"");
31 | }
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/src/dune/unicode.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2011
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #ifndef DUNE_UNICODE
10 | #define DUNE_UNICODE
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | namespace dune
18 | {
19 | #ifdef UNICODE
20 |
21 | typedef std::wstring tstring;
22 | typedef std::wifstream tifstream;
23 | typedef std::wofstream tofstream;
24 | typedef std::wstringstream tstringstream;
25 | #define tcerr std::wcerr
26 | #define tclog std::wclog
27 | #define tcout std::wcout
28 |
29 | tstring to_tstring(const std::string& str);
30 | std::string to_string(const tstring& str);
31 |
32 | #else
33 |
34 | typedef std::string tstring;
35 | typedef std::ifstream tifstream;
36 | typedef std::ofstream tofstream;
37 | typedef std::stringstream tstringstream;
38 | #define tcerr std::cerr
39 | #define tclog std::clog
40 | #define tcout std::cout
41 |
42 | tstring to_tstring(const std::wstring& str);
43 | std::wstring to_string(const tstring& str);
44 |
45 | #endif
46 | }
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/src/dune/exception.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2011
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #ifndef DUNE_EXCEPTION
10 | #define DUNE_EXCEPTION
11 |
12 | #include
13 |
14 | #include "unicode.h"
15 |
16 | namespace dune
17 | {
18 | /*!
19 | * \brief Exception class.
20 | *
21 | * A wrapper class for std::exception which adds support
22 | * for multibyte character messages. Call msg() instead of what()
23 | * to get a tstring of the exception.
24 | */
25 | class exception : public std::exception
26 | {
27 | protected:
28 | tstring msg_;
29 |
30 | public:
31 | exception(tstring msg)
32 | {
33 | msg_ = msg;
34 | }
35 |
36 | virtual const char* what() const
37 | {
38 | return to_string(msg_).c_str();
39 | }
40 |
41 | /*! \brief Return exception message as tstring. */
42 | virtual const tstring& msg() const
43 | {
44 | return msg_;
45 | }
46 |
47 | virtual ~exception() throw()
48 | {
49 | }
50 | };
51 | }
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/src/dune/camera.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2014
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | #include "camera.h"
8 |
9 | namespace dune
10 | {
11 | void camera::create(ID3D11Device* device)
12 | {
13 | cb_param_.create(device);
14 | }
15 |
16 | void camera::destroy()
17 | {
18 | cb_param_.destroy();
19 | }
20 |
21 | void camera::update(float z_far)
22 | {
23 | DirectX::XMMATRIX view = GetViewMatrix();
24 | DirectX::XMMATRIX proj = GetProjMatrix();
25 |
26 | DirectX::XMStoreFloat4x4(¶meters().data().vp, view * proj);
27 |
28 | DirectX::XMFLOAT4X4 temp;
29 | DirectX::XMStoreFloat4x4(&temp, view);
30 |
31 | temp._41 = 0;
32 | temp._42 = 0;
33 | temp._43 = 0;
34 |
35 | DirectX::XMMATRIX no_translate = DirectX::XMLoadFloat4x4(&temp);
36 |
37 | DirectX::XMMATRIX vpp = no_translate * proj;
38 |
39 | DirectX::XMStoreFloat4x4(¶meters().data().vp_inv, DirectX::XMMatrixInverse(nullptr, vpp));
40 |
41 | DirectX::XMStoreFloat3(¶meters().data().camera_pos, GetEyePt());
42 | parameters().data().z_far = z_far;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/shader/overlay.hlsl:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2011
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | SamplerState ShadowFilter : register(s2);
8 |
9 | struct PS_OVERLAY_INPUT
10 | {
11 | float4 position : SV_POSITION;
12 | float2 tex_coord : TEXCOORD0;
13 | };
14 |
15 | Texture2D overlay_tex : register(t10);
16 |
17 | float2 calc_tex_coord(in float2 tex_coord)
18 | {
19 | float s = 0.3;
20 |
21 | if (tex_coord.x >= s ||
22 | tex_coord.x < 0.0 ||
23 | tex_coord.y >= s ||
24 | tex_coord.x < 0.0)
25 | discard;
26 |
27 | return tex_coord * (1.0/s);
28 | }
29 |
30 | float4 ps_overlay(in PS_OVERLAY_INPUT In) : SV_Target
31 | {
32 | float2 ntex = calc_tex_coord(In.tex_coord);
33 |
34 | float4 over = abs(overlay_tex.Sample(ShadowFilter, ntex));
35 |
36 | if (over.x > 1.0 || over.y > 1.0 || over.z > 1.0)
37 | over/=1000;
38 |
39 | return over;
40 | }
41 |
42 | float4 ps_overlay_depth(in PS_OVERLAY_INPUT In) : SV_TARGET
43 | {
44 | float2 ntex = calc_tex_coord(In.tex_coord);
45 |
46 | float d = 1.0 - overlay_tex.Sample(ShadowFilter, ntex).r;
47 |
48 | return float4(d,d,d,1);
49 | }
50 |
--------------------------------------------------------------------------------
/data/demo_gi_mr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 0
5 | 0
6 | 1
7 |
8 |
9 | 0
10 | 0
11 | 0
12 |
13 |
14 |
15 | false
16 | 21
17 |
18 | 4
19 |
20 |
21 |
22 |
23 | 0.50256
24 | -0.712761
25 | 0.489291
26 |
27 |
28 | 1.63
29 | 1.63
30 | 1.63
31 |
32 |
33 | -20.9553
34 | 86.8186
35 | 314.676
36 |
37 |
38 |
39 |
40 | true
41 | 0.8
42 | 1.5
43 |
44 |
45 | false
46 |
47 |
48 | 0.74
49 | true
50 | 844
51 |
52 |
53 | false
54 | 0.05
55 | 0.4
56 |
57 |
58 | true
59 |
60 |
61 | true
62 |
63 |
64 | false
65 | 0.0005
66 |
67 |
68 | true
69 | 0.33
70 |
71 |
72 |
--------------------------------------------------------------------------------
/cmake/FindDXUT.cmake:
--------------------------------------------------------------------------------
1 | # Find DXUT
2 |
3 | include(FindPackageHandleStandardArgs)
4 |
5 | if (CMAKE_CL_64)
6 | set(DXUTARCH "x64")
7 | else()
8 | set(DXUTARCH "Win32")
9 | endif()
10 |
11 | find_path(DXUT_SDK_PATH
12 | NAMES Core/DXUT.h)
13 |
14 | find_library(DXUT_LIBRARY_RELEASE
15 | NAMES DXUT
16 | PATHS ${DXUT_SDK_PATH}/Core/Bin/*/${DXUTARCH}/Release)
17 |
18 | find_library(DXUT_LIBRARY_DEBUG
19 | NAMES DXUT
20 | PATHS ${DXUT_SDK_PATH}/Core/Bin/*/${DXUTARCH}/Debug)
21 |
22 | find_library(DXUT_Opt_LIBRARY_RELEASE
23 | NAMES DXUTOpt
24 | PATHS ${DXUT_SDK_PATH}/Optional/Bin/*/${DXUTARCH}/Release)
25 |
26 | find_library(DXUT_Opt_LIBRARY_DEBUG
27 | NAMES DXUTOpt
28 | PATHS ${DXUT_SDK_PATH}/Optional/Bin/*/${DXUTARCH}/Debug)
29 |
30 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(DXUT
31 | DEFAULT_MSG
32 | DXUT_LIBRARY_RELEASE
33 | DXUT_Opt_LIBRARY_RELEASE
34 | DXUT_SDK_PATH)
35 |
36 | if(DXUT_FOUND)
37 | mark_as_advanced(DXUT_SDK_PATH DXUT_LIBRARY_RELEAE DXUT_LIBRARY_DEBUG DXUT_Opt_LIBRARY_RELEASE DXUT_Opt_LIBRARY_DEBUG)
38 | set(DXUT_INCLUDE_DIRS
39 | ${DXUT_SDK_PATH}/Core
40 | ${DXUT_SDK_PATH}/Optional
41 | CACHE STRING "")
42 |
43 | set(DXUT_LIBRARIES
44 | optimized ${DXUT_LIBRARY_RELEASE} optimized ${DXUT_Opt_LIBRARY_RELEASE}
45 | debug ${DXUT_LIBRARY_DEBUG} debug ${DXUT_Opt_LIBRARY_DEBUG}
46 | CACHE STRING "")
47 | endif()
--------------------------------------------------------------------------------
/shader/lpv_normalize.hlsl:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2012
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | struct PS_LPV_NORMALIZE
8 | {
9 | float4 coeff_r : SV_Target0;
10 | float4 coeff_g : SV_Target1;
11 | float4 coeff_b : SV_Target2;
12 | };
13 |
14 | struct GS_LPV_PROPAGATE
15 | {
16 | float4 pos : SV_Position;
17 | float3 tex : TEXCOORD;
18 | uint rtindex : SV_RenderTargetArrayIndex;
19 | };
20 |
21 | Texture2DArray lpv_sh_r : register(t7);
22 | Texture2DArray lpv_sh_g : register(t8);
23 | Texture2DArray lpv_sh_b : register(t9);
24 | Texture2DArray lpv_inject_counter : register(t10);
25 |
26 | PS_LPV_NORMALIZE ps_lpv_normalize(in GS_LPV_PROPAGATE input)
27 | {
28 | PS_LPV_NORMALIZE output;
29 |
30 | int4 lpv_pos = int4(input.pos.x, input.pos.y, input.tex.z, 0);
31 |
32 | float num_lights = abs(lpv_inject_counter.Load(lpv_pos).r);
33 |
34 | float scale = 1.0;
35 |
36 | if (num_lights > 0)
37 | scale = 1.0/num_lights;
38 |
39 | float4 r = lpv_sh_r.Load(lpv_pos);
40 | float4 g = lpv_sh_g.Load(lpv_pos);
41 | float4 b = lpv_sh_b.Load(lpv_pos);
42 |
43 | output.coeff_r = r * scale;
44 | output.coeff_g = g * scale;
45 | output.coeff_b = b * scale;
46 |
47 | return output;
48 | }
49 |
--------------------------------------------------------------------------------
/src/idc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2013
3 | * For copyright and license see copying.txt
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #pragma once
10 |
11 | /*! \brief IDs for DXUT GUI elements. */
12 | enum
13 | {
14 | IDC_TARGETS,
15 | IDC_TOGGLE_FULLSCREEN,
16 | IDC_SETTINGS,
17 | IDC_FPS_COUNTER,
18 |
19 | IDC_FLUX_SCALE,
20 |
21 | IDC_LIGHT_DIRECTION,
22 | IDC_LIGHT_POS_X,
23 | IDC_LIGHT_POS_Y,
24 | IDC_LIGHT_POS_Z,
25 | IDC_LIGHT_WARMTH,
26 |
27 | IDC_NUM_VPLS,
28 | IDC_NUM_VPLS_INFO,
29 | IDC_GI_SCALE,
30 | IDC_GI_DEBUG1,
31 | IDC_GI_DEBUG2,
32 | IDC_GI_PARAMETER1,
33 | IDC_GI_PARAMETER2,
34 | IDC_GI_PARAMETER3,
35 | IDC_GI_INFO1,
36 | IDC_GI_INFO2,
37 | IDC_GI_INFO3,
38 |
39 | IDC_SSAO_ENABLED,
40 | IDC_SSAO_SCALE,
41 |
42 | IDC_FXAA_ENABLED,
43 |
44 | IDC_BLOOM_ENABLED,
45 | IDC_BLOOM_SIGMA,
46 | IDC_BLOOM_TRESHOLD,
47 |
48 | IDC_GODRAYS_ENABLED,
49 | IDC_GODRAYS_TAU,
50 |
51 | IDC_DOF_ENABLED,
52 | IDC_DOF_FOCAL_PLANE,
53 | IDC_DOF_COC_SCALE,
54 |
55 | IDC_EXPOSURE_ADAPT,
56 | IDC_EXPOSURE_KEY,
57 | IDC_EXPOSURE_SPEED,
58 |
59 | IDC_TRACK_TRANSX,
60 | IDC_TRACK_TRANSY,
61 | IDC_TRACK_TRANSZ,
62 | IDC_TRACK_SCALE,
63 | IDC_TRACK_ANIMATE,
64 |
65 | IDC_ZFAR,
66 | IDC_ZNEAR,
67 |
68 | IDC_CRT_ENABLED,
69 | IDC_FILM_GRAIN_ENABLED,
70 |
71 | // HAS TO BE LAST!
72 | IDC_DEBUG_INFO,
73 | };
74 |
--------------------------------------------------------------------------------
/src/dune/record_tools.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2017
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #ifndef DUNE_RECORD_TOOLS
10 | #define DUNE_RECORD_TOOLS
11 |
12 | #include "unicode.h"
13 |
14 | #include
15 |
16 | namespace dune
17 | {
18 | class gbuffer;
19 | }
20 |
21 | namespace dune
22 | {
23 | class video_recorder
24 | {
25 | protected:
26 | UINT width_,
27 | height_,
28 | fps_;
29 | ID3D11Texture2D* ffmpeg_texture_;
30 | FILE* ffmpeg_;
31 | tstring path_;
32 |
33 | public:
34 | video_recorder();
35 | virtual ~video_recorder();
36 |
37 | void create(ID3D11Device* device, UINT width, UINT height, UINT fps, const tstring& path = L"../../data");
38 | void destroy();
39 |
40 | void start_recording();
41 | void stop_recording();
42 | void add_frame(ID3D11DeviceContext* context, ID3D11RenderTargetView* rtv);
43 | void add_frame(ID3D11DeviceContext* context, ID3D11Resource* resource);
44 | };
45 |
46 | void dump_rtv(ID3D11Device* device, ID3D11DeviceContext* context, UINT width, UINT height, DXGI_FORMAT format, ID3D11RenderTargetView* rtv, const tstring& name);
47 | void dump_gbuffer(ID3D11Device* device, ID3D11DeviceContext* context, gbuffer& g, const tstring& name);
48 | }
49 |
50 | #endif
51 |
--------------------------------------------------------------------------------
/src/dune/camera.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2014
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #ifndef DUNE_CAMERA
10 | #define DUNE_CAMERA
11 |
12 | #undef NOMINMAX
13 | #include
14 | #include
15 |
16 | #include "cbuffer.h"
17 |
18 | namespace dune
19 | {
20 | /*!
21 | * \brief A simple perspective camera.
22 | *
23 | * This class derives from CFirstPersonCamera in DXUT and simply handles
24 | * a constant buffer for the camera parameters.
25 | */
26 | class camera : public CFirstPersonCamera
27 | {
28 | public:
29 | struct param
30 | {
31 | DirectX::XMFLOAT4X4 vp;
32 | DirectX::XMFLOAT4X4 vp_inv;
33 | DirectX::XMFLOAT3 camera_pos;
34 | FLOAT z_far;
35 | };
36 |
37 | protected:
38 | typedef cbuffer cb_param;
39 | cb_param cb_param_;
40 |
41 | public:
42 | void create(ID3D11Device* device);
43 | void destroy();
44 |
45 | //!@{
46 | /*! \brief Return local cbuffer parameters. */
47 | cb_param& parameters() { return cb_param_; }
48 | const cb_param& parameters() const { return cb_param_; }
49 | //!@}
50 |
51 | /*! \brief Update the constant buffer from the current values of the camera and a supplied Z-far. */
52 | void update(float z_far);
53 | };
54 | }
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/src/dune/serializer_tools.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2014
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #ifndef DUNE_SERIALIZER_TOOLS
10 | #define DUNE_SERIALIZER_TOOLS
11 |
12 | #include "serializer.h"
13 |
14 | namespace dune
15 | {
16 | class camera;
17 | class directional_light;
18 | class light_propagation_volume;
19 | class sparse_voxel_octree;
20 | }
21 |
22 | namespace dune
23 | {
24 | //!@{
25 | /*! \brief Read/write camera parameters from/to a serializer. */
26 | serializer& operator<<(serializer& s, const camera& c);
27 | const serializer& operator>>(const serializer& s, camera& c);
28 | //!@}
29 |
30 | //!@{
31 | /*! \brief Read/write directional_light parameters from/to a serializer. */
32 | serializer& operator<<(serializer& s, const directional_light& l);
33 | const serializer& operator>>(const serializer& s, directional_light& l);
34 | //!@}
35 |
36 | //!@{
37 | /*! \brief Read/write light_propagation_volume parameters from/to a serializer. */
38 | serializer& operator<<(serializer& s, const light_propagation_volume& lpv);
39 | const serializer& operator>>(const serializer& s, light_propagation_volume& lpv);
40 | //!@}
41 |
42 | //!@{
43 | /*! \brief Read/write sparse_voxel_octree parameters from/to a serializer. */
44 | serializer& operator<<(serializer& s, const sparse_voxel_octree& svo);
45 | const serializer& operator>>(const serializer& s, sparse_voxel_octree& svo);
46 | //!@}
47 | }
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/shader/tonemapping.hlsl:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2012
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | #ifndef TONEMAPPING_HLSL
8 | #define TONEMAPPING_HLSL
9 |
10 | #define TONEMAP_GAMMA 1.0
11 |
12 | // Reinhard Tonemapper
13 | float4 tonemap_reinhard(in float3 color)
14 | {
15 | color *= 16;
16 | color = color/(1+color);
17 | float3 ret = pow(color, TONEMAP_GAMMA); // gamma
18 | return float4(ret,1);
19 | }
20 |
21 | // Uncharted 2 Tonemapper
22 | float3 tonemap_uncharted2(in float3 x)
23 | {
24 | float A = 0.15;
25 | float B = 0.50;
26 | float C = 0.10;
27 | float D = 0.20;
28 | float E = 0.02;
29 | float F = 0.30;
30 |
31 | return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;
32 | }
33 |
34 | float3 tonemap_uc2(in float3 color)
35 | {
36 | float W = 11.2;
37 |
38 | color *= 16; // Hardcoded Exposure Adjustment
39 |
40 | float exposure_bias = 2.0f;
41 | float3 curr = tonemap_uncharted2(exposure_bias*color);
42 |
43 | float3 white_scale = 1.0f/tonemap_uncharted2(W);
44 | float3 ccolor = curr*white_scale;
45 |
46 | float3 ret = pow(abs(ccolor), TONEMAP_GAMMA); // gamma
47 |
48 | return ret;
49 | }
50 |
51 | // Filmic tonemapper
52 | float3 tonemap_filmic(in float3 color)
53 | {
54 | color = max(0, color - 0.004f);
55 | color = (color * (6.2f * color + 0.5f)) / (color * (6.2f * color + 1.7f)+ 0.06f);
56 |
57 | // result has 1/2.2 baked in
58 | return pow(color, TONEMAP_GAMMA);
59 | }
60 |
61 | #endif
62 |
--------------------------------------------------------------------------------
/data/demo_gi.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -0.0624965
5 | 9.99092
6 | -34.3683
7 |
8 |
9 | -0.0624965
10 | 9.99092
11 | -35.3683
12 |
13 |
14 |
15 | false
16 |
17 | 4
18 |
19 |
20 | 3.824
21 | 32
22 |
23 | 21
24 |
25 |
26 |
27 | 0
28 | -1
29 | 0
30 |
31 |
32 | 1
33 | 1
34 | 1
35 |
36 |
37 | 9.53674e-007
38 | 20.0297
39 | -9.53674e-007
40 |
41 |
42 |
43 |
44 | true
45 | 0.5
46 | 0.5
47 |
48 |
49 | false
50 |
51 |
52 | 0.8
53 | false
54 | 2000
55 |
56 |
57 | false
58 | 0.05
59 | 0.4
60 |
61 |
62 | true
63 |
64 |
65 | true
66 |
67 |
68 | false
69 | 0.0005
70 |
71 |
72 | true
73 | 0.1
74 |
75 |
76 |
--------------------------------------------------------------------------------
/src/dune/shader_resource.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2012
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | #include "shader_resource.h"
8 |
9 | #include "unicode.h"
10 | #include "d3d_tools.h"
11 |
12 | namespace dune
13 | {
14 | void shader_resource::to_vs(ID3D11DeviceContext* context, UINT slot)
15 | {
16 | tcerr << name.c_str() << L" has no to_vs implementation" << std::endl;
17 | }
18 |
19 | void shader_resource::to_gs(ID3D11DeviceContext* context, UINT slot)
20 | {
21 | tcerr << name.c_str() << L" has no to_gs implementation" << std::endl;
22 | }
23 |
24 | void shader_resource::to_ps(ID3D11DeviceContext* context, UINT slot)
25 | {
26 | tcerr << name.c_str() << L" has no to_ps implementation" << std::endl;
27 | }
28 |
29 | void shader_resource::to_cs(ID3D11DeviceContext* context, UINT slot)
30 | {
31 | tcerr << name.c_str() << L" has no to_cs implementation" << std::endl;
32 | }
33 |
34 | void sampler_state::create(ID3D11Device* device, const D3D11_SAMPLER_DESC& desc)
35 | {
36 | assert_hr(device->CreateSamplerState(&desc, &state));
37 | }
38 |
39 | void sampler_state::destroy()
40 | {
41 | safe_release(state);
42 | }
43 |
44 | void sampler_state::to_vs(ID3D11DeviceContext* context, UINT slot)
45 | {
46 | context->VSSetSamplers(slot, 1, &state);
47 | }
48 |
49 | void sampler_state::to_ps(ID3D11DeviceContext* context, UINT slot)
50 | {
51 | context->PSSetSamplers(slot, 1, &state);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/cmake/cpack/Package.cmake:
--------------------------------------------------------------------------------
1 | set(DIRTCHAMBER_BINARY_DIR "bin/release")
2 |
3 | # install redist package
4 | set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ${DIRTCHAMBER_BINARY_DIR})
5 | include(InstallRequiredSystemLibraries)
6 |
7 | # common config
8 | set(CPACK_PACKAGE_NAME "Dirtchamber")
9 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Dirtchamber")
10 | set(CPACK_PACKAGE_VENDOR "Tobias Alexander Franke")
11 | set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/Readme.md")
12 | set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/Readme.md")
13 | set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/Readme.md")
14 | set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/cmake/cpack/license.txt")
15 | set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/doc/logo.png")
16 | set(CPACK_PACKAGE_VERSION_MAJOR "1")
17 | set(CPACK_PACKAGE_VERSION_MINOR "0")
18 | set(CPACK_PACKAGE_VERSION_PATCH "0")
19 | set(CPACK_PACKAGE_INSTALL_DIRECTORY "Dirtchamber")
20 |
21 | set(CPACK_PACKAGE_EXECUTABLES vct "Voxel Cone Tracer"
22 | lpv "Light Propagation Volume Renderer")
23 |
24 | if(OPENCV_FOUND)
25 | set(CPACK_PACKAGE_EXECUTABLES ${CPACK_PACKAGE_EXECUTABLES}
26 | delta_vct "DVCT Viewer"
27 | delta_lpv "DLPV Viewer")
28 | endif()
29 |
30 | # WiX
31 | set(CPACK_WIX_UPGRADE_GUID "00B776BF-6115-489E-85CD-49AF8559A7F8")
32 | set(CPACK_WIX_UI_BANNER "${CMAKE_SOURCE_DIR}/cmake/cpack/banner.png")
33 | set(CPACK_WIX_UI_DIALOG "${CMAKE_SOURCE_DIR}/cmake/cpack/dialog.png")
34 | set(CPACK_WIX_PROPERTY_ARPURLINFOABOUT "http://www.tobias-franke.eu/projects/dirtchamber")
35 | set(CPACK_WIX_PROPERTY_ARPHELPLINK "http://tobias-franke.eu/projects/dirtchamber/doc")
36 |
37 | include(CPack)
--------------------------------------------------------------------------------
/cmake/FindOpenCV.cmake:
--------------------------------------------------------------------------------
1 | # Find OpenCV
2 |
3 | include(FindPackageHandleStandardArgs)
4 |
5 | find_path(OpenCV_DIR
6 | include/opencv2/opencv.hpp)
7 |
8 | if(OpenCV_DIR)
9 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH};${OpenCV_DIR})
10 | include(OpenCVConfig-version)
11 | include(OpenCVConfig)
12 |
13 | mark_as_advanced(OpenCV_FOUND)
14 |
15 | find_path(OpenCV_INCLUDE_DIR
16 | NAMES opencv2/opencv.hpp
17 | PATHS ${OpenCV_DIR}/include)
18 |
19 | set(FVER "${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}")
20 |
21 | foreach(lib ${OpenCV_LIB_COMPONENTS})
22 | string(SUBSTRING ${lib} 7 -1 slib)
23 |
24 | find_library(OpenCV_${slib}_LIBRARY_RELEASE
25 | NAMES opencv_${slib}${FVER}
26 | PATHS ${OpenCV_LIB_DIR})
27 |
28 | mark_as_advanced(OpenCV_${slib}_LIBRARY_RELEASE)
29 |
30 | find_library(OpenCV_${slib}_LIBRARY_DEBUG
31 | NAMES opencv_${slib}${FVER}d
32 | PATHS ${OpenCV_LIB_DIR})
33 |
34 | mark_as_advanced(OpenCV_${slib}_LIBRARY_DEBUG)
35 |
36 | set(OpenCV_${slib}_LIBRARY
37 | optimized ${OpenCV_${slib}_LIBRARY_RELEASE}
38 | #debug ${OpenCV_${slib}_LIBRARY_DEBUG} # don't add debug
39 | CACHE FILE "OpenCV ${slib} component")
40 |
41 | mark_as_advanced(OpenCV_${slib}_LIBRARY)
42 |
43 | set(OpenCV_LIBRARIES
44 | ${OpenCV_LIBRARIES};${OpenCV_${slib}_LIBRARY}
45 | CACHE STRING "All OpenCV libraries")
46 | endforeach(lib)
47 |
48 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenCV
49 | DEFAULT_MSG
50 | OpenCV_INCLUDE_DIR
51 | OpenCV_LIBRARIES)
52 | endif()
--------------------------------------------------------------------------------
/src/common_dxut.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2013
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #ifndef COMMON_DXUT
10 | #define COMMON_DXUT
11 |
12 | #include "common_renderer.h"
13 |
14 | #include
15 |
16 | extern dc::common_renderer* the_renderer;
17 | extern ID3D11Device* the_device;
18 | extern ID3D11DeviceContext* the_context;
19 |
20 | namespace dc
21 | {
22 | //!@{
23 | /*!
24 | * \brief Default implementation of DXUT callbacks common to all render samples.
25 | *
26 | * All render samples share common DXUT function callbacks which use identical code. They all refer to a
27 | * common_renderer pointer the_renderer which represents the main implementation and which must be set when initializing
28 | * the sample
29 | */
30 | void CALLBACK on_releasing_swap_chain(void* pUserContext);
31 | bool CALLBACK on_modify_device(DXUTDeviceSettings* settings, void* user_context);
32 | HRESULT CALLBACK on_resize(ID3D11Device* pd3dDevice, IDXGISwapChain *pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext);
33 | void CALLBACK on_frame_move(double fTime, float fElapsedTime, void* pUserContext);
34 | LRESULT CALLBACK on_msg(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool *pbNoFurtherProcessing, void *pUserContext);
35 | void CALLBACK on_destroy_device(void* pUserContext);
36 | void CALLBACK on_keyboard(UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext);
37 | void CALLBACK on_render(ID3D11Device* device, ID3D11DeviceContext* context, double fTime, float fElapsedTime, void* pUserContext);
38 | void CALLBACK on_gui_event(UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext);
39 | //!@}
40 | }
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/src/dune/postprocess.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2012
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | #include "postprocess.h"
8 | #include "d3d_tools.h"
9 |
10 | namespace dune
11 | {
12 | postprocessor::postprocessor() :
13 | buffers_start_slot_(-1),
14 | fs_triangle_(),
15 | frontbuffer_(),
16 | enabled_(false)
17 | {
18 | }
19 |
20 | void postprocessor::set_shader(ID3D11Device* device, ID3DBlob* input_binary, ID3D11VertexShader* fs_triangle, UINT buffers_start_slot)
21 | {
22 | fs_triangle_.set_shader(device, input_binary, fs_triangle, nullptr);
23 |
24 | buffers_start_slot_ = buffers_start_slot;
25 |
26 | do_set_shader(device);
27 | }
28 |
29 | void postprocessor::create(ID3D11Device* device, DXGI_SURFACE_DESC desc)
30 | {
31 | disable();
32 |
33 | fs_triangle_.push_back(DirectX::XMFLOAT3(-1.f, -3.f, 1.f));
34 | fs_triangle_.push_back(DirectX::XMFLOAT3(-1.f, 1.f, 1.f));
35 | fs_triangle_.push_back(DirectX::XMFLOAT3(3.f, 1.f, 1.f));
36 |
37 | fs_triangle_.create(device, L"full_screen_tri");
38 | frontbuffer_.create(device, desc, 0);
39 | do_create(device);
40 |
41 | enable();
42 | }
43 |
44 | void postprocessor::render(ID3D11DeviceContext* context, ID3D11RenderTargetView* backbuffer)
45 | {
46 |
47 | }
48 |
49 | void postprocessor::destroy()
50 | {
51 | do_destroy();
52 | frontbuffer_.destroy();
53 | fs_triangle_.destroy();
54 | buffers_start_slot_ = -1;
55 | }
56 |
57 | void postprocessor::resize(UINT width, UINT height)
58 | {
59 | frontbuffer_.resize(width, height);
60 | do_resize(width, height);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/cmake/FindD3D.cmake:
--------------------------------------------------------------------------------
1 | # Find Microsoft Direct3D 11 in the Windows SDK
2 |
3 | include(FindPackageHandleStandardArgs)
4 |
5 | # find d3d
6 | if (CMAKE_CL_64)
7 | set(LIBPATH "x64")
8 | else()
9 | set(LIBPATH "x86")
10 | endif()
11 |
12 | set(WINDOWS_SDK_VERSION "8.1" CACHE STRING "Specify Windows SDK version")
13 |
14 | set(DXSDK_HKEY "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v${WINDOWS_SDK_VERSION};InstallationFolder]")
15 |
16 | get_filename_component(DXSDK_DIR ${DXSDK_HKEY} ABSOLUTE)
17 |
18 | set(DXSDK_LIB_DIR "${DXSDK_DIR}/Lib/*/um/${LIBPATH}")
19 | set(DXSDK_INC_DIR "${DXSDK_DIR}/Include")
20 |
21 | find_path(D3D_INCLUDE_DIR
22 | NAMES D3D11.h
23 | PATHS ${DXSDK_INC_DIR}/um
24 | PATH_SUFFIXES Include/um)
25 |
26 | find_path(WINDOWS_SDK_INCLUDE_DIR
27 | NAMES winapifamily.h
28 | PATHS ${DXSDK_INC_DIR}/shared
29 | PATH_SUFFIXES Include/shared)
30 |
31 | find_library(WINDOWS_SDK_USP10_LIBRARY
32 | NAMES USP10
33 | PATHS ${DXSDK_LIB_DIR}
34 | PATH_SUFFIXES ${LIBPATH})
35 |
36 | find_library(D3D_D3D11_LIBRARY
37 | NAMES d3d11
38 | PATHS ${DXSDK_LIB_DIR}
39 | PATH_SUFFIXES ${LIBPATH})
40 |
41 | find_library(D3D_D3D10_LIBRARY
42 | NAMES d3d10
43 | PATHS ${DXSDK_LIB_DIR}
44 | PATH_SUFFIXES ${LIBPATH})
45 |
46 | find_library(D3D_D3D9_LIBRARY
47 | NAMES d3d9
48 | PATHS ${DXSDK_LIB_DIR}
49 | PATH_SUFFIXES ${LIBPATH})
50 |
51 | find_library(D3D_D3DCompiler_LIBRARY
52 | NAMES d3dcompiler
53 | PATHS ${DXSDK_LIB_DIR}
54 | PATH_SUFFIXES ${LIBPATH})
55 |
56 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(D3D
57 | DEFAULT_MSG
58 | D3D_INCLUDE_DIR
59 | D3D_D3D11_LIBRARY
60 | D3D_D3D10_LIBRARY
61 | D3D_D3D9_LIBRARY
62 | D3D_D3DCompiler_LIBRARY)
63 |
64 | if(D3D_FOUND)
65 | mark_as_advanced(
66 | D3D_D3D11_LIBRARY
67 | D3D_D3D10_LIBRARY
68 | D3D_D3D9_LIBRARY
69 | D3D_D3DCompiler_LIBRARY)
70 | endif()
71 |
--------------------------------------------------------------------------------
/src/dune/sdk_mesh.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2011
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #ifndef DUNE_SDK_MESH
10 | #define DUNE_SDK_MESH
11 |
12 | #include
13 |
14 | #include "mesh.h"
15 | #include "cbuffer.h"
16 |
17 | class CDXUTSDKMesh;
18 |
19 | namespace dune {
20 |
21 | const D3D11_INPUT_ELEMENT_DESC sdkmesh_vertex_desc[] =
22 | {
23 | { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
24 | { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
25 | { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
26 | { "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0 },
27 | 0
28 | };
29 |
30 | /*! \brief A d3d_mesh created with the SDKMesh DXUT loader. */
31 | class sdk_mesh : public d3d_mesh
32 | {
33 | protected:
34 | std::shared_ptr sdk_mesh_;
35 |
36 | struct cbs_mesh_data_ps
37 | {
38 | DirectX::XMFLOAT4 diffuse_color;
39 | BOOL has_diffuse_tex;
40 | BOOL has_normal_tex;
41 | BOOL has_specular_tex;
42 | BOOL has_alpha_tex;
43 | };
44 |
45 | struct cbs_mesh_data_vs
46 | {
47 | DirectX::XMFLOAT4X4 world;
48 | };
49 |
50 | cbuffer cb_mesh_data_ps_;
51 | cbuffer cb_mesh_data_vs_;
52 |
53 | protected:
54 | virtual void reset();
55 | virtual const D3D11_INPUT_ELEMENT_DESC* vertex_desc() { return sdkmesh_vertex_desc; }
56 | void load_texture(ID3D11Device* device, ID3D11Resource* texture, ID3D11ShaderResourceView* srv, void* context);
57 |
58 | public:
59 | size_t num_vertices();
60 | size_t num_faces();
61 |
62 | void create(ID3D11Device* device, LPCTSTR file);
63 | virtual void render(ID3D11DeviceContext* context, DirectX::XMFLOAT4X4* to_clip);
64 | };
65 |
66 | }
67 |
68 | #endif // SDK_MESH
69 |
--------------------------------------------------------------------------------
/src/dune/serializer.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2014
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | #include "serializer.h"
8 |
9 | #include
10 | #include
11 |
12 | #ifdef UNICODE
13 | typedef boost::property_tree::wptree tptree;
14 | #else
15 | typedef boost::property_tree::ptree tptree;
16 | #endif
17 |
18 | typedef boost::property_tree::xml_writer_settings txml_writer_settings;
19 |
20 | namespace dune
21 | {
22 | namespace detail
23 | {
24 | void to_properties(tstring path, const tptree& pt, std::map& properties)
25 | {
26 | for (const auto& i : pt)
27 | {
28 | tstring subpath = path;
29 |
30 | if (subpath != L"")
31 | subpath += L".";
32 |
33 | subpath += i.first;
34 |
35 | if (!i.second.empty())
36 | {
37 | to_properties(subpath, i.second, properties);
38 | }
39 | else
40 | properties[subpath] = i.second.data();
41 | }
42 | }
43 |
44 | void from_properties(const std::map& properties, tptree& pt)
45 | {
46 | for (const auto& i : properties)
47 | pt.add(i.first, i.second);
48 | }
49 | }
50 |
51 | void serializer::load(const tstring& filename)
52 | {
53 | tptree pt;
54 | boost::property_tree::read_xml(dune::to_string(filename), pt);
55 |
56 | detail::to_properties(L"", pt, properties_);
57 | }
58 |
59 | void serializer::save(const tstring& filename)
60 | {
61 | tptree pt;
62 | detail::from_properties(properties_, pt);
63 |
64 | txml_writer_settings settings(L'\t', 1);
65 | boost::property_tree::write_xml(dune::to_string(filename), pt, std::locale(), settings);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/dune/shader_resource.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2012
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #ifndef DUNE_SHADER_RESOURCE
10 | #define DUNE_SHADER_RESOURCE
11 |
12 | #include
13 | #include "unicode.h"
14 |
15 | namespace dune
16 | {
17 | /*!
18 | * \brief A shader resource wrapper.
19 | *
20 | * This basic interface defines a resource which can be anything that can be uploaded to a GPU.
21 | * Each shader_resource has an identifying name, a function to destroy it and free all its resources
22 | * and several functions to upload it to a typed shader into a specified register.
23 | */
24 | struct shader_resource
25 | {
26 | tstring name;
27 |
28 | /*! \brief Upload the shader resource to register slot of a vertex shader. */
29 | virtual void to_vs(ID3D11DeviceContext* context, UINT slot);
30 |
31 | /*! \brief Upload the shader resource to register slot of a geometry shader. */
32 | virtual void to_gs(ID3D11DeviceContext* context, UINT slot);
33 |
34 | /*! \brief Upload the shader resource to register slot of a pixel shader. */
35 | virtual void to_ps(ID3D11DeviceContext* context, UINT slot);
36 |
37 | /*! \brief Upload the shader resource to register slot of a compute shader. */
38 | virtual void to_cs(ID3D11DeviceContext* context, UINT slot);
39 |
40 | /*! \brief Destroy the shader_resource and free all memory. */
41 | virtual void destroy() = 0;
42 | };
43 |
44 | /*!
45 | * \brief A wrapper class for a sampler state.
46 | *
47 | * Manages an ID3D11SamplerState.
48 | */
49 | struct sampler_state : public shader_resource
50 | {
51 | ID3D11SamplerState* state;
52 |
53 | void create(ID3D11Device* device, const D3D11_SAMPLER_DESC& desc);
54 | void destroy();
55 |
56 | void to_vs(ID3D11DeviceContext* context, UINT slot);
57 | void to_ps(ID3D11DeviceContext* context, UINT slot);
58 | };
59 | }
60 |
61 | #endif
62 |
--------------------------------------------------------------------------------
/shader/common.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2013
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | #ifndef COMMON_SHADER_H
8 | #define COMMON_SHADER_H
9 |
10 | #define SLOT_SVO_PARAMETERS_VS_GS_PS 7
11 | #define SVO_SIZE 256
12 | #define SVO_MIPS 8
13 |
14 | #define SLOT_TEX_SVO_RSM_MU_START 12
15 | #define SLOT_TEX_SVO_RSM_RHO_START 6
16 |
17 | #define SLOT_TEX_SVO_V_START 7
18 | #define SLOT_TEX_SVO_V_DELTA 8
19 | #define SLOT_TEX_SVO_V_MU 9
20 | #define SLOT_TEX_SVO_V_NORMAL 7
21 |
22 | #define SLOT_TEX_LPV_INJECT_RSM_START 6
23 | #define SLOT_TEX_LPV_PROPAGATE_START 7
24 | #define SLOT_TEX_LPV_DEFERRED_START 7
25 |
26 | #define SLOT_TEX_DEFERRED_START 2
27 | #define SLOT_TEX_DEFERRED_KINECT_START 0
28 |
29 | #define SLOT_TEX_DEF_RSM_LINEARDEPTH 6
30 | #define SLOT_TEX_POSTPROCESSING_START 10
31 | #define SLOT_TEX_DIFFUSE 0
32 | #define SLOT_TEX_NORMAL 1
33 | #define SLOT_TEX_SPECULAR 2
34 | #define SLOT_TEX_ALPHA 3
35 | #define SLOT_TEX_OVERLAY 10
36 | #define SLOT_TEX_NOISE 14
37 |
38 | #define SLOT_ONETIME_VS 2
39 | #define SLOT_CAMERA_VS 0
40 |
41 | #define SLOT_ONETIME_PS 6
42 | #define SLOT_CAMERA_PS 1
43 |
44 | #define SLOT_ONETIME_GS 2
45 | #define SLOT_CAMERA_GS 0
46 |
47 | #define SLOT_GI_PARAMETERS_PS 3
48 | #define SLOT_POSTPROCESSING_PS 4
49 | #define SLOT_PER_FRAME_PS 5
50 | #define SLOT_LIGHT_PS 2
51 | #define SLOT_LPV_PARAMETERS_VS_PS 7
52 |
53 | #define USE_LPV
54 | #define GAMMA 2.2
55 | #define SHADOW_BIAS 0.015
56 | #define LPV_SIZE 32
57 | #define M_PI 3.14159265358
58 | #define PCF_SAMPLES 64
59 | #define SSAO_SAMPLES 8
60 | #define MAX_VPLS 512
61 |
62 | #endif
63 |
--------------------------------------------------------------------------------
/shader/pp_fxaa.hlsl:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2012
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | #include "postprocessing.hlsl"
8 |
9 | #define FXAA_PC 1
10 | #define FXAA_HLSL_4 1
11 | #define FXAA_QUALITY__PRESET 12
12 | #define FXAA_GREEN_AS_LUMA 1
13 |
14 | #include "Fxaa3_11.h"
15 |
16 | float4 ps_fxaa(in PS_INPUT inp) : SV_TARGET
17 | {
18 | if (!fxaa_enabled)
19 | return frontbuffer.Sample(StandardFilter, inp.tex_coord);
20 |
21 | float4 unused = float4(0,0,0,0);
22 |
23 | FxaaFloat2 pos = inp.tex_coord;
24 | FxaaFloat4 fxaaConsolePosPos = unused;
25 | FxaaTex tex = { StandardFilter, frontbuffer };
26 | FxaaTex fxaaConsole360TexExpBiasNegOne = { StandardFilter, frontbuffer };
27 | FxaaTex fxaaConsole360TexExpBiasNegTwo = { StandardFilter, frontbuffer };
28 |
29 | float w,h;
30 | frontbuffer.GetDimensions(w,h);
31 |
32 | FxaaFloat2 fxaaQualityRcpFrame = float2(1.0/w, 1.0/h);
33 |
34 | FxaaFloat4 fxaaConsoleRcpFrameOpt = unused;
35 | FxaaFloat4 fxaaConsoleRcpFrameOpt2 = unused;
36 | FxaaFloat4 fxaaConsole360RcpFrameOpt2 = unused;
37 | FxaaFloat fxaaQualitySubpix = 0.75;
38 | FxaaFloat fxaaQualityEdgeThreshold = 0.166;
39 | FxaaFloat fxaaQualityEdgeThresholdMin = 0.0833;
40 | FxaaFloat fxaaConsoleEdgeSharpness = 8.0;
41 | FxaaFloat fxaaConsoleEdgeThreshold = 0.125;
42 | FxaaFloat fxaaConsoleEdgeThresholdMin = 0.05;
43 | FxaaFloat4 fxaaConsole360ConstDir = unused;
44 |
45 | return FxaaPixelShader(
46 | pos,
47 | fxaaConsolePosPos,
48 | tex,
49 | fxaaConsole360TexExpBiasNegOne,
50 | fxaaConsole360TexExpBiasNegTwo,
51 | fxaaQualityRcpFrame,
52 | fxaaConsoleRcpFrameOpt,
53 | fxaaConsoleRcpFrameOpt2,
54 | fxaaConsole360RcpFrameOpt2,
55 | fxaaQualitySubpix,
56 | fxaaQualityEdgeThreshold,
57 | fxaaQualityEdgeThresholdMin,
58 | fxaaConsoleEdgeSharpness,
59 | fxaaConsoleEdgeThreshold,
60 | fxaaConsoleEdgeThresholdMin,
61 | fxaaConsole360ConstDir
62 | );
63 | }
64 |
--------------------------------------------------------------------------------
/src/dune/composite_mesh.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2011
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #ifndef DUNE_COMPOSITE_MESH
10 | #define DUNE_COMPOSITE_MESH
11 |
12 | #include "mesh.h"
13 |
14 | #include
15 | #include
16 |
17 | namespace dune
18 | {
19 | /*!
20 | * \brief A mesh composed from other meshes.
21 | *
22 | * A composite_mesh object is simply a collection of other d3d_mesh objects.
23 | * It can be used to group up objects together or simply have one representative
24 | * for many loaded meshes.
25 | *
26 | * This is not a scenegraph node!
27 | */
28 | class composite_mesh : public d3d_mesh
29 | {
30 | protected:
31 | typedef std::shared_ptr mesh_ptr;
32 | std::vector meshes_;
33 |
34 | public:
35 | size_t num_vertices();
36 | size_t num_faces();
37 |
38 | virtual void set_world(const DirectX::XMFLOAT4X4& world);
39 |
40 | void set_shader(ID3D11Device* device, ID3DBlob* input_binary, ID3D11VertexShader* vs, ID3D11PixelShader* ps);
41 |
42 | virtual void set_shader_slots(INT diffuse_tex = -1, INT specular_tex = -1, INT normal_tex = -1);
43 |
44 | void create(ID3D11Device* device, const tstring& file);
45 |
46 | /*!
47 | * \brief Create a composite_mesh from a filename pattern.
48 | *
49 | * Calling this function will search a directory for a pattern and load all
50 | * hits into as separate meshes to group them up in a composite_mesh.
51 | *
52 | * \param device The Direct3D device.
53 | * \param pattern A string representing a file pattern, e.g. C:/models/\*.obj.
54 | *
55 | */
56 | void create_from_dir(ID3D11Device* device, const tstring& pattern);
57 |
58 | /*! \brief Add a new mesh m to the composite_mesh. */
59 | void push_back(mesh_ptr& m);
60 | void render(ID3D11DeviceContext* context, DirectX::XMFLOAT4X4* to_clip = nullptr);
61 |
62 | /*! \brief Returns the mesh at index i. */
63 | mesh_ptr operator[](size_t i);
64 |
65 | /*! \brief Returns the number of submeshes. */
66 | inline size_t size() { return meshes_.size(); }
67 |
68 | virtual void destroy();
69 | };
70 | }
71 |
72 | #endif // COMPOSITE_MESH
73 |
--------------------------------------------------------------------------------
/shader/pp_bloom.hlsl:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2012
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | #include "postprocessing.hlsl"
8 | #include "tonemapping.hlsl"
9 |
10 | float average_luminance()
11 | {
12 | return rt_adapted_luminance.Load(uint3(0,0,0)).x;
13 | }
14 |
15 | float ps_adapt_exposure(in PS_INPUT inp) : SV_Target
16 | {
17 | //get medium brightness of scene
18 | float curr_lum = luminance(frontbuffer.SampleLevel(StandardFilter, float2(0.5, 0.5), 10).rgb);
19 | float last_lum = rt_adapted_luminance.Load(uint3(0, 0, 0)).x;
20 |
21 | float v = last_lum + (curr_lum - last_lum) * (1 - exp(-time_delta * exposure_speed));
22 |
23 | if (!exposure_adapt)
24 | v = 0.5;
25 |
26 | return v;
27 | }
28 |
29 | // Determines the color based on exposure settings
30 | float3 calc_exposed_color(in float3 color, in float average_lum, in float threshold, out float exposure)
31 | {
32 | // Use geometric mean
33 | average_lum = max(average_lum, 0.001f);
34 | float keyValue = exposure_key;
35 | float linear_exposure = (exposure_key / average_lum);
36 | exposure = log2(max(linear_exposure, 0.0001f));
37 | exposure -= threshold;
38 | return exp2(exposure) * color;
39 | }
40 |
41 | // Applies exposure and tone mapping to the specific color, and applies
42 | // the threshold to the exposure value.
43 | float3 tone_map(in float4 color, in float average_lum, in float threshold, out float exposure)
44 | {
45 | color.rgb = calc_exposed_color(color.rgb, average_lum, threshold, exposure);
46 | color.rgb = tonemap_uc2(color.rgb);
47 |
48 | return color.rgb;
49 | }
50 |
51 | float4 ps_bloom(in PS_INPUT inp) : SV_TARGET
52 | {
53 | float4 color = frontbuffer.SampleLevel(StandardFilter, inp.tex_coord, 0);
54 | float avg_lum = average_luminance();
55 |
56 | float exposure = 0;
57 | color.rgb = tone_map(color.rgba, avg_lum, 0, exposure);
58 |
59 | float4 bloom = bloom_buffer.Sample(ShadowFilter, inp.tex_coord);
60 |
61 | if (bloom_enabled)
62 | return float4((color + bloom).rgb, color.a);
63 | else
64 | return color;
65 | }
66 |
67 | float4 ps_bloom_treshold(in PS_INPUT inp) : SV_TARGET
68 | {
69 | float4 color = frontbuffer.Sample(StandardFilter, inp.tex_coord);
70 |
71 | float avg_lum = average_luminance();
72 | float exposure = 0;
73 | color.rgb = calc_exposed_color(color.rgb, avg_lum, bloom_treshold, exposure);
74 |
75 | if (dot(color.rgb, 0.333f) <= 0.01f)
76 | color = 0.f;
77 |
78 | return float4(color.rgb, 1);
79 | }
80 |
--------------------------------------------------------------------------------
/shader/pp_crt.hlsl:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2012
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | // Reference: https://www.shadertoy.com/view/MsXGD4
8 |
9 | #include "postprocessing.hlsl"
10 |
11 | float4 scanline(in float2 coord, in float4 screen)
12 | {
13 | screen.rgb -= sin((coord.y * 0.7 - (time * 19.0))) * 0.002;
14 | screen.rgb -= sin((coord.y * 0.02 + (time * 6.0))) * 0.005;
15 | return screen;
16 | }
17 |
18 | float4 texture_chromatic_distort(in float2 coord)
19 | {
20 | float4 frag;
21 | frag.r = frontbuffer.SampleLevel(StandardFilter, float2(coord.x - 0.003 * sin(time), coord.y), 0.0).r;
22 | frag.g = frontbuffer.SampleLevel(StandardFilter, float2(coord.x, coord.y), 0.0).g;
23 | frag.b = frontbuffer.SampleLevel(StandardFilter, float2(coord.x + 0.003 * sin(time), coord.y), 0.0).b;
24 | frag.a = frontbuffer.SampleLevel(StandardFilter, float2(coord.x, coord.y), 0.0).a;
25 | return frag;
26 | }
27 |
28 | float2 crt_distort(in float2 coord, in float bend)
29 | {
30 | // put in symmetrical coords
31 | coord = (coord - 0.5) * 2.0;
32 |
33 | // deform coords
34 | coord.x *= 1.0 + pow(abs(abs(coord.y) / bend), 2.0);
35 | coord.y *= 1.0 + pow(abs(abs(coord.x) / bend), 2.0);
36 |
37 | // transform back to 0.0 - 1.0 space
38 | coord = (coord / 2.0) + 0.5;
39 |
40 | return coord;
41 | }
42 |
43 | float vignette(in float2 uv)
44 | {
45 | uv = (uv - 0.5) * 0.98;
46 | return clamp(pow(abs(cos(uv.x * M_PI)), 1.2) * pow(abs(cos(uv.y * M_PI)), 1.2) * 50.0, 0.0, 1.0);
47 | }
48 |
49 | float noise(in float2 uv)
50 | {
51 | float a = noise_tex.SampleLevel(StandardFilter, float3(uv + time*6.0, 0.0), 0.0).r;
52 | float b = noise_tex.SampleLevel(StandardFilter, float3(uv + time*4.0, 0.5), 0.0).r;
53 |
54 | return clamp(a + b, 0.94, 1.0);
55 | }
56 |
57 | float4 ps_crt(in PS_INPUT inp) : SV_Target
58 | {
59 | if (!crt_enabled)
60 | return frontbuffer.Sample(StandardFilter, inp.tex_coord);
61 |
62 | float2 uv = inp.tex_coord.xy;
63 | float2 crt_uv = crt_distort(uv, 3.2);
64 |
65 | float4 color = texture_chromatic_distort(crt_uv);
66 |
67 | float2 dim;
68 | frontbuffer.GetDimensions(dim.x, dim.y);
69 |
70 | float2 screen_space = crt_uv * dim;
71 | color = scanline(screen_space, color);
72 |
73 | color = lerp(vignette(crt_uv) * color, color, 0.2);
74 |
75 | float n = noise(crt_uv*2);
76 |
77 | if (any(clamp(crt_uv, float2(0,0), float2(1,1)) - crt_uv))
78 | return float4(0,0,0,1);
79 | else
80 | return color * n;
81 | }
82 |
--------------------------------------------------------------------------------
/shader/pp_ssao.hlsl:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2012
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | #include "postprocessing.hlsl"
8 |
9 | float ssao(in PS_INPUT inp)
10 | {
11 | float2 tc = inp.tex_coord;
12 | float depth = rt_lineardepth.Sample(StandardFilter, tc).r;
13 | float3 pos = camera_pos + (normalize(inp.view_ray.xyz) * depth);
14 | float3 normal = rt_normals.Sample(StandardFilter, tc).rgb * 2.0 - 1.0;
15 |
16 | if (ssao_scale == 0.0)
17 | return 1.0;
18 |
19 | float w, h;
20 | rt_lineardepth.GetDimensions(w, h);
21 |
22 | const float2 scale = float2(1.0/w, 1.0/h);
23 |
24 | float ret = 0.0;
25 |
26 | float2 samples[24] = {
27 | float2(1,1),
28 | float2(-1,1),
29 | float2(1,-1),
30 | float2(-1,-1),
31 | float2(1,0),
32 | float2(-1,0),
33 | float2(0,-1),
34 | float2(0,-1),
35 |
36 | float2(2, 1),
37 | float2(-2, 1),
38 | float2(2, -1),
39 | float2(-2, -1),
40 | float2(2, 0),
41 | float2(-2, 0),
42 | float2(0, -2),
43 | float2(0, -2),
44 |
45 | float2(1, 2),
46 | float2(-1, 2),
47 | float2(1, -2),
48 | float2(-1, -2),
49 |
50 | float2(2, 2),
51 | float2(-2, 2),
52 | float2(2, -2),
53 | float2(-2, -2),
54 | };
55 |
56 | [unroll]
57 | for (int i = 0; i < 24; ++i)
58 | {
59 | // TODO: Needs distance scaling
60 | float2 ntc = tc + samples[i] * scale * 2 * abs(simple_noise(tc));
61 |
62 | float4 occvr = to_ray(ntc, vp_inv);
63 |
64 | float occdepth = rt_lineardepth.Sample(StandardFilter, ntc.xy).r;
65 |
66 | // bilateral filter
67 | if (abs(occdepth - depth) > 0.1)
68 | continue;
69 |
70 | float3 occnorm = rt_normals.Sample(StandardFilter, ntc.xy).xyz * 2.0 - 1.0;
71 | float3 occpos = camera_pos + (normalize(occvr).xyz * occdepth);
72 |
73 | float3 diff = occpos - pos;
74 | float3 v = normalize(diff);
75 | float ddiff = length(diff);
76 |
77 | if (dot(occnorm, normal) < 0.95)
78 | ret += ssao_scale * saturate(dot(normal, v)) * (1.0 / (1.0 + ddiff));
79 | }
80 |
81 | return 1.0 - saturate(ret/SSAO_SAMPLES);
82 | }
83 |
84 | float4 ps_ssao(in PS_INPUT inp) : SV_TARGET
85 | {
86 | float4 color = frontbuffer.Sample(StandardFilter, inp.tex_coord, 0);
87 |
88 | if (ssao_enabled && color.a > 0)
89 | return color * ssao(inp);
90 | else
91 | return color;
92 | }
93 |
--------------------------------------------------------------------------------
/shader/lpv_tools.hlsl:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2014
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | #ifndef LPV_TOOLS_HLSL
8 | #define LPV_TOOLS_HLSL
9 |
10 | #include "common.h"
11 |
12 | SamplerState LPVFilter : register(s1);
13 |
14 | Texture2DArray lpv_r : register(t7);
15 | Texture2DArray lpv_g : register(t8);
16 | Texture2DArray lpv_b : register(t9);
17 |
18 | cbuffer lpv_parameters : register(b7)
19 | {
20 | float4x4 world_to_lpv : packoffset(c0);
21 | uint lpv_size : packoffset(c4.x);
22 | float3 pad : packoffset(c4.y);
23 | }
24 |
25 | void lpv_trilinear_lookup(in float3 lpv_pos, inout float4 sh_r_val, inout float4 sh_g_val, inout float4 sh_b_val,
26 | in Texture2DArray lpvr, in Texture2DArray lpvg, in Texture2DArray lpvb, in int lpv_size, in SamplerState LPVFilter)
27 | {
28 | float3 tc = float3(lpv_pos.x, lpv_pos.y, lpv_pos.z * lpv_size);
29 |
30 | int zl = floor(tc.z);
31 | int zh = min(zl + 1, lpv_size - 1);
32 |
33 | float inv_zh = tc.z - zl;
34 | float inv_zl = 1.0f - inv_zh;
35 |
36 | float3 tc_l = float3(tc.x, tc.y, zl);
37 | float3 tc_h = float3(tc.x, tc.y, zh);
38 |
39 | sh_r_val = inv_zl * lpvr.SampleLevel(LPVFilter, tc_l, 0) + inv_zh * lpvr.SampleLevel(LPVFilter, tc_h, 0);
40 | sh_g_val = inv_zl * lpvg.SampleLevel(LPVFilter, tc_l, 0) + inv_zh * lpvg.SampleLevel(LPVFilter, tc_h, 0);
41 | sh_b_val = inv_zl * lpvb.SampleLevel(LPVFilter, tc_l, 0) + inv_zh * lpvb.SampleLevel(LPVFilter, tc_h, 0);
42 | }
43 |
44 | float4 gi_from_lpv(in float3 pos, in float3 N)
45 | {
46 | float4 indirect = float4(0.0, 0.0, 0.0, 1.0);
47 |
48 | float4 normal_sh = sh_clamped_cos_coeff(-N);
49 |
50 | float4 shcoeff_red = float4(0,0,0,0);
51 | float4 shcoeff_green = float4(0,0,0,0);
52 | float4 shcoeff_blue = float4(0,0,0,0);
53 |
54 | float3 lpv_pos = mul(world_to_lpv, float4(pos, 1)).xyz;
55 | float3 lpv_normal = normalize(mul(world_to_lpv, float4(N, 0))).xyz;
56 |
57 | // bias
58 | lpv_pos.z -= 0.5/LPV_SIZE;
59 |
60 | // ignore stuff outside the volume
61 | if (lpv_pos.x < 0 || lpv_pos.x > 1 ||
62 | lpv_pos.y < 0 || lpv_pos.y > 1 ||
63 | lpv_pos.z < 0 || lpv_pos.z > 1)
64 | return 0.f;
65 |
66 | lpv_trilinear_lookup(lpv_pos, shcoeff_red, shcoeff_green, shcoeff_blue, lpv_r, lpv_g, lpv_b, LPV_SIZE, LPVFilter);
67 |
68 | indirect.r = dot(shcoeff_red, normal_sh)/M_PI;
69 | indirect.g = dot(shcoeff_green, normal_sh)/M_PI;
70 | indirect.b = dot(shcoeff_blue, normal_sh)/M_PI;
71 |
72 | return indirect;
73 | }
74 |
75 | #endif
76 |
--------------------------------------------------------------------------------
/src/dune/texture.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2011
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #ifndef DUNE_TEXTURE
10 | #define DUNE_TEXTURE
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | #include "shader_resource.h"
17 |
18 | namespace dune
19 | {
20 | /*!
21 | * \brief Wrapper for a Direct3D texture object
22 | *
23 | * Wraps up a Direct3D texture object with its own shader resource view.
24 | */
25 | class texture : public shader_resource
26 | {
27 | protected:
28 | ID3D11ShaderResourceView* srview_;
29 | ID3D11Texture2D* texture_;
30 | DirectX::XMFLOAT2 size_;
31 |
32 | protected:
33 | virtual void do_create(ID3D11Device* device, D3D11_TEXTURE2D_DESC desc, D3D11_SUBRESOURCE_DATA* subresource);
34 |
35 | public:
36 | texture();
37 | virtual ~texture() {}
38 |
39 | /* \brief Returns the shader resource view (SRV). */
40 | ID3D11ShaderResourceView* const srv() const { return srview_; }
41 |
42 | void to_vs(ID3D11DeviceContext* context, UINT slot);
43 | void to_ps(ID3D11DeviceContext* context, UINT slot);
44 |
45 | //!@{
46 | /*! \brief Create an empty texture from given descriptor, other resource or single parameters. */
47 | void create(ID3D11Device* device, D3D11_TEXTURE2D_DESC desc, D3D11_SUBRESOURCE_DATA* subresource = nullptr);
48 | void create(ID3D11Device* device, const DXGI_SURFACE_DESC& desc, UINT num_mipmaps = 1);
49 | void create(ID3D11Device* device, UINT width, UINT height, DXGI_FORMAT format, const DXGI_SAMPLE_DESC& msaa, UINT num_mipmaps = 1);
50 | //!@}
51 |
52 | virtual void destroy();
53 |
54 | /*!
55 | * \brief Map the texture to a pointer.
56 | *
57 | * Maps the texture to a pointer. If the texture is CPU accessible, this pointer can be read from and/or written to.
58 | *
59 | * \param context A Direct3D context.
60 | * \return A pointer to the texture buffer.
61 | */
62 | void* map(ID3D11DeviceContext* context);
63 |
64 | /* \brief Unmap a previously mapped texture. */
65 | void unmap(ID3D11DeviceContext* context);
66 |
67 | /* \brief Returns the size of the texture as float2(width, height). */
68 | DirectX::XMFLOAT2 size() const;
69 |
70 | /* \brief Returns a texture descriptor of the texture. */
71 | D3D11_TEXTURE2D_DESC desc() const;
72 |
73 | /* \brief Returns a pointer to the actual resource behind the texture. */
74 | ID3D11Texture2D* resource() const;
75 | };
76 | }
77 |
78 | #endif
79 |
--------------------------------------------------------------------------------
/shader/fuse_buffers.hlsl:
--------------------------------------------------------------------------------
1 | /*
2 | * The Dirtchamber - Tobias Alexander Franke 2013
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | #include "common.h"
8 |
9 | SamplerState StandardFilter : register(s0);
10 |
11 | struct PS_INPUT
12 | {
13 | float4 position : SV_POSITION;
14 | float2 tex_coord : TEXCOORD0;
15 | float3 view_ray : TEXCOORD1;
16 | };
17 |
18 | struct PS_OUTPUT
19 | {
20 | float4 color : SV_Target0;
21 | float4 specular : SV_Target1;
22 | float4 normal : SV_Target2;
23 | float2 ldepth : SV_Target3;
24 | };
25 |
26 | Texture2D rt_color : register(t0);
27 | Texture2D rt_specular : register(t1);
28 | Texture2D rt_normal : register(t2);
29 | Texture2D rt_lineardepth : register(t3);
30 | Texture2D rt_kinect_color : register(t4);
31 | Texture2D rt_kinect_depth : register(t5);
32 | Texture2D rt_tracked_scene : register(t10);
33 |
34 | cbuffer gi_parameters_ps : register(b3)
35 | {
36 | float vpl_scale : packoffset(c0.x);
37 | float lpv_flux_amplifier : packoffset(c0.y);
38 | uint num_vpls : packoffset(c0.z);
39 | bool debug_gi : packoffset(c0.w);
40 | float4x4 world_to_lpv : packoffset(c1);
41 | }
42 |
43 | PS_OUTPUT ps_fuse_buffers(in PS_INPUT inp) : SV_TARGET
44 | {
45 | PS_OUTPUT output;
46 |
47 | float2 vd = rt_lineardepth.Sample(StandardFilter, inp.tex_coord).rg;
48 | float virtual_depth = vd.r;
49 |
50 | float real_depth = rt_kinect_depth.Sample(StandardFilter, inp.tex_coord).r * 4 - 7;
51 | float2 rd = float2(real_depth, real_depth * real_depth);
52 |
53 | float4 virtual_color = rt_color.Sample(StandardFilter, inp.tex_coord);
54 | float4 real_color = rt_kinect_color.Sample(StandardFilter, inp.tex_coord);
55 |
56 | real_color = pow(real_color, GAMMA);
57 |
58 | output.color = real_color;
59 |
60 | #if 0
61 | output.ldepth = rd;
62 | output.normal = float4(0.0,1.0,0.0,0);
63 | #else
64 | output.ldepth = float2(0,0);
65 | output.normal = float4(0.0,0.0,0.0,0);
66 | #endif
67 |
68 | output.specular = float4(0,0,0,0);
69 |
70 | if (virtual_depth > 0)
71 | {
72 | float3 tracked = rt_tracked_scene.Sample(StandardFilter, inp.tex_coord).rgb;
73 |
74 | if (length(tracked) != 0 || debug_gi)
75 | output.color = real_color;
76 | else
77 | output.color = virtual_color;
78 |
79 | output.normal = rt_normal.Sample(StandardFilter, inp.tex_coord);
80 |
81 | output.ldepth = vd;
82 | output.specular = rt_specular.Sample(StandardFilter, inp.tex_coord);
83 | }
84 |
85 | return output;
86 | }
87 |
--------------------------------------------------------------------------------
/src/dune/texture_cache.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Dune D3D library - Tobias Alexander Franke 2011
3 | * For copyright and license see LICENSE
4 | * http://www.tobias-franke.eu
5 | */
6 |
7 | /*! \file */
8 |
9 | #ifndef DUNE_TEXTURE_CACHE
10 | #define DUNE_TEXTURE_CACHE
11 |
12 | #include