git.s-ol.nu forks/DiligentFX / 7477289
Renamed .h -> .hpp where appropriate assiduous 2 years ago
19 changed file(s) with 783 addition(s) and 783 deletion(s). Raw diff Collapse all Expand all
44 )
55
66 set(INCLUDE
7 "${CMAKE_CURRENT_SOURCE_DIR}/interface/ShadowMapManager.h"
7 "${CMAKE_CURRENT_SOURCE_DIR}/interface/ShadowMapManager.hpp"
88 )
99
1010 target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE})
+0
-150
Components/interface/ShadowMapManager.h less more
0 /*
1 * Copyright 2019-2020 Diligent Graphics LLC
2 * Copyright 2015-2019 Egor Yusov
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * In no event and under no legal theory, whether in tort (including negligence),
17 * contract, or otherwise, unless required by applicable law (such as deliberate
18 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
19 * liable for any damages, including any direct, indirect, special, incidental,
20 * or consequential damages of any character arising as a result of this License or
21 * out of the use or inability to use the software (including but not limited to damages
22 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23 * all other commercial damages or losses), even if such Contributor has been advised
24 * of the possibility of such damages.
25 */
26
27 #include <vector>
28 #include <array>
29
30 #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/RenderDevice.h"
31 #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h"
32 #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/Texture.h"
33 #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/TextureView.h"
34 #include "../../../DiligentCore/Common/interface/RefCntAutoPtr.hpp"
35 #include "../../../DiligentCore/Common/interface/BasicMath.hpp"
36
37 namespace Diligent
38 {
39
40 #include "Shaders/Common/public/BasicStructures.fxh"
41
42 class ShadowMapManager
43 {
44 public:
45 ShadowMapManager();
46
47 // clang-format off
48
49 /// Shadow map manager initialization info
50 struct InitInfo
51 {
52 /// Shadow map format. This parameter must not be TEX_FORMAT_UNKNOWN.
53 TEXTURE_FORMAT Format = TEX_FORMAT_UNKNOWN;
54
55 /// Shadow map resolution, must not be 0.
56 Uint32 Resolution = 0;
57
58 /// Number of shadow cascades, must not be 0.
59 Uint32 NumCascades = 0;
60
61 /// Shadow mode (see SHADOW_MODE_* defines in BasicStructures.fxh), must not be 0.
62 int ShadowMode = 0;
63
64 /// Wether to use 32-bit or 16-bit filterable textures
65 bool Is32BitFilterableFmt = false;
66
67 /// Optional comparison sampler to be set in the shadow map resource view
68 ISampler* pComparisonSampler = nullptr;
69
70 /// Optional sampler to be set in the filterable shadow map representation
71 ISampler* pFilterableShadowMapSampler = nullptr;
72 };
73 void Initialize(IRenderDevice* pDevice, const InitInfo& initInfo);
74
75 ITextureView* GetSRV() { return m_pShadowMapSRV; }
76 ITextureView* GetCascadeDSV(Uint32 Cascade){ return m_pShadowMapDSVs[Cascade]; }
77 ITextureView* GetFilterableSRV() { return m_pFilterableShadowMapSRV; }
78
79 struct DistributeCascadeInfo
80 {
81 /// Pointer to camera view matrix, must not be null.
82 const float4x4* pCameraView = nullptr;
83
84 /// Pointer to camera world matrix.
85 const float4x4* pCameraWorld = nullptr;
86
87 /// Pointer to camera projection matrix, must not be null.
88 const float4x4* pCameraProj = nullptr;
89
90 /// Pointer to light direction, must not be null.
91 const float3* pLightDir = nullptr;
92
93 /// Wether to snap cascades to texels in light view space
94 bool SnapCascades = true;
95
96 /// Wether to stabilize cascade extents in light view space
97 bool StabilizeExtents = true;
98
99 /// Wether to use same extents for X and Y axis. Enabled automatically if StabilizeExtents == true
100 bool EqualizeExtents = true;
101
102 /// Cascade partitioning factor that defines the ratio between fully linear (0.0) and
103 /// fully logarithmic (1.0) partitioning.
104 float fPartitioningFactor = 0.95f;
105
106 /// Callback that allows the application to adjust z range of every cascade.
107 /// The callback is also called with cascade value -1 to adjust that entire camera range.
108 std::function<void(int, float&, float&)> AdjustCascadeRange;
109 };
110
111 // clang-format on
112
113 struct CascadeTransforms
114 {
115 float4x4 Proj;
116 float4x4 WorldToLightProjSpace;
117 };
118
119 void DistributeCascades(const DistributeCascadeInfo& Info,
120 ShadowMapAttribs& shadowMapAttribs);
121
122 void ConvertToFilterable(IDeviceContext* pCtx, const ShadowMapAttribs& ShadowAttribs);
123
124 const CascadeTransforms& GetCascadeTranform(Uint32 Cascade) const { return m_CascadeTransforms[Cascade]; }
125
126 private:
127 void InitializeConversionTechniques(TEXTURE_FORMAT FilterableShadowMapFmt);
128 void InitializeResourceBindings();
129
130 int m_ShadowMode = 0;
131 RefCntAutoPtr<IRenderDevice> m_pDevice;
132 RefCntAutoPtr<ITextureView> m_pShadowMapSRV;
133 std::vector<RefCntAutoPtr<ITextureView>> m_pShadowMapDSVs;
134 RefCntAutoPtr<ITextureView> m_pFilterableShadowMapSRV;
135 std::vector<RefCntAutoPtr<ITextureView>> m_pFilterableShadowMapRTVs;
136 RefCntAutoPtr<ITextureView> m_pIntermediateSRV;
137 RefCntAutoPtr<ITextureView> m_pIntermediateRTV;
138 RefCntAutoPtr<IBuffer> m_pConversionAttribsBuffer;
139 std::vector<CascadeTransforms> m_CascadeTransforms;
140 struct ShadowConversionTechnique
141 {
142 RefCntAutoPtr<IPipelineState> PSO;
143 RefCntAutoPtr<IShaderResourceBinding> SRB;
144 };
145 std::array<ShadowConversionTechnique, SHADOW_MODE_EVSM4 + 1> m_ConversionTech;
146 ShadowConversionTechnique m_BlurVertTech;
147 };
148
149 } // namespace Diligent
0 /*
1 * Copyright 2019-2020 Diligent Graphics LLC
2 * Copyright 2015-2019 Egor Yusov
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * In no event and under no legal theory, whether in tort (including negligence),
17 * contract, or otherwise, unless required by applicable law (such as deliberate
18 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
19 * liable for any damages, including any direct, indirect, special, incidental,
20 * or consequential damages of any character arising as a result of this License or
21 * out of the use or inability to use the software (including but not limited to damages
22 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23 * all other commercial damages or losses), even if such Contributor has been advised
24 * of the possibility of such damages.
25 */
26
27 #include <vector>
28 #include <array>
29
30 #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/RenderDevice.h"
31 #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h"
32 #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/Texture.h"
33 #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/TextureView.h"
34 #include "../../../DiligentCore/Common/interface/RefCntAutoPtr.hpp"
35 #include "../../../DiligentCore/Common/interface/BasicMath.hpp"
36
37 namespace Diligent
38 {
39
40 #include "Shaders/Common/public/BasicStructures.fxh"
41
42 class ShadowMapManager
43 {
44 public:
45 ShadowMapManager();
46
47 // clang-format off
48
49 /// Shadow map manager initialization info
50 struct InitInfo
51 {
52 /// Shadow map format. This parameter must not be TEX_FORMAT_UNKNOWN.
53 TEXTURE_FORMAT Format = TEX_FORMAT_UNKNOWN;
54
55 /// Shadow map resolution, must not be 0.
56 Uint32 Resolution = 0;
57
58 /// Number of shadow cascades, must not be 0.
59 Uint32 NumCascades = 0;
60
61 /// Shadow mode (see SHADOW_MODE_* defines in BasicStructures.fxh), must not be 0.
62 int ShadowMode = 0;
63
64 /// Wether to use 32-bit or 16-bit filterable textures
65 bool Is32BitFilterableFmt = false;
66
67 /// Optional comparison sampler to be set in the shadow map resource view
68 ISampler* pComparisonSampler = nullptr;
69
70 /// Optional sampler to be set in the filterable shadow map representation
71 ISampler* pFilterableShadowMapSampler = nullptr;
72 };
73 void Initialize(IRenderDevice* pDevice, const InitInfo& initInfo);
74
75 ITextureView* GetSRV() { return m_pShadowMapSRV; }
76 ITextureView* GetCascadeDSV(Uint32 Cascade){ return m_pShadowMapDSVs[Cascade]; }
77 ITextureView* GetFilterableSRV() { return m_pFilterableShadowMapSRV; }
78
79 struct DistributeCascadeInfo
80 {
81 /// Pointer to camera view matrix, must not be null.
82 const float4x4* pCameraView = nullptr;
83
84 /// Pointer to camera world matrix.
85 const float4x4* pCameraWorld = nullptr;
86
87 /// Pointer to camera projection matrix, must not be null.
88 const float4x4* pCameraProj = nullptr;
89
90 /// Pointer to light direction, must not be null.
91 const float3* pLightDir = nullptr;
92
93 /// Wether to snap cascades to texels in light view space
94 bool SnapCascades = true;
95
96 /// Wether to stabilize cascade extents in light view space
97 bool StabilizeExtents = true;
98
99 /// Wether to use same extents for X and Y axis. Enabled automatically if StabilizeExtents == true
100 bool EqualizeExtents = true;
101
102 /// Cascade partitioning factor that defines the ratio between fully linear (0.0) and
103 /// fully logarithmic (1.0) partitioning.
104 float fPartitioningFactor = 0.95f;
105
106 /// Callback that allows the application to adjust z range of every cascade.
107 /// The callback is also called with cascade value -1 to adjust that entire camera range.
108 std::function<void(int, float&, float&)> AdjustCascadeRange;
109 };
110
111 // clang-format on
112
113 struct CascadeTransforms
114 {
115 float4x4 Proj;
116 float4x4 WorldToLightProjSpace;
117 };
118
119 void DistributeCascades(const DistributeCascadeInfo& Info,
120 ShadowMapAttribs& shadowMapAttribs);
121
122 void ConvertToFilterable(IDeviceContext* pCtx, const ShadowMapAttribs& ShadowAttribs);
123
124 const CascadeTransforms& GetCascadeTranform(Uint32 Cascade) const { return m_CascadeTransforms[Cascade]; }
125
126 private:
127 void InitializeConversionTechniques(TEXTURE_FORMAT FilterableShadowMapFmt);
128 void InitializeResourceBindings();
129
130 int m_ShadowMode = 0;
131 RefCntAutoPtr<IRenderDevice> m_pDevice;
132 RefCntAutoPtr<ITextureView> m_pShadowMapSRV;
133 std::vector<RefCntAutoPtr<ITextureView>> m_pShadowMapDSVs;
134 RefCntAutoPtr<ITextureView> m_pFilterableShadowMapSRV;
135 std::vector<RefCntAutoPtr<ITextureView>> m_pFilterableShadowMapRTVs;
136 RefCntAutoPtr<ITextureView> m_pIntermediateSRV;
137 RefCntAutoPtr<ITextureView> m_pIntermediateRTV;
138 RefCntAutoPtr<IBuffer> m_pConversionAttribsBuffer;
139 std::vector<CascadeTransforms> m_CascadeTransforms;
140 struct ShadowConversionTechnique
141 {
142 RefCntAutoPtr<IPipelineState> PSO;
143 RefCntAutoPtr<IShaderResourceBinding> SRB;
144 };
145 std::array<ShadowConversionTechnique, SHADOW_MODE_EVSM4 + 1> m_ConversionTech;
146 ShadowConversionTechnique m_BlurVertTech;
147 };
148
149 } // namespace Diligent
2626
2727 #include <cfloat>
2828
29 #include "ShadowMapManager.h"
29 #include "ShadowMapManager.hpp"
3030 #include "AdvancedMath.hpp"
31 #include "../../../Utilities/include/DiligentFXShaderSourceStreamFactory.h"
31 #include "../../../Utilities/include/DiligentFXShaderSourceStreamFactory.hpp"
3232 #include "GraphicsUtilities.h"
3333 #include "MapHelper.hpp"
3434 #include "CommonlyUsedStates.h"
44 )
55
66 set(INCLUDE
7 "${CMAKE_CURRENT_SOURCE_DIR}/interface/GLTF_PBR_Renderer.h"
7 "${CMAKE_CURRENT_SOURCE_DIR}/interface/GLTF_PBR_Renderer.hpp"
88 )
99
1010 target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE})
+0
-167
GLTF_PBR_Renderer/interface/GLTF_PBR_Renderer.h less more
0 /*
1 * Copyright 2019-2020 Diligent Graphics LLC
2 * Copyright 2015-2019 Egor Yusov
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * In no event and under no legal theory, whether in tort (including negligence),
17 * contract, or otherwise, unless required by applicable law (such as deliberate
18 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
19 * liable for any damages, including any direct, indirect, special, incidental,
20 * or consequential damages of any character arising as a result of this License or
21 * out of the use or inability to use the software (including but not limited to damages
22 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23 * all other commercial damages or losses), even if such Contributor has been advised
24 * of the possibility of such damages.
25 */
26
27 #include <unordered_map>
28 #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h"
29 #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/RenderDevice.h"
30 #include "../../../DiligentTools/AssetLoader/interface/GLTFLoader.h"
31
32 namespace Diligent
33 {
34
35 class GLTF_PBR_Renderer
36 {
37 public:
38 struct CreateInfo
39 {
40 TEXTURE_FORMAT RTVFmt = TEX_FORMAT_UNKNOWN;
41 TEXTURE_FORMAT DSVFmt = TEX_FORMAT_UNKNOWN;
42 bool FrontCCW = false;
43 bool AllowDebugView = false;
44 bool UseIBL = false;
45
46 /// When set to true, pipeline state will be compiled with static samplers.
47 /// When set to false, samplers from the texture views will be used.
48 bool UseStaticSamplers = true;
49 static const SamplerDesc DefaultSampler;
50 SamplerDesc ColorMapStaticSampler = DefaultSampler;
51 SamplerDesc PhysDescMapStaticSampler = DefaultSampler;
52 SamplerDesc NormalMapStaticSampler = DefaultSampler;
53 SamplerDesc AOMapStaticSampler = DefaultSampler;
54 SamplerDesc EmissiveMapStaticSampler = DefaultSampler;
55 };
56
57 GLTF_PBR_Renderer(IRenderDevice* pDevice,
58 IDeviceContext* pCtx,
59 const CreateInfo& CI);
60
61 struct RenderInfo
62 {
63 float4x4 ModelTransform = float4x4::Identity();
64
65 enum class DebugViewType : int
66 {
67 None = 0,
68 BaseColor = 1,
69 Transparency = 2,
70 NormalMap = 3,
71 Occlusion = 4,
72 Emissive = 5,
73 Metallic = 6,
74 Roughness = 7,
75 DiffuseColor = 8,
76 SpecularColor = 9,
77 Reflectance90 = 10,
78 MeshNormal = 11,
79 PerturbedNormal = 12,
80 NdotV = 13,
81 DiffuseIBL = 14,
82 SpecularIBL = 15,
83 NumDebugViews
84 };
85 DebugViewType DebugView = DebugViewType::None;
86
87 float OcclusionStrength = 1;
88 float EmissionScale = 1;
89 float IBLScale = 1;
90 float AverageLogLum = 0.3f;
91 float MiddleGray = 0.18f;
92 float WhitePoint = 3.f;
93 };
94 void Render(IDeviceContext* pCtx,
95 GLTF::Model& GLTFModel,
96 const RenderInfo& RenderParams);
97
98 void InitializeResourceBindings(GLTF::Model& GLTFModel,
99 IBuffer* pCameraAttribs,
100 IBuffer* pLightAttribs);
101
102 void ReleaseResourceBindings(GLTF::Model& GLTFModel);
103
104 void PrecomputeCubemaps(IRenderDevice* pDevice,
105 IDeviceContext* pCtx,
106 ITextureView* pEnvironmentMap);
107
108 ITextureView* GetIrradianceCubeSRV()
109 {
110 return m_pIrradianceCubeSRV;
111 }
112
113 ITextureView* GetPrefilteredEnvMapSRV()
114 {
115 return m_pPrefilteredEnvMapSRV;
116 }
117
118 private:
119 void PrecomputeBRDF(IRenderDevice* pDevice,
120 IDeviceContext* pCtx);
121
122 void CreatePSO(IRenderDevice* pDevice);
123
124 void RenderGLTFNode(IDeviceContext* pCtx,
125 const GLTF::Node* node,
126 GLTF::Material::ALPHA_MODE AlphaMode,
127 const float4x4& ModelTransform);
128
129 void UpdateRenderParams(IDeviceContext* pCtx);
130
131 IShaderResourceBinding* CreateMaterialSRB(GLTF::Material& Material,
132 IBuffer* pCameraAttribs,
133 IBuffer* pLightAttribs);
134
135 const CreateInfo m_Settings;
136
137 static constexpr Uint32 BRDF_LUT_Dim = 512;
138 RefCntAutoPtr<ITextureView> m_pBRDF_LUT_SRV;
139 RefCntAutoPtr<IPipelineState> m_pRenderGLTF_PBR_PSO;
140 RefCntAutoPtr<IPipelineState> m_pRenderGLTF_PBR_AlphaBlend_PSO;
141
142 RefCntAutoPtr<ITextureView> m_pWhiteTexSRV;
143 RefCntAutoPtr<ITextureView> m_pBlackTexSRV;
144 RefCntAutoPtr<ITextureView> m_pDefaultNormalMapSRV;
145 std::unordered_map<const GLTF::Material*, RefCntAutoPtr<IShaderResourceBinding>> m_SRBCache;
146
147 static constexpr TEXTURE_FORMAT IrradianceCubeFmt = TEX_FORMAT_RGBA32_FLOAT;
148 static constexpr TEXTURE_FORMAT PrefilteredEnvMapFmt = TEX_FORMAT_RGBA16_FLOAT;
149 static constexpr Uint32 IrradianceCubeDim = 64;
150 static constexpr Uint32 PrefilteredEnvMapDim = 256;
151 RefCntAutoPtr<ITextureView> m_pIrradianceCubeSRV;
152 RefCntAutoPtr<ITextureView> m_pPrefilteredEnvMapSRV;
153 RefCntAutoPtr<IPipelineState> m_pPrecomputeIrradianceCubePSO;
154 RefCntAutoPtr<IPipelineState> m_pPrefilterEnvMapPSO;
155 RefCntAutoPtr<IShaderResourceBinding> m_pPrecomputeIrradianceCubeSRB;
156 RefCntAutoPtr<IShaderResourceBinding> m_pPrefilterEnvMapSRB;
157
158 RenderInfo m_RenderParams;
159
160 RefCntAutoPtr<IBuffer> m_TransformsCB;
161 RefCntAutoPtr<IBuffer> m_MaterialInfoCB;
162 RefCntAutoPtr<IBuffer> m_RenderParametersCB;
163 RefCntAutoPtr<IBuffer> m_PrecomputeEnvMapAttribsCB;
164 };
165
166 } // namespace Diligent
0 /*
1 * Copyright 2019-2020 Diligent Graphics LLC
2 * Copyright 2015-2019 Egor Yusov
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * In no event and under no legal theory, whether in tort (including negligence),
17 * contract, or otherwise, unless required by applicable law (such as deliberate
18 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
19 * liable for any damages, including any direct, indirect, special, incidental,
20 * or consequential damages of any character arising as a result of this License or
21 * out of the use or inability to use the software (including but not limited to damages
22 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23 * all other commercial damages or losses), even if such Contributor has been advised
24 * of the possibility of such damages.
25 */
26
27 #include <unordered_map>
28 #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h"
29 #include "../../../DiligentCore/Graphics/GraphicsEngine/interface/RenderDevice.h"
30 #include "../../../DiligentTools/AssetLoader/interface/GLTFLoader.hpp"
31
32 namespace Diligent
33 {
34
35 class GLTF_PBR_Renderer
36 {
37 public:
38 struct CreateInfo
39 {
40 TEXTURE_FORMAT RTVFmt = TEX_FORMAT_UNKNOWN;
41 TEXTURE_FORMAT DSVFmt = TEX_FORMAT_UNKNOWN;
42 bool FrontCCW = false;
43 bool AllowDebugView = false;
44 bool UseIBL = false;
45
46 /// When set to true, pipeline state will be compiled with static samplers.
47 /// When set to false, samplers from the texture views will be used.
48 bool UseStaticSamplers = true;
49 static const SamplerDesc DefaultSampler;
50 SamplerDesc ColorMapStaticSampler = DefaultSampler;
51 SamplerDesc PhysDescMapStaticSampler = DefaultSampler;
52 SamplerDesc NormalMapStaticSampler = DefaultSampler;
53 SamplerDesc AOMapStaticSampler = DefaultSampler;
54 SamplerDesc EmissiveMapStaticSampler = DefaultSampler;
55 };
56
57 GLTF_PBR_Renderer(IRenderDevice* pDevice,
58 IDeviceContext* pCtx,
59 const CreateInfo& CI);
60
61 struct RenderInfo
62 {
63 float4x4 ModelTransform = float4x4::Identity();
64
65 enum class DebugViewType : int
66 {
67 None = 0,
68 BaseColor = 1,
69 Transparency = 2,
70 NormalMap = 3,
71 Occlusion = 4,
72 Emissive = 5,
73 Metallic = 6,
74 Roughness = 7,
75 DiffuseColor = 8,
76 SpecularColor = 9,
77 Reflectance90 = 10,
78 MeshNormal = 11,
79 PerturbedNormal = 12,
80 NdotV = 13,
81 DiffuseIBL = 14,
82 SpecularIBL = 15,
83 NumDebugViews
84 };
85 DebugViewType DebugView = DebugViewType::None;
86
87 float OcclusionStrength = 1;
88 float EmissionScale = 1;
89 float IBLScale = 1;
90 float AverageLogLum = 0.3f;
91 float MiddleGray = 0.18f;
92 float WhitePoint = 3.f;
93 };
94 void Render(IDeviceContext* pCtx,
95 GLTF::Model& GLTFModel,
96 const RenderInfo& RenderParams);
97
98 void InitializeResourceBindings(GLTF::Model& GLTFModel,
99 IBuffer* pCameraAttribs,
100 IBuffer* pLightAttribs);
101
102 void ReleaseResourceBindings(GLTF::Model& GLTFModel);
103
104 void PrecomputeCubemaps(IRenderDevice* pDevice,
105 IDeviceContext* pCtx,
106 ITextureView* pEnvironmentMap);
107
108 ITextureView* GetIrradianceCubeSRV()
109 {
110 return m_pIrradianceCubeSRV;
111 }
112
113 ITextureView* GetPrefilteredEnvMapSRV()
114 {
115 return m_pPrefilteredEnvMapSRV;
116 }
117
118 private:
119 void PrecomputeBRDF(IRenderDevice* pDevice,
120 IDeviceContext* pCtx);
121
122 void CreatePSO(IRenderDevice* pDevice);
123
124 void RenderGLTFNode(IDeviceContext* pCtx,
125 const GLTF::Node* node,
126 GLTF::Material::ALPHA_MODE AlphaMode,
127 const float4x4& ModelTransform);
128
129 void UpdateRenderParams(IDeviceContext* pCtx);
130
131 IShaderResourceBinding* CreateMaterialSRB(GLTF::Material& Material,
132 IBuffer* pCameraAttribs,
133 IBuffer* pLightAttribs);
134
135 const CreateInfo m_Settings;
136
137 static constexpr Uint32 BRDF_LUT_Dim = 512;
138 RefCntAutoPtr<ITextureView> m_pBRDF_LUT_SRV;
139 RefCntAutoPtr<IPipelineState> m_pRenderGLTF_PBR_PSO;
140 RefCntAutoPtr<IPipelineState> m_pRenderGLTF_PBR_AlphaBlend_PSO;
141
142 RefCntAutoPtr<ITextureView> m_pWhiteTexSRV;
143 RefCntAutoPtr<ITextureView> m_pBlackTexSRV;
144 RefCntAutoPtr<ITextureView> m_pDefaultNormalMapSRV;
145 std::unordered_map<const GLTF::Material*, RefCntAutoPtr<IShaderResourceBinding>> m_SRBCache;
146
147 static constexpr TEXTURE_FORMAT IrradianceCubeFmt = TEX_FORMAT_RGBA32_FLOAT;
148 static constexpr TEXTURE_FORMAT PrefilteredEnvMapFmt = TEX_FORMAT_RGBA16_FLOAT;
149 static constexpr Uint32 IrradianceCubeDim = 64;
150 static constexpr Uint32 PrefilteredEnvMapDim = 256;
151 RefCntAutoPtr<ITextureView> m_pIrradianceCubeSRV;
152 RefCntAutoPtr<ITextureView> m_pPrefilteredEnvMapSRV;
153 RefCntAutoPtr<IPipelineState> m_pPrecomputeIrradianceCubePSO;
154 RefCntAutoPtr<IPipelineState> m_pPrefilterEnvMapPSO;
155 RefCntAutoPtr<IShaderResourceBinding> m_pPrecomputeIrradianceCubeSRB;
156 RefCntAutoPtr<IShaderResourceBinding> m_pPrefilterEnvMapSRB;
157
158 RenderInfo m_RenderParams;
159
160 RefCntAutoPtr<IBuffer> m_TransformsCB;
161 RefCntAutoPtr<IBuffer> m_MaterialInfoCB;
162 RefCntAutoPtr<IBuffer> m_RenderParametersCB;
163 RefCntAutoPtr<IBuffer> m_PrecomputeEnvMapAttribsCB;
164 };
165
166 } // namespace Diligent
2727 #include <cstring>
2828 #include <array>
2929
30 #include "GLTF_PBR_Renderer.h"
31 #include "../../../Utilities/include/DiligentFXShaderSourceStreamFactory.h"
30 #include "GLTF_PBR_Renderer.hpp"
31 #include "../../../Utilities/include/DiligentFXShaderSourceStreamFactory.hpp"
3232 #include "CommonlyUsedStates.h"
3333 #include "HashUtils.hpp"
3434 #include "ShaderMacroHelper.hpp"
44 )
55
66 set(INCLUDE
7 "${CMAKE_CURRENT_SOURCE_DIR}/interface/EpipolarLightScattering.h"
7 "${CMAKE_CURRENT_SOURCE_DIR}/interface/EpipolarLightScattering.hpp"
88 )
99
1010 target_sources(DiligentFX PRIVATE ${SOURCE} ${INCLUDE})
+0
-379
PostProcess/EpipolarLightScattering/interface/EpipolarLightScattering.h less more
0 /*
1 * Copyright 2019-2020 Diligent Graphics LLC
2 * Copyright 2015-2019 Egor Yusov
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * In no event and under no legal theory, whether in tort (including negligence),
17 * contract, or otherwise, unless required by applicable law (such as deliberate
18 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
19 * liable for any damages, including any direct, indirect, special, incidental,
20 * or consequential damages of any character arising as a result of this License or
21 * out of the use or inability to use the software (including but not limited to damages
22 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23 * all other commercial damages or losses), even if such Contributor has been advised
24 * of the possibility of such damages.
25 */
26 #pragma once
27
28 #include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/RenderDevice.h"
29 #include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h"
30 #include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/Buffer.h"
31 #include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/Texture.h"
32 #include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/BufferView.h"
33 #include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/TextureView.h"
34 #include "../../../../DiligentCore/Common/interface/RefCntAutoPtr.hpp"
35 #include "../../../../DiligentCore/Common/interface/BasicMath.hpp"
36
37 namespace Diligent
38 {
39
40 using uint = uint32_t;
41
42 #include "Shaders/Common/public/BasicStructures.fxh"
43 #include "Shaders/PostProcess/ToneMapping/public/ToneMappingStructures.fxh"
44 #include "Shaders/PostProcess/EpipolarLightScattering/public/EpipolarLightScatteringStructures.fxh"
45
46
47 class EpipolarLightScattering
48 {
49 public:
50 struct FrameAttribs
51 {
52 IRenderDevice* pDevice = nullptr;
53 IDeviceContext* pDeviceContext = nullptr;
54
55 double dElapsedTime = 0;
56
57 const LightAttribs* pLightAttribs = nullptr;
58 const CameraAttribs* pCameraAttribs = nullptr;
59 // If this parameter is null, the effect will use its own buffer.
60 IBuffer* pcbLightAttribs = nullptr;
61 // If this parameter is null, the effect will use its own buffer.
62 IBuffer* pcbCameraAttribs = nullptr;
63
64 /// Shader resource view of the source color buffer.
65 ITextureView* ptex2DSrcColorBufferSRV = nullptr;
66
67 /// Render target view of the source color buffer. This RTV is used to render the sun.
68 ITextureView* ptex2DSrcColorBufferRTV = nullptr;
69
70 /// Depth-stencil view of the source depth. This DSV is used to render the sun.
71 ITextureView* ptex2DSrcDepthBufferDSV = nullptr;
72
73 /// Shader resource view of the source depth.
74 ITextureView* ptex2DSrcDepthBufferSRV = nullptr;
75
76 /// Render target view of the destination color buffer where final image will be rendered.
77 ITextureView* ptex2DDstColorBufferRTV = nullptr;
78
79 /// Depth-stencil view of the destination depth buffer where.
80 ITextureView* ptex2DDstDepthBufferDSV = nullptr;
81
82 /// Shadow map shader resource view
83 ITextureView* ptex2DShadowMapSRV = nullptr;
84 };
85
86 EpipolarLightScattering(IRenderDevice* in_pDevice,
87 IDeviceContext* in_pContext,
88 TEXTURE_FORMAT BackBufferFmt,
89 TEXTURE_FORMAT DepthBufferFmt,
90 TEXTURE_FORMAT OffscreenBackBuffer,
91 const AirScatteringAttribs& ScatteringAttibs = AirScatteringAttribs{});
92 ~EpipolarLightScattering();
93
94
95 void OnWindowResize(IRenderDevice* pDevice, Uint32 uiBackBufferWidth, Uint32 uiBackBufferHeight);
96
97 void PerformPostProcessing(FrameAttribs& FrameAttribs,
98 EpipolarLightScatteringAttribs& PPAttribs);
99
100 void ComputeSunColor(const float3& vDirectionOnSun,
101 const float4& f4ExtraterrestrialSunColor,
102 float4& f4SunColorAtGround,
103 float4& f4AmbientLight);
104
105 void RenderSun();
106
107 IBuffer* GetMediaAttribsCB() { return m_pcbMediaAttribs; }
108 ITextureView* GetPrecomputedNetDensitySRV() { return m_ptex2DOccludedNetDensityToAtmTopSRV; }
109 ITextureView* GetAmbientSkyLightSRV(IRenderDevice* pDevice, IDeviceContext* pContext);
110
111 private:
112 void ReconstructCameraSpaceZ();
113 void RenderSliceEndpoints();
114 void RenderCoordinateTexture();
115 void RenderCoarseUnshadowedInctr();
116 void RefineSampleLocations();
117 void MarkRayMarchingSamples();
118 void RenderSliceUVDirAndOrig();
119 void Build1DMinMaxMipMap(int iCascadeIndex);
120 void DoRayMarching(Uint32 uiMaxStepsAlongRay, int iCascadeIndex);
121 void InterpolateInsctrIrradiance();
122 void UnwarpEpipolarScattering(bool bRenderLuminance);
123 void UpdateAverageLuminance();
124 enum class EFixInscatteringMode
125 {
126 LuminanceOnly = 0,
127 FixInscattering = 1,
128 FullScreenRayMarching = 2
129 };
130 void FixInscatteringAtDepthBreaks(Uint32 uiMaxStepsAlongRay, EFixInscatteringMode Mode);
131 void RenderSampleLocations();
132
133 void PrecomputeOpticalDepthTexture(IRenderDevice* pDevice, IDeviceContext* pContext);
134 void PrecomputeScatteringLUT(IRenderDevice* pDevice, IDeviceContext* pContext);
135 void CreateRandomSphereSamplingTexture(IRenderDevice* pDevice);
136 void ComputeAmbientSkyLightTexture(IRenderDevice* pDevice, IDeviceContext* pContext);
137 void ComputeScatteringCoefficients(IDeviceContext* pDeviceCtx = nullptr);
138 void CreateEpipolarTextures(IRenderDevice* pDevice);
139 void CreateSliceEndPointsTexture(IRenderDevice* pDevice);
140 void CreateExtinctionTexture(IRenderDevice* pDevice);
141 void CreateAmbientSkyLightTexture(IRenderDevice* pDevice);
142 void CreateLowResLuminanceTexture(IRenderDevice* pDevice, IDeviceContext* pDeviceCtx);
143 void CreateSliceUVDirAndOriginTexture(IRenderDevice* pDevice);
144 void CreateCamSpaceZTexture(IRenderDevice* pDevice);
145 void CreateMinMaxShadowMap(IRenderDevice* pDevice);
146
147 void DefineMacros(class ShaderMacroHelper& Macros);
148
149 const TEXTURE_FORMAT m_BackBufferFmt;
150 const TEXTURE_FORMAT m_DepthBufferFmt;
151 const TEXTURE_FORMAT m_OffscreenBackBufferFmt;
152
153 static constexpr TEXTURE_FORMAT PrecomputedNetDensityTexFmt = TEX_FORMAT_RG32_FLOAT;
154 static constexpr TEXTURE_FORMAT CoordinateTexFmt = TEX_FORMAT_RG32_FLOAT;
155 static constexpr TEXTURE_FORMAT SliceEndpointsFmt = TEX_FORMAT_RGBA32_FLOAT;
156 static constexpr TEXTURE_FORMAT InterpolationSourceTexFmt = TEX_FORMAT_RGBA32_UINT;
157 static constexpr TEXTURE_FORMAT EpipolarCamSpaceZFmt = TEX_FORMAT_R32_FLOAT;
158 static constexpr TEXTURE_FORMAT EpipolarInsctrTexFmt = TEX_FORMAT_RGBA16_FLOAT;
159 static constexpr TEXTURE_FORMAT EpipolarImageDepthFmt0 = TEX_FORMAT_D24_UNORM_S8_UINT;
160 static constexpr TEXTURE_FORMAT EpipolarImageDepthFmt1 = TEX_FORMAT_D32_FLOAT_S8X24_UINT;
161 static constexpr TEXTURE_FORMAT EpipolarExtinctionFmt = TEX_FORMAT_RGBA8_UNORM;
162 static constexpr TEXTURE_FORMAT AmbientSkyLightTexFmt = TEX_FORMAT_RGBA16_FLOAT;
163 static constexpr TEXTURE_FORMAT WeightedLogLumTexFmt = TEX_FORMAT_RG16_FLOAT;
164 static constexpr TEXTURE_FORMAT AverageLuminanceTexFmt = TEX_FORMAT_R16_FLOAT;
165 static constexpr TEXTURE_FORMAT SliceUVDirAndOriginTexFmt = TEX_FORMAT_RGBA32_FLOAT;
166 static constexpr TEXTURE_FORMAT CamSpaceZFmt = TEX_FORMAT_R32_FLOAT;
167
168
169 EpipolarLightScatteringAttribs m_PostProcessingAttribs;
170 FrameAttribs m_FrameAttribs;
171
172 struct UserResourceIds
173 {
174 Int32 LightAttribs = -1;
175 Int32 CameraAttribs = -1;
176 Int32 SrcColorBufferSRV = -1;
177 Int32 SrcColorBufferRTV = -1;
178 Int32 SrcDepthBufferDSV = -1;
179 Int32 SrcDepthBufferSRV = -1;
180 Int32 ShadowMapSRV = -1;
181 } m_UserResourceIds;
182
183 bool m_bUseCombinedMinMaxTexture;
184 Uint32 m_uiSampleRefinementCSThreadGroupSize;
185 Uint32 m_uiSampleRefinementCSMinimumThreadGroupSize;
186
187 static const int sm_iNumPrecomputedHeights = 1024;
188 static const int sm_iNumPrecomputedAngles = 1024;
189
190 int m_iPrecomputedSctrUDim = 32;
191 int m_iPrecomputedSctrVDim = 128;
192 int m_iPrecomputedSctrWDim = 64;
193 int m_iPrecomputedSctrQDim = 16;
194
195 RefCntAutoPtr<ITextureView> m_ptex3DSingleScatteringSRV;
196 RefCntAutoPtr<ITextureView> m_ptex3DHighOrderScatteringSRV;
197 RefCntAutoPtr<ITextureView> m_ptex3DMultipleScatteringSRV;
198
199 Uint32 m_uiNumRandomSamplesOnSphere = 128;
200 RefCntAutoPtr<ITextureView> m_ptex2DSphereRandomSamplingSRV;
201
202 static const int sm_iLowResLuminanceMips = 7; // 64x64
203 RefCntAutoPtr<ITextureView> m_ptex2DLowResLuminanceRTV; // 64 X 64 R16F
204 RefCntAutoPtr<ITextureView> m_ptex2DLowResLuminanceSRV;
205 RefCntAutoPtr<ITextureView> m_ptex2DAverageLuminanceRTV; // 1 X 1 R16F
206
207 static const int sm_iAmbientSkyLightTexDim = 1024;
208 RefCntAutoPtr<ITextureView> m_ptex2DAmbientSkyLightSRV; // 1024 x 1 RGBA16F
209 RefCntAutoPtr<ITextureView> m_ptex2DAmbientSkyLightRTV;
210 RefCntAutoPtr<ITextureView> m_ptex2DOccludedNetDensityToAtmTopSRV; // 1024 x 1024 RG32F
211 RefCntAutoPtr<ITextureView> m_ptex2DOccludedNetDensityToAtmTopRTV;
212
213 RefCntAutoPtr<IShader> m_pFullScreenTriangleVS;
214
215 RefCntAutoPtr<IResourceMapping> m_pResMapping;
216
217 RefCntAutoPtr<ITextureView> m_ptex2DCoordinateTextureRTV; // Max Samples X Num Slices RG32F
218 RefCntAutoPtr<ITextureView> m_ptex2DSliceEndpointsRTV; // Num Slices X 1 RGBA32F
219 RefCntAutoPtr<ITextureView> m_ptex2DEpipolarCamSpaceZRTV; // Max Samples X Num Slices R32F
220 RefCntAutoPtr<ITextureView> m_ptex2DEpipolarInscatteringRTV; // Max Samples X Num Slices RGBA16F
221 RefCntAutoPtr<ITextureView> m_ptex2DEpipolarExtinctionRTV; // Max Samples X Num Slices RGBA8_UNORM
222 RefCntAutoPtr<ITextureView> m_ptex2DEpipolarImageDSV; // Max Samples X Num Slices D24S8
223 RefCntAutoPtr<ITextureView> m_ptex2DInitialScatteredLightRTV; // Max Samples X Num Slices RGBA16F
224 RefCntAutoPtr<ITextureView> m_ptex2DSliceUVDirAndOriginRTV; // Num Slices X Num Cascaes RGBA32F
225 RefCntAutoPtr<ITextureView> m_ptex2DCamSpaceZRTV; // BckBfrWdth x BckBfrHght R32F
226 RefCntAutoPtr<ITextureView> m_ptex2DMinMaxShadowMapSRV[2]; // MinMaxSMRes x Num Slices RG32F or RG16UNORM
227 RefCntAutoPtr<ITextureView> m_ptex2DMinMaxShadowMapRTV[2];
228
229 RefCntAutoPtr<ISampler> m_pPointClampSampler, m_pLinearClampSampler;
230
231 struct RenderTechnique
232 {
233 RefCntAutoPtr<IPipelineState> PSO;
234 RefCntAutoPtr<IShaderResourceBinding> SRB;
235 Uint32 PSODependencyFlags = 0;
236 Uint32 SRBDependencyFlags = 0;
237
238 void InitializeFullScreenTriangleTechnique(IRenderDevice* pDevice,
239 const char* PSOName,
240 IShader* VertexShader,
241 IShader* PixelShader,
242 const PipelineResourceLayoutDesc& ResourceLayout,
243 Uint8 NumRTVs,
244 TEXTURE_FORMAT RTVFmts[],
245 TEXTURE_FORMAT DSVFmt,
246 const DepthStencilStateDesc& DSSDesc,
247 const BlendStateDesc& BSDesc);
248
249 void InitializeFullScreenTriangleTechnique(IRenderDevice* pDevice,
250 const char* PSOName,
251 IShader* VertexShader,
252 IShader* PixelShader,
253 const PipelineResourceLayoutDesc& ResourceLayout,
254 TEXTURE_FORMAT RTVFmt,
255 TEXTURE_FORMAT DSVFmt,
256 const DepthStencilStateDesc& DSSDesc,
257 const BlendStateDesc& BSDesc);
258
259 void InitializeComputeTechnique(IRenderDevice* pDevice,
260 const char* PSOName,
261 IShader* ComputeShader,
262 const PipelineResourceLayoutDesc& ResourceLayout);
263
264 void PrepareSRB(IRenderDevice* pDevice, IResourceMapping* pResMapping, Uint32 Flags);
265
266 void Render(IDeviceContext* pDeviceContext, Uint8 StencilRef = 0, Uint32 NumQuads = 1);
267
268 void DispatchCompute(IDeviceContext* pDeviceContext, const DispatchComputeAttribs& DispatchAttrs);
269
270 void CheckStaleFlags(Uint32 StalePSODependencies, Uint32 StaleSRBDependencies);
271 };
272
273 enum RENDER_TECH
274 {
275 RENDER_TECH_RECONSTRUCT_CAM_SPACE_Z = 0,
276 RENDER_TECH_RENDER_SLICE_END_POINTS,
277 RENDER_TECH_RENDER_COORD_TEXTURE,
278 RENDER_TECH_RENDER_COARSE_UNSHADOWED_INSCTR,
279 RENDER_TECH_REFINE_SAMPLE_LOCATIONS,
280 RENDER_TECH_MARK_RAY_MARCHING_SAMPLES,
281 RENDER_TECH_RENDER_SLICE_UV_DIRECTION,
282 RENDER_TECH_INIT_MIN_MAX_SHADOW_MAP,
283 RENDER_TECH_COMPUTE_MIN_MAX_SHADOW_MAP_LEVEL,
284 RENDER_TECH_RAY_MARCH_NO_MIN_MAX_OPT,
285 RENDER_TECH_RAY_MARCH_MIN_MAX_OPT,
286 RENDER_TECH_INTERPOLATE_IRRADIANCE,
287 RENDER_TECH_UNWARP_EPIPOLAR_SCATTERING,
288 RENDER_TECH_UNWARP_AND_RENDER_LUMINANCE,
289 RENDER_TECH_UPDATE_AVERAGE_LUMINANCE,
290 RENDER_TECH_FIX_INSCATTERING_LUM_ONLY,
291 RENDER_TECH_FIX_INSCATTERING,
292 RENDER_TECH_BRUTE_FORCE_RAY_MARCHING,
293 RENDER_TECH_RENDER_SUN,
294 RENDER_TECH_RENDER_SAMPLE_LOCATIONS,
295
296 // Precomputation techniques
297 RENDER_TECH_PRECOMPUTE_NET_DENSITY_TO_ATM_TOP,
298 RENDER_TECH_PRECOMPUTE_SINGLE_SCATTERING,
299 RENDER_TECH_COMPUTE_SCATTERING_RADIANCE,
300 RENDER_TECH_COMPUTE_SCATTERING_ORDER,
301 RENDER_TECH_INIT_HIGH_ORDER_SCATTERING,
302 RENDER_TECH_UPDATE_HIGH_ORDER_SCATTERING,
303 RENDER_TECH_COMBINE_SCATTERING_ORDERS,
304 RENDER_TECH_PRECOMPUTE_AMBIENT_SKY_LIGHT,
305
306 RENDER_TECH_TOTAL_TECHNIQUES
307 };
308
309 RenderTechnique m_RenderTech[RENDER_TECH_TOTAL_TECHNIQUES];
310
311 enum PSO_DEPENDENCY_FLAGS
312 {
313 PSO_DEPENDENCY_INITIAL_SAMPLE_STEP = 0x00001,
314 PSO_DEPENDENCY_EPIPOLE_SAMPLING_DENSITY = 0x00002,
315 PSO_DEPENDENCY_CORRECT_SCATTERING = 0x00004,
316 PSO_DEPENDENCY_OPTIMIZE_SAMPLE_LOCATIONS = 0x00008,
317 PSO_DEPENDENCY_ENABLE_LIGHT_SHAFTS = 0x00010,
318 PSO_DEPENDENCY_USE_1D_MIN_MAX_TREE = 0x00020,
319 PSO_DEPENDENCY_USE_COMBINED_MIN_MAX_TEX = 0x00040,
320 PSO_DEPENDENCY_LIGHT_SCTR_TECHNIQUE = 0x00080,
321 PSO_DEPENDENCY_CASCADE_PROCESSING_MODE = 0x00100,
322 PSO_DEPENDENCY_REFINEMENT_CRITERION = 0x00200,
323 PSO_DEPENDENCY_IS_32_BIT_MIN_MAX_TREE = 0x00400,
324 PSO_DEPENDENCY_MULTIPLE_SCATTERING_MODE = 0x00800,
325 PSO_DEPENDENCY_SINGLE_SCATTERING_MODE = 0x01000,
326 PSO_DEPENDENCY_AUTO_EXPOSURE = 0x02000,
327 PSO_DEPENDENCY_TONE_MAPPING_MODE = 0x04000,
328 PSO_DEPENDENCY_LIGHT_ADAPTATION = 0x08000,
329 PSO_DEPENDENCY_EXTINCTION_EVAL_MODE = 0x10000
330 };
331
332 enum SRB_DEPENDENCY_FLAGS
333 {
334 SRB_DEPENDENCY_LIGHT_ATTRIBS = 0x00001,
335 SRB_DEPENDENCY_CAMERA_ATTRIBS = 0x00002,
336 SRB_DEPENDENCY_SRC_COLOR_BUFFER = 0x00004,
337 SRB_DEPENDENCY_SRC_DEPTH_BUFFER = 0x00008,
338 SRB_DEPENDENCY_SHADOW_MAP = 0x00010,
339 SRB_DEPENDENCY_MIN_MAX_SHADOW_MAP = 0x00020,
340 SRB_DEPENDENCY_COORDINATE_TEX = 0x00040,
341 SRB_DEPENDENCY_INTERPOLATION_SOURCE_TEX = 0x00080,
342 SRB_DEPENDENCY_SLICE_END_POINTS_TEX = 0x00100,
343 SRB_DEPENDENCY_EPIPOLAR_CAM_SPACE_Z_TEX = 0x00200,
344 SRB_DEPENDENCY_EPIPOLAR_INSCTR_TEX = 0x00400,
345 SRB_DEPENDENCY_EPIPOLAR_EXTINCTION_TEX = 0x00800,
346 SRB_DEPENDENCY_EPIPOLAR_IMAGE_DEPTH = 0x01000,
347 SRB_DEPENDENCY_INITIAL_SCTR_LIGHT_TEX = 0x02000,
348 SRB_DEPENDENCY_AVERAGE_LUMINANCE_TEX = 0x04000,
349 SRB_DEPENDENCY_SLICE_UV_DIR_TEX = 0x08000,
350 SRB_DEPENDENCY_CAM_SPACE_Z_TEX = 0x10000
351 };
352
353 RefCntAutoPtr<IShaderResourceBinding> m_pComputeMinMaxSMLevelSRB[2];
354
355 RefCntAutoPtr<ITexture> m_ptex3DHighOrderSctr, m_ptex3DHighOrderSctr2;
356
357 RefCntAutoPtr<IBuffer> m_pcbPostProcessingAttribs;
358 RefCntAutoPtr<IBuffer> m_pcbMediaAttribs;
359 RefCntAutoPtr<IBuffer> m_pcbMiscParams;
360 RefCntAutoPtr<IBuffer> m_pcbLightAttribs;
361 RefCntAutoPtr<IBuffer> m_pcbCameraAttribs;
362
363 Uint32 m_uiBackBufferWidth = 0;
364 Uint32 m_uiBackBufferHeight = 0;
365
366 //const float m_fTurbidity = 1.02f;
367 AirScatteringAttribs m_MediaParams;
368
369 enum UpToDateResourceFlags
370 {
371 PrecomputedOpticalDepthTex = 0x01,
372 AmbientSkyLightTex = 0x02,
373 PrecomputedIntegralsTex = 0x04
374 };
375 Uint32 m_uiUpToDateResourceFlags;
376 };
377
378 } // namespace Diligent
0 /*
1 * Copyright 2019-2020 Diligent Graphics LLC
2 * Copyright 2015-2019 Egor Yusov
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * In no event and under no legal theory, whether in tort (including negligence),
17 * contract, or otherwise, unless required by applicable law (such as deliberate
18 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
19 * liable for any damages, including any direct, indirect, special, incidental,
20 * or consequential damages of any character arising as a result of this License or
21 * out of the use or inability to use the software (including but not limited to damages
22 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23 * all other commercial damages or losses), even if such Contributor has been advised
24 * of the possibility of such damages.
25 */
26 #pragma once
27
28 #include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/RenderDevice.h"
29 #include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h"
30 #include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/Buffer.h"
31 #include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/Texture.h"
32 #include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/BufferView.h"
33 #include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/TextureView.h"
34 #include "../../../../DiligentCore/Common/interface/RefCntAutoPtr.hpp"
35 #include "../../../../DiligentCore/Common/interface/BasicMath.hpp"
36
37 namespace Diligent
38 {
39
40 using uint = uint32_t;
41
42 #include "Shaders/Common/public/BasicStructures.fxh"
43 #include "Shaders/PostProcess/ToneMapping/public/ToneMappingStructures.fxh"
44 #include "Shaders/PostProcess/EpipolarLightScattering/public/EpipolarLightScatteringStructures.fxh"
45
46
47 class EpipolarLightScattering
48 {
49 public:
50 struct FrameAttribs
51 {
52 IRenderDevice* pDevice = nullptr;
53 IDeviceContext* pDeviceContext = nullptr;
54
55 double dElapsedTime = 0;
56
57 const LightAttribs* pLightAttribs = nullptr;
58 const CameraAttribs* pCameraAttribs = nullptr;
59 // If this parameter is null, the effect will use its own buffer.
60 IBuffer* pcbLightAttribs = nullptr;
61 // If this parameter is null, the effect will use its own buffer.
62 IBuffer* pcbCameraAttribs = nullptr;
63
64 /// Shader resource view of the source color buffer.
65 ITextureView* ptex2DSrcColorBufferSRV = nullptr;
66
67 /// Render target view of the source color buffer. This RTV is used to render the sun.
68 ITextureView* ptex2DSrcColorBufferRTV = nullptr;
69
70 /// Depth-stencil view of the source depth. This DSV is used to render the sun.
71 ITextureView* ptex2DSrcDepthBufferDSV = nullptr;
72
73 /// Shader resource view of the source depth.
74 ITextureView* ptex2DSrcDepthBufferSRV = nullptr;
75
76 /// Render target view of the destination color buffer where final image will be rendered.
77 ITextureView* ptex2DDstColorBufferRTV = nullptr;
78
79 /// Depth-stencil view of the destination depth buffer where.
80 ITextureView* ptex2DDstDepthBufferDSV = nullptr;
81
82 /// Shadow map shader resource view
83 ITextureView* ptex2DShadowMapSRV = nullptr;
84 };
85
86 EpipolarLightScattering(IRenderDevice* in_pDevice,
87 IDeviceContext* in_pContext,
88 TEXTURE_FORMAT BackBufferFmt,
89 TEXTURE_FORMAT DepthBufferFmt,
90 TEXTURE_FORMAT OffscreenBackBuffer,
91 const AirScatteringAttribs& ScatteringAttibs = AirScatteringAttribs{});
92 ~EpipolarLightScattering();
93
94
95 void OnWindowResize(IRenderDevice* pDevice, Uint32 uiBackBufferWidth, Uint32 uiBackBufferHeight);
96
97 void PerformPostProcessing(FrameAttribs& FrameAttribs,
98 EpipolarLightScatteringAttribs& PPAttribs);
99
100 void ComputeSunColor(const float3& vDirectionOnSun,
101 const float4& f4ExtraterrestrialSunColor,
102 float4& f4SunColorAtGround,
103 float4& f4AmbientLight);
104
105 void RenderSun();
106
107 IBuffer* GetMediaAttribsCB() { return m_pcbMediaAttribs; }
108 ITextureView* GetPrecomputedNetDensitySRV() { return m_ptex2DOccludedNetDensityToAtmTopSRV; }
109 ITextureView* GetAmbientSkyLightSRV(IRenderDevice* pDevice, IDeviceContext* pContext);
110
111 private:
112 void ReconstructCameraSpaceZ();
113 void RenderSliceEndpoints();
114 void RenderCoordinateTexture();
115 void RenderCoarseUnshadowedInctr();
116 void RefineSampleLocations();
117 void MarkRayMarchingSamples();
118 void RenderSliceUVDirAndOrig();
119 void Build1DMinMaxMipMap(int iCascadeIndex);
120 void DoRayMarching(Uint32 uiMaxStepsAlongRay, int iCascadeIndex);
121 void InterpolateInsctrIrradiance();
122 void UnwarpEpipolarScattering(bool bRenderLuminance);
123 void UpdateAverageLuminance();
124 enum class EFixInscatteringMode
125 {
126 LuminanceOnly = 0,
127 FixInscattering = 1,
128 FullScreenRayMarching = 2
129 };
130 void FixInscatteringAtDepthBreaks(Uint32 uiMaxStepsAlongRay, EFixInscatteringMode Mode);
131 void RenderSampleLocations();
132
133 void PrecomputeOpticalDepthTexture(IRenderDevice* pDevice, IDeviceContext* pContext);
134 void PrecomputeScatteringLUT(IRenderDevice* pDevice, IDeviceContext* pContext);
135 void CreateRandomSphereSamplingTexture(IRenderDevice* pDevice);
136 void ComputeAmbientSkyLightTexture(IRenderDevice* pDevice, IDeviceContext* pContext);
137 void ComputeScatteringCoefficients(IDeviceContext* pDeviceCtx = nullptr);
138 void CreateEpipolarTextures(IRenderDevice* pDevice);
139 void CreateSliceEndPointsTexture(IRenderDevice* pDevice);
140 void CreateExtinctionTexture(IRenderDevice* pDevice);
141 void CreateAmbientSkyLightTexture(IRenderDevice* pDevice);
142 void CreateLowResLuminanceTexture(IRenderDevice* pDevice, IDeviceContext* pDeviceCtx);
143 void CreateSliceUVDirAndOriginTexture(IRenderDevice* pDevice);
144 void CreateCamSpaceZTexture(IRenderDevice* pDevice);
145 void CreateMinMaxShadowMap(IRenderDevice* pDevice);
146
147 void DefineMacros(class ShaderMacroHelper& Macros);
148
149 const TEXTURE_FORMAT m_BackBufferFmt;
150 const TEXTURE_FORMAT m_DepthBufferFmt;
151 const TEXTURE_FORMAT m_OffscreenBackBufferFmt;
152
153 static constexpr TEXTURE_FORMAT PrecomputedNetDensityTexFmt = TEX_FORMAT_RG32_FLOAT;
154 static constexpr TEXTURE_FORMAT CoordinateTexFmt = TEX_FORMAT_RG32_FLOAT;
155 static constexpr TEXTURE_FORMAT SliceEndpointsFmt = TEX_FORMAT_RGBA32_FLOAT;
156 static constexpr TEXTURE_FORMAT InterpolationSourceTexFmt = TEX_FORMAT_RGBA32_UINT;
157 static constexpr TEXTURE_FORMAT EpipolarCamSpaceZFmt = TEX_FORMAT_R32_FLOAT;
158 static constexpr TEXTURE_FORMAT EpipolarInsctrTexFmt = TEX_FORMAT_RGBA16_FLOAT;
159 static constexpr TEXTURE_FORMAT EpipolarImageDepthFmt0 = TEX_FORMAT_D24_UNORM_S8_UINT;
160 static constexpr TEXTURE_FORMAT EpipolarImageDepthFmt1 = TEX_FORMAT_D32_FLOAT_S8X24_UINT;
161 static constexpr TEXTURE_FORMAT EpipolarExtinctionFmt = TEX_FORMAT_RGBA8_UNORM;
162 static constexpr TEXTURE_FORMAT AmbientSkyLightTexFmt = TEX_FORMAT_RGBA16_FLOAT;
163 static constexpr TEXTURE_FORMAT WeightedLogLumTexFmt = TEX_FORMAT_RG16_FLOAT;
164 static constexpr TEXTURE_FORMAT AverageLuminanceTexFmt = TEX_FORMAT_R16_FLOAT;
165 static constexpr TEXTURE_FORMAT SliceUVDirAndOriginTexFmt = TEX_FORMAT_RGBA32_FLOAT;
166 static constexpr TEXTURE_FORMAT CamSpaceZFmt = TEX_FORMAT_R32_FLOAT;
167
168
169 EpipolarLightScatteringAttribs m_PostProcessingAttribs;
170 FrameAttribs m_FrameAttribs;
171
172 struct UserResourceIds
173 {
174 Int32 LightAttribs = -1;
175 Int32 CameraAttribs = -1;
176 Int32 SrcColorBufferSRV = -1;
177 Int32 SrcColorBufferRTV = -1;
178 Int32 SrcDepthBufferDSV = -1;
179 Int32 SrcDepthBufferSRV = -1;
180 Int32 ShadowMapSRV = -1;
181 } m_UserResourceIds;
182
183 bool m_bUseCombinedMinMaxTexture;
184 Uint32 m_uiSampleRefinementCSThreadGroupSize;
185 Uint32 m_uiSampleRefinementCSMinimumThreadGroupSize;
186
187 static const int sm_iNumPrecomputedHeights = 1024;
188 static const int sm_iNumPrecomputedAngles = 1024;
189
190 int m_iPrecomputedSctrUDim = 32;
191 int m_iPrecomputedSctrVDim = 128;
192 int m_iPrecomputedSctrWDim = 64;
193 int m_iPrecomputedSctrQDim = 16;
194
195 RefCntAutoPtr<ITextureView> m_ptex3DSingleScatteringSRV;
196 RefCntAutoPtr<ITextureView> m_ptex3DHighOrderScatteringSRV;
197 RefCntAutoPtr<ITextureView> m_ptex3DMultipleScatteringSRV;
198
199 Uint32 m_uiNumRandomSamplesOnSphere = 128;
200 RefCntAutoPtr<ITextureView> m_ptex2DSphereRandomSamplingSRV;
201
202 static const int sm_iLowResLuminanceMips = 7; // 64x64
203 RefCntAutoPtr<ITextureView> m_ptex2DLowResLuminanceRTV; // 64 X 64 R16F
204 RefCntAutoPtr<ITextureView> m_ptex2DLowResLuminanceSRV;
205 RefCntAutoPtr<ITextureView> m_ptex2DAverageLuminanceRTV; // 1 X 1 R16F
206
207 static const int sm_iAmbientSkyLightTexDim = 1024;
208 RefCntAutoPtr<ITextureView> m_ptex2DAmbientSkyLightSRV; // 1024 x 1 RGBA16F
209 RefCntAutoPtr<ITextureView> m_ptex2DAmbientSkyLightRTV;
210 RefCntAutoPtr<ITextureView> m_ptex2DOccludedNetDensityToAtmTopSRV; // 1024 x 1024 RG32F
211 RefCntAutoPtr<ITextureView> m_ptex2DOccludedNetDensityToAtmTopRTV;
212
213 RefCntAutoPtr<IShader> m_pFullScreenTriangleVS;
214
215 RefCntAutoPtr<IResourceMapping> m_pResMapping;
216
217 RefCntAutoPtr<ITextureView> m_ptex2DCoordinateTextureRTV; // Max Samples X Num Slices RG32F
218 RefCntAutoPtr<ITextureView> m_ptex2DSliceEndpointsRTV; // Num Slices X 1 RGBA32F
219 RefCntAutoPtr<ITextureView> m_ptex2DEpipolarCamSpaceZRTV; // Max Samples X Num Slices R32F
220 RefCntAutoPtr<ITextureView> m_ptex2DEpipolarInscatteringRTV; // Max Samples X Num Slices RGBA16F
221 RefCntAutoPtr<ITextureView> m_ptex2DEpipolarExtinctionRTV; // Max Samples X Num Slices RGBA8_UNORM
222 RefCntAutoPtr<ITextureView> m_ptex2DEpipolarImageDSV; // Max Samples X Num Slices D24S8
223 RefCntAutoPtr<ITextureView> m_ptex2DInitialScatteredLightRTV; // Max Samples X Num Slices RGBA16F
224 RefCntAutoPtr<ITextureView> m_ptex2DSliceUVDirAndOriginRTV; // Num Slices X Num Cascaes RGBA32F
225 RefCntAutoPtr<ITextureView> m_ptex2DCamSpaceZRTV; // BckBfrWdth x BckBfrHght R32F
226 RefCntAutoPtr<ITextureView> m_ptex2DMinMaxShadowMapSRV[2]; // MinMaxSMRes x Num Slices RG32F or RG16UNORM
227 RefCntAutoPtr<ITextureView> m_ptex2DMinMaxShadowMapRTV[2];
228
229 RefCntAutoPtr<ISampler> m_pPointClampSampler, m_pLinearClampSampler;
230
231 struct RenderTechnique
232 {
233 RefCntAutoPtr<IPipelineState> PSO;
234 RefCntAutoPtr<IShaderResourceBinding> SRB;
235 Uint32 PSODependencyFlags = 0;
236 Uint32 SRBDependencyFlags = 0;
237
238 void InitializeFullScreenTriangleTechnique(IRenderDevice* pDevice,
239 const char* PSOName,
240 IShader* VertexShader,
241 IShader* PixelShader,
242 const PipelineResourceLayoutDesc& ResourceLayout,
243 Uint8 NumRTVs,
244 TEXTURE_FORMAT RTVFmts[],
245 TEXTURE_FORMAT DSVFmt,
246 const DepthStencilStateDesc& DSSDesc,
247 const BlendStateDesc& BSDesc);
248
249 void InitializeFullScreenTriangleTechnique(IRenderDevice* pDevice,
250 const char* PSOName,
251 IShader* VertexShader,
252 IShader* PixelShader,
253 const PipelineResourceLayoutDesc& ResourceLayout,
254 TEXTURE_FORMAT RTVFmt,
255 TEXTURE_FORMAT DSVFmt,
256 const DepthStencilStateDesc& DSSDesc,
257 const BlendStateDesc& BSDesc);
258
259 void InitializeComputeTechnique(IRenderDevice* pDevice,
260 const char* PSOName,
261 IShader* ComputeShader,
262 const PipelineResourceLayoutDesc& ResourceLayout);
263
264 void PrepareSRB(IRenderDevice* pDevice, IResourceMapping* pResMapping, Uint32 Flags);
265
266 void Render(IDeviceContext* pDeviceContext, Uint8 StencilRef = 0, Uint32 NumQuads = 1);
267
268 void DispatchCompute(IDeviceContext* pDeviceContext, const DispatchComputeAttribs& DispatchAttrs);
269
270 void CheckStaleFlags(Uint32 StalePSODependencies, Uint32 StaleSRBDependencies);
271 };
272
273 enum RENDER_TECH
274 {
275 RENDER_TECH_RECONSTRUCT_CAM_SPACE_Z = 0,
276 RENDER_TECH_RENDER_SLICE_END_POINTS,
277 RENDER_TECH_RENDER_COORD_TEXTURE,
278 RENDER_TECH_RENDER_COARSE_UNSHADOWED_INSCTR,
279 RENDER_TECH_REFINE_SAMPLE_LOCATIONS,
280 RENDER_TECH_MARK_RAY_MARCHING_SAMPLES,
281 RENDER_TECH_RENDER_SLICE_UV_DIRECTION,
282 RENDER_TECH_INIT_MIN_MAX_SHADOW_MAP,
283 RENDER_TECH_COMPUTE_MIN_MAX_SHADOW_MAP_LEVEL,
284 RENDER_TECH_RAY_MARCH_NO_MIN_MAX_OPT,
285 RENDER_TECH_RAY_MARCH_MIN_MAX_OPT,
286 RENDER_TECH_INTERPOLATE_IRRADIANCE,
287 RENDER_TECH_UNWARP_EPIPOLAR_SCATTERING,
288 RENDER_TECH_UNWARP_AND_RENDER_LUMINANCE,
289 RENDER_TECH_UPDATE_AVERAGE_LUMINANCE,
290 RENDER_TECH_FIX_INSCATTERING_LUM_ONLY,
291 RENDER_TECH_FIX_INSCATTERING,
292 RENDER_TECH_BRUTE_FORCE_RAY_MARCHING,
293 RENDER_TECH_RENDER_SUN,
294 RENDER_TECH_RENDER_SAMPLE_LOCATIONS,
295
296 // Precomputation techniques
297 RENDER_TECH_PRECOMPUTE_NET_DENSITY_TO_ATM_TOP,
298 RENDER_TECH_PRECOMPUTE_SINGLE_SCATTERING,
299 RENDER_TECH_COMPUTE_SCATTERING_RADIANCE,
300 RENDER_TECH_COMPUTE_SCATTERING_ORDER,
301 RENDER_TECH_INIT_HIGH_ORDER_SCATTERING,
302 RENDER_TECH_UPDATE_HIGH_ORDER_SCATTERING,
303 RENDER_TECH_COMBINE_SCATTERING_ORDERS,
304 RENDER_TECH_PRECOMPUTE_AMBIENT_SKY_LIGHT,
305
306 RENDER_TECH_TOTAL_TECHNIQUES
307 };
308
309 RenderTechnique m_RenderTech[RENDER_TECH_TOTAL_TECHNIQUES];
310
311 enum PSO_DEPENDENCY_FLAGS
312 {
313 PSO_DEPENDENCY_INITIAL_SAMPLE_STEP = 0x00001,
314 PSO_DEPENDENCY_EPIPOLE_SAMPLING_DENSITY = 0x00002,
315 PSO_DEPENDENCY_CORRECT_SCATTERING = 0x00004,
316 PSO_DEPENDENCY_OPTIMIZE_SAMPLE_LOCATIONS = 0x00008,
317 PSO_DEPENDENCY_ENABLE_LIGHT_SHAFTS = 0x00010,
318 PSO_DEPENDENCY_USE_1D_MIN_MAX_TREE = 0x00020,
319 PSO_DEPENDENCY_USE_COMBINED_MIN_MAX_TEX = 0x00040,
320 PSO_DEPENDENCY_LIGHT_SCTR_TECHNIQUE = 0x00080,
321 PSO_DEPENDENCY_CASCADE_PROCESSING_MODE = 0x00100,
322 PSO_DEPENDENCY_REFINEMENT_CRITERION = 0x00200,
323 PSO_DEPENDENCY_IS_32_BIT_MIN_MAX_TREE = 0x00400,
324 PSO_DEPENDENCY_MULTIPLE_SCATTERING_MODE = 0x00800,
325 PSO_DEPENDENCY_SINGLE_SCATTERING_MODE = 0x01000,
326 PSO_DEPENDENCY_AUTO_EXPOSURE = 0x02000,
327 PSO_DEPENDENCY_TONE_MAPPING_MODE = 0x04000,
328 PSO_DEPENDENCY_LIGHT_ADAPTATION = 0x08000,
329 PSO_DEPENDENCY_EXTINCTION_EVAL_MODE = 0x10000
330 };
331
332 enum SRB_DEPENDENCY_FLAGS
333 {
334 SRB_DEPENDENCY_LIGHT_ATTRIBS = 0x00001,
335 SRB_DEPENDENCY_CAMERA_ATTRIBS = 0x00002,
336 SRB_DEPENDENCY_SRC_COLOR_BUFFER = 0x00004,
337 SRB_DEPENDENCY_SRC_DEPTH_BUFFER = 0x00008,
338 SRB_DEPENDENCY_SHADOW_MAP = 0x00010,
339 SRB_DEPENDENCY_MIN_MAX_SHADOW_MAP = 0x00020,
340 SRB_DEPENDENCY_COORDINATE_TEX = 0x00040,
341 SRB_DEPENDENCY_INTERPOLATION_SOURCE_TEX = 0x00080,
342 SRB_DEPENDENCY_SLICE_END_POINTS_TEX = 0x00100,
343 SRB_DEPENDENCY_EPIPOLAR_CAM_SPACE_Z_TEX = 0x00200,
344 SRB_DEPENDENCY_EPIPOLAR_INSCTR_TEX = 0x00400,
345 SRB_DEPENDENCY_EPIPOLAR_EXTINCTION_TEX = 0x00800,
346 SRB_DEPENDENCY_EPIPOLAR_IMAGE_DEPTH = 0x01000,
347 SRB_DEPENDENCY_INITIAL_SCTR_LIGHT_TEX = 0x02000,
348 SRB_DEPENDENCY_AVERAGE_LUMINANCE_TEX = 0x04000,
349 SRB_DEPENDENCY_SLICE_UV_DIR_TEX = 0x08000,
350 SRB_DEPENDENCY_CAM_SPACE_Z_TEX = 0x10000
351 };
352
353 RefCntAutoPtr<IShaderResourceBinding> m_pComputeMinMaxSMLevelSRB[2];
354
355 RefCntAutoPtr<ITexture> m_ptex3DHighOrderSctr, m_ptex3DHighOrderSctr2;
356
357 RefCntAutoPtr<IBuffer> m_pcbPostProcessingAttribs;
358 RefCntAutoPtr<IBuffer> m_pcbMediaAttribs;
359 RefCntAutoPtr<IBuffer> m_pcbMiscParams;
360 RefCntAutoPtr<IBuffer> m_pcbLightAttribs;
361 RefCntAutoPtr<IBuffer> m_pcbCameraAttribs;
362
363 Uint32 m_uiBackBufferWidth = 0;
364 Uint32 m_uiBackBufferHeight = 0;
365
366 //const float m_fTurbidity = 1.02f;
367 AirScatteringAttribs m_MediaParams;
368
369 enum UpToDateResourceFlags
370 {
371 PrecomputedOpticalDepthTex = 0x01,
372 AmbientSkyLightTex = 0x02,
373 PrecomputedIntegralsTex = 0x04
374 };
375 Uint32 m_uiUpToDateResourceFlags;
376 };
377
378 } // namespace Diligent
2929 #include <array>
3030 #include <cstring>
3131
32 #include "EpipolarLightScattering.h"
32 #include "EpipolarLightScattering.hpp"
3333 #include "ShaderMacroHelper.hpp"
3434 #include "GraphicsUtilities.h"
3535 #include "GraphicsAccessories.hpp"
36 #include "../../../Utilities/include/DiligentFXShaderSourceStreamFactory.h"
36 #include "../../../Utilities/include/DiligentFXShaderSourceStreamFactory.hpp"
3737 #include "MapHelper.hpp"
3838 #include "CommonlyUsedStates.h"
3939 #include "Align.hpp"
2424 * of the possibility of such damages.
2525 */
2626
27 #include "Components/interface/ShadowMapManager.h"
27 #include "Components/interface/ShadowMapManager.hpp"
2424 * of the possibility of such damages.
2525 */
2626
27 #include "GLTF_PBR_Renderer/interface/GLTF_PBR_Renderer.h"
27 #include "GLTF_PBR_Renderer/interface/GLTF_PBR_Renderer.hpp"
2424 * of the possibility of such damages.
2525 */
2626
27 #include "PostProcess/EpipolarLightScattering/interface/EpipolarLightScattering.h"
27 #include "PostProcess/EpipolarLightScattering/interface/EpipolarLightScattering.hpp"
00 cmake_minimum_required (VERSION 3.6)
11
22 target_sources(DiligentFX PRIVATE
3 "${CMAKE_CURRENT_SOURCE_DIR}/include/DiligentFXShaderSourceStreamFactory.h"
3 "${CMAKE_CURRENT_SOURCE_DIR}/include/DiligentFXShaderSourceStreamFactory.hpp"
44 "${CMAKE_CURRENT_SOURCE_DIR}/src/DiligentFXShaderSourceStreamFactory.cpp"
55 )
+0
-73
Utilities/include/DiligentFXShaderSourceStreamFactory.h less more
0 /*
1 * Copyright 2019-2020 Diligent Graphics LLC
2 * Copyright 2015-2019 Egor Yusov
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * In no event and under no legal theory, whether in tort (including negligence),
17 * contract, or otherwise, unless required by applicable law (such as deliberate
18 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
19 * liable for any damages, including any direct, indirect, special, incidental,
20 * or consequential damages of any character arising as a result of this License or
21 * out of the use or inability to use the software (including but not limited to damages
22 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23 * all other commercial damages or losses), even if such Contributor has been advised
24 * of the possibility of such damages.
25 */
26
27 #pragma once
28
29 #include <unordered_map>
30 #include "BasicFileStream.hpp"
31 #include "Shader.h"
32 #include "HashUtils.hpp"
33
34 namespace Diligent
35 {
36
37 class DiligentFXShaderSourceStreamFactory final : public IShaderSourceInputStreamFactory
38 {
39 public:
40 static DiligentFXShaderSourceStreamFactory& GetInstance();
41
42 virtual void CreateInputStream(const Char* Name, IFileStream** ppStream) override final;
43
44 virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final
45 {
46 UNSUPPORTED("This method is not implemented and should never be called");
47 }
48
49 virtual ReferenceCounterValueType AddRef() override final
50 {
51 UNSUPPORTED("This method is not implemented and should never be called");
52 return 0;
53 }
54
55 virtual ReferenceCounterValueType Release() override final
56 {
57 UNSUPPORTED("This method is not implemented and should never be called");
58 return 0;
59 }
60
61 virtual IReferenceCounters* GetReferenceCounters() const override final
62 {
63 UNSUPPORTED("This method is not implemented and should never be called");
64 return nullptr;
65 }
66
67 private:
68 DiligentFXShaderSourceStreamFactory();
69 std::unordered_map<HashMapStringKey, const Char*, HashMapStringKey::Hasher> m_NameToSourceMap;
70 };
71
72 } // namespace Diligent
0 /*
1 * Copyright 2019-2020 Diligent Graphics LLC
2 * Copyright 2015-2019 Egor Yusov
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * In no event and under no legal theory, whether in tort (including negligence),
17 * contract, or otherwise, unless required by applicable law (such as deliberate
18 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
19 * liable for any damages, including any direct, indirect, special, incidental,
20 * or consequential damages of any character arising as a result of this License or
21 * out of the use or inability to use the software (including but not limited to damages
22 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23 * all other commercial damages or losses), even if such Contributor has been advised
24 * of the possibility of such damages.
25 */
26
27 #pragma once
28
29 #include <unordered_map>
30 #include "BasicFileStream.hpp"
31 #include "Shader.h"
32 #include "HashUtils.hpp"
33
34 namespace Diligent
35 {
36
37 class DiligentFXShaderSourceStreamFactory final : public IShaderSourceInputStreamFactory
38 {
39 public:
40 static DiligentFXShaderSourceStreamFactory& GetInstance();
41
42 virtual void CreateInputStream(const Char* Name, IFileStream** ppStream) override final;
43
44 virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final
45 {
46 UNSUPPORTED("This method is not implemented and should never be called");
47 }
48
49 virtual ReferenceCounterValueType AddRef() override final
50 {
51 UNSUPPORTED("This method is not implemented and should never be called");
52 return 0;
53 }
54
55 virtual ReferenceCounterValueType Release() override final
56 {
57 UNSUPPORTED("This method is not implemented and should never be called");
58 return 0;
59 }
60
61 virtual IReferenceCounters* GetReferenceCounters() const override final
62 {
63 UNSUPPORTED("This method is not implemented and should never be called");
64 return nullptr;
65 }
66
67 private:
68 DiligentFXShaderSourceStreamFactory();
69 std::unordered_map<HashMapStringKey, const Char*, HashMapStringKey::Hasher> m_NameToSourceMap;
70 };
71
72 } // namespace Diligent
2424 * of the possibility of such damages.
2525 */
2626
27 #include "../include/DiligentFXShaderSourceStreamFactory.h"
27 #include "../include/DiligentFXShaderSourceStreamFactory.hpp"
2828 #include "MemoryFileStream.hpp"
2929 #include "StringDataBlobImpl.hpp"
3030 #include "RefCntAutoPtr.hpp"