Merge pull request #7 from luzpaz/typos
Fix misc. typos
Assiduous authored 2 years ago
GitHub committed 2 years ago
95 | 95 | } |
96 | 96 | ``` |
97 | 97 | |
98 | When using filterable represenations, the shadow map must be post-processed before it can be used in a shader: | |
98 | When using filterable representations, the shadow map must be post-processed before it can be used in a shader: | |
99 | 99 | |
100 | 100 | ```cpp |
101 | 101 | if (m_ShadowSettings.iShadowMode > SHADOW_MODE_PCF) |
61 | 61 | /// Shadow mode (see SHADOW_MODE_* defines in BasicStructures.fxh), must not be 0. |
62 | 62 | int ShadowMode = 0; |
63 | 63 | |
64 | /// Wether to use 32-bit or 16-bit filterable textures | |
64 | /// Whether to use 32-bit or 16-bit filterable textures | |
65 | 65 | bool Is32BitFilterableFmt = false; |
66 | 66 | |
67 | 67 | /// Optional comparison sampler to be set in the shadow map resource view |
90 | 90 | /// Pointer to light direction, must not be null. |
91 | 91 | const float3* pLightDir = nullptr; |
92 | 92 | |
93 | /// Wether to snap cascades to texels in light view space | |
93 | /// Whether to snap cascades to texels in light view space | |
94 | 94 | bool SnapCascades = true; |
95 | 95 | |
96 | /// Wether to stabilize cascade extents in light view space | |
96 | /// Whether to stabilize cascade extents in light view space | |
97 | 97 | bool StabilizeExtents = true; |
98 | 98 | |
99 | /// Wether to use same extents for X and Y axis. Enabled automatically if StabilizeExtents == true | |
99 | /// Whether to use same extents for X and Y axis. Enabled automatically if StabilizeExtents == true | |
100 | 100 | bool EqualizeExtents = true; |
101 | 101 | |
102 | 102 | /// Cascade partitioning factor that defines the ratio between fully linear (0.0) and |
103 | 103 | /// fully logarithmic (1.0) partitioning. |
104 | 104 | float fPartitioningFactor = 0.95f; |
105 | 105 | |
106 | /// Wether to use right-handed or left-handed light view transform matrix | |
106 | /// Whether to use right-handed or left-handed light view transform matrix | |
107 | 107 | bool UseRightHandedLightViewTransform = true; |
108 | 108 | |
109 | 109 | /// Callback that allows the application to adjust z range of every cascade. |
5 | 5 | |
6 | 6 |  |
7 | 7 | |
8 | The renderer uses the refernce | |
8 | The renderer uses the reference | |
9 | 9 | [GLTF2.0 lighting model](https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-b-brdf-implementation). |
10 | 10 | |
11 | 11 | |[Khronos GLTF viewer][1]| Diligent Engine | |
51 | 51 | The renderer itself does not implement any loading functionality. Use |
52 | 52 | [Asset Loader](https://github.com/DiligentGraphics/DiligentTools/tree/master/AssetLoader) to load GLTF |
53 | 53 | models. When model is loaded, it is important to call `InitializeResourceBindings()` method |
54 | to let the renderer intiailize internal shader resource binding objects: | |
54 | to let the renderer initialize internal shader resource binding objects: | |
55 | 55 | |
56 | 56 | ```cpp |
57 | 57 | m_Model.reset(new GLTF::Model(m_pDevice, m_pImmediateContext, Path)); |
134 | 134 | { |
135 | 135 | CreateUniformBuffer(pDevice, sizeof(GLTFNodeShaderTransforms), "GLTF node transforms CB", &m_TransformsCB); |
136 | 136 | CreateUniformBuffer(pDevice, sizeof(GLTFMaterialShaderInfo) + sizeof(GLTFRendererShaderParameters), "GLTF attribs CB", &m_GLTFAttribsCB); |
137 | CreateUniformBuffer(pDevice, static_cast<Uint32>(sizeof(float4x4) * m_Settings.MaxJointCount), "GLTF joint tranforms", &m_JointsBuffer); | |
137 | CreateUniformBuffer(pDevice, static_cast<Uint32>(sizeof(float4x4) * m_Settings.MaxJointCount), "GLTF joint transforms", &m_JointsBuffer); | |
138 | 138 | |
139 | 139 | // clang-format off |
140 | 140 | StateTransitionDesc Barriers[] = |
977 | 977 | GLTFRendererShaderParameters RenderParameters; |
978 | 978 | GLTF::Material::ShaderAttribs MaterialInfo; |
979 | 979 | static_assert(sizeof(GLTFMaterialShaderInfo) == sizeof(GLTF::Material::ShaderAttribs), |
980 | "The sizeof(GLTFMaterialShaderInfo) is incosistent with sizeof(GLTF::Material::ShaderAttribs)"); | |
980 | "The sizeof(GLTFMaterialShaderInfo) is inconsistent with sizeof(GLTF::Material::ShaderAttribs)"); | |
981 | 981 | }; |
982 | 982 | static_assert(sizeof(GLTFAttribs) <= 256, "Size of dynamic GLTFAttribs buffer exceeds 256 bytes. " |
983 | 983 | "It may be worth trying to reduce the size or just live with it."); |
27 | 27 | produce more samples and higher quality, but at a higher performance cost. |
28 | 28 | * bShowSampling - Whether to show epipolar sampling. |
29 | 29 | * bCorrectScatteringAtDepthBreaks - Whether to correct inscattering at depth discontinuities. Improves quality |
30 | for additional cost. It may be preferrable to increase the number of slices | |
30 | for additional cost. It may be preferable to increase the number of slices | |
31 | 31 | and or maximum number of samples on an epipolar line instead. |
32 | 32 | * bShowDepthBreaks - Whether to display pixels which are classified as depth discontinuities and which |
33 | 33 | will be corrected. Only has effect when bCorrectScatteringAtDepthBreaks is TRUE. |
34 | 34 | * bShowLightingOnly - Whether to show lighting only |
35 | 35 | * bOptimizeSampleLocations - Optimize sample locations to avoid oversampling. This should generally be TRUE. |
36 | * bEnableLightShafts - Wether to enable light shafts or render unshadowed inscattering. | |
36 | * bEnableLightShafts - Whether to enable light shafts or render unshadowed inscattering. | |
37 | 37 | Setting this to FALSE increases performance, but reduces visual quality. |
38 | 38 | * uiInstrIntegralSteps - Number of inscattering integral steps taken when computing unshadowed inscattering |
39 | 39 | Default value is OK and should not be changed. |
67 | 67 | * uiExtinctionEvalMode - Atmospheric extinction evaluation mode. |
68 | 68 | * bUseCustomSctrCoeffs - Whether to use custom scattering coefficients. |
69 | 69 | * fAerosolDensityScale - Aerosol density scale to use for scattering coefficient computation. |
70 | * fAerosolAbsorbtionScale - Aerosol absorbtion scale to use for scattering coefficient computation. | |
70 | * fAerosolAbsorbtionScale - Aerosol absorption scale to use for scattering coefficient computation. | |
71 | 71 | * f4CustomRlghBeta - Custom Rayleigh coefficients. |
72 | 72 | * f4CustomMieBeta - Custom Mie coefficients. |
73 | 73 | |
80 | 80 | * Light and color attributes |
81 | 81 | |
82 | 82 | The code snippet below shows how to use the epipolar light scattering post-processing effect. |
83 | For the full soure code, see [Atmospheric scattering sample](https://github.com/DiligentGraphics/DiligentSamples/tree/master/Samples/Atmosphere). | |
83 | For the full source code, see [Atmospheric scattering sample](https://github.com/DiligentGraphics/DiligentSamples/tree/master/Samples/Atmosphere). | |
84 | 84 | |
85 | 85 | ```cpp |
86 | 86 | EpipolarLightScattering::FrameAttribs FrameAttribs; |
57 | 57 | // Pixel shader discards pixels that should not be further processed, thus keeping the |
58 | 58 | // stencil value untouched. |
59 | 59 | // For instance, pixel shader performing epipolar coordinates generation discards all |
60 | // sampes, whoose coordinates are outside the screen [-1,1]x[-1,1] area. | |
60 | // sampes, whose coordinates are outside the screen [-1,1]x[-1,1] area. | |
61 | 61 | static const DepthStencilStateDesc DSS_IncStencilAlways |
62 | 62 | { |
63 | 63 | False, // DepthEnable |
85 | 85 | |
86 | 86 | // Disable depth testing, stencil testing function equal, increment stencil. |
87 | 87 | // This state is used to process only those pixels that were marked at the previous pass. |
88 | // All pixels whith different stencil value are discarded from further processing as well | |
88 | // All pixels with different stencil value are discarded from further processing as well | |
89 | 89 | // as some pixels can also be discarded during the draw call. |
90 | 90 | // For instance, pixel shader marking ray marching samples processes only those pixels which are inside |
91 | 91 | // the screen. It also discards all but those samples that are interpolated from themselves. |
902 | 902 | auto* tex2DAverageLuminanceSRV = tex2DAverageLuminance->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE); |
903 | 903 | m_ptex2DAverageLuminanceRTV = tex2DAverageLuminance->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET); |
904 | 904 | tex2DAverageLuminanceSRV->SetSampler(m_pLinearClampSampler); |
905 | // Set intial luminance to 1 | |
905 | // Set initial luminance to 1 | |
906 | 906 | ITextureView* pRTVs[] = {m_ptex2DAverageLuminanceRTV}; |
907 | 907 | pDeviceCtx->SetRenderTargets(1, pRTVs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); |
908 | 908 | pDeviceCtx->ClearRenderTarget(m_ptex2DAverageLuminanceRTV, TexDesc.ClearValue.Color, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); |
1747 | 1747 | UnwarpAndRenderLuminanceTech.SRBDependencyFlags = SRBDependencies; |
1748 | 1748 | } |
1749 | 1749 | |
1750 | // Unwarp inscattering image and apply it to attenuated backgorund | |
1750 | // Unwarp inscattering image and apply it to attenuated background | |
1751 | 1751 | if (bRenderLuminance) |
1752 | 1752 | { |
1753 | 1753 | UnwarpAndRenderLuminanceTech.PrepareSRB(m_FrameAttribs.pDevice, m_pResMapping, BIND_SHADER_RESOURCES_KEEP_EXISTING); |
38 | 38 | and you agree that the content is free of any Intellectual Property claims and you have the right to license it under those terms. |
39 | 39 | |
40 | 40 | Diligent Engine uses [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to ensure |
41 | consistent source code style throught the code base. The format is validated by appveyor and travis | |
41 | consistent source code style throughout the code base. The format is validated by appveyor and travis | |
42 | 42 | for each commit and pull request, and the build will fail if any code formatting issue is found. Please refer |
43 | 43 | to [this page](https://github.com/DiligentGraphics/DiligentCore/blob/master/doc/code_formatting.md) for instructions |
44 | 44 | on how to set up clang-format and automatic code formatting. |
190 | 190 | fDistToRayEnd = max(fDistToRayEnd, f2RayAtmTopIsecs.x); |
191 | 191 | |
192 | 192 | // To properly compute scattering from the space, we must |
193 | // set up ray end position before extiting the loop | |
193 | // set up ray end position before exiting the loop | |
194 | 194 | f3RayEnd = f3CameraPos + f3ViewDir * fDistToRayEnd; |
195 | 195 | f3RayStart = f3CameraPos + f3ViewDir * fDistToRayStart; |
196 | 196 | |
266 | 266 | } |
267 | 267 | #endif |
268 | 268 | |
269 | // Calcualte ray step length in world space | |
269 | // Calculate ray step length in world space | |
270 | 270 | float fRayStepLengthWS = fRayLength * (fShadowMapUVStepLen / fTraceLenInShadowMapUVSpace); |
271 | 271 | // Note that fTraceLenInShadowMapUVSpace can be very small when looking directly at sun |
272 | 272 | // Since fShadowMapUVStepLen is at least one shadow map texel in size, |
78 | 78 | if( bIsValidThread ) |
79 | 79 | { |
80 | 80 | #if REFINEMENT_CRITERION == REFINEMENT_CRITERION_DEPTH_DIFF |
81 | // Load camera space Z for this sample and for its right neighbour (remeber to use global sample index) | |
81 | // Load camera space Z for this sample and for its right neighbour (remember to use global sample index) | |
82 | 82 | float fCamSpaceZ = g_tex2DEpipolarCamSpaceZ.Load( int3(uiGlobalSampleInd, uiSliceInd, 0) ); |
83 | 83 | float fRightNeighbCamSpaceZ = g_tex2DEpipolarCamSpaceZ.Load( int3( int(uiGlobalSampleInd)+1, uiSliceInd, 0) ); |
84 | 84 | float fMaxZ = max(fCamSpaceZ, fRightNeighbCamSpaceZ); |
94 | 94 | // Compute minimum inscattering threshold based on the average scene luminance |
95 | 95 | float fAverageLum = GetAverageSceneLuminance(g_tex2DAverageLuminance); |
96 | 96 | // Inscattering threshold should be proportional to the average scene luminance and |
97 | // inversely proportional to the middle gray level (the higher middle gray, the briter the scene, | |
98 | // thus the less the theshold) | |
97 | // inversely proportional to the middle gray level (the higher middle gray, the brighter the scene, | |
98 | // thus the less the threshold) | |
99 | 99 | // It should also account for the fact that rgb channels contribute differently |
100 | // to the percieved brightness. For r channel the threshold should be smallest, | |
100 | // to the perceived brightness. For r channel the threshold should be smallest, | |
101 | 101 | // for b channel - the largest |
102 | 102 | float3 f3MinInsctrThreshold = (0.02 * fAverageLum / RGB_TO_LUMINANCE.xyz) / g_PPAttribs.ToneMapping.fMiddleGray; |
103 | 103 | |
142 | 142 | } |
143 | 143 | uint uiInitialSample1Ind = uiInitialSample0Ind + uiInitialSampleStep; |
144 | 144 | |
145 | // Remeber that the last sample in each epipolar slice must be ray marching one | |
145 | // Remember that the last sample in each epipolar slice must be ray marching one | |
146 | 146 | uint uiInterpolationTexWidth, uiInterpolationTexHeight; |
147 | 147 | g_rwtex2DInterpolationSource.GetDimensions(uiInterpolationTexWidth, uiInterpolationTexHeight); |
148 | 148 | if( Gid.x == uiInterpolationTexWidth/uint(THREAD_GROUP_SIZE) - 1u ) |
52 | 52 | float4 f4Boundaries = GetOutermostScreenPixelCoords(g_PPAttribs.f4ScreenResolution); |
53 | 53 | bool4 b4IsCorrectIntersectionFlag = Greater( abs(f2RayDir.xyxy), 1e-5 * float4(1.0, 1.0, 1.0, 1.0) ); |
54 | 54 | float4 f4DistToBoundaries = (f4Boundaries - g_PPAttribs.f4LightScreenPos.xyxy) / (f2RayDir.xyxy + BoolToFloat( Not(b4IsCorrectIntersectionFlag) ) ); |
55 | // Addition of !b4IsCorrectIntersectionFlag is required to prevent divison by zero | |
55 | // Addition of !b4IsCorrectIntersectionFlag is required to prevent division by zero | |
56 | 56 | // Note that such incorrect lanes will be masked out anyway |
57 | 57 | |
58 | 58 | // We now need to find first intersection BEFORE the intersection with the exit boundary |
134 | 134 | |
135 | 135 | // Note that in fact the outermost visible screen pixels do not lie exactly on the boundary (+1 or -1), but are biased by |
136 | 136 | // 0.5 screen pixel size inwards. Using these adjusted boundaries improves precision and results in |
137 | // samller number of pixels which require inscattering correction | |
137 | // smaller number of pixels which require inscattering correction | |
138 | 138 | float4 f4OutermostScreenPixelCoords = GetOutermostScreenPixelCoords(g_PPAttribs.f4ScreenResolution);// xyzw = (left, bottom, right, top) |
139 | 139 | |
140 | 140 | // Check if there can definitely be no correct intersection with the boundary: |
+2
-2
127 | 127 | BOOL bShowLightingOnly DEFAULT_VALUE(FALSE); |
128 | 128 | // Optimize sample locations to avoid oversampling. This should generally be TRUE. |
129 | 129 | BOOL bOptimizeSampleLocations DEFAULT_VALUE(TRUE); |
130 | // Wether to enable light shafts or render unshadowed inscattering. | |
130 | // Whether to enable light shafts or render unshadowed inscattering. | |
131 | 131 | // Setting this to FALSE increases performance, but reduces visual quality. |
132 | 132 | BOOL bEnableLightShafts DEFAULT_VALUE(TRUE); |
133 | 133 | // Number of inscattering integral steps taken when computing unshadowed inscattering (default is OK). |
181 | 181 | BOOL bUseCustomSctrCoeffs DEFAULT_VALUE(FALSE); |
182 | 182 | // Aerosol density scale to use for scattering coefficient computation. |
183 | 183 | float fAerosolDensityScale DEFAULT_VALUE(1.f); |
184 | // Aerosol absorbtion scale to use for scattering coefficient computation. | |
184 | // Aerosol absorption scale to use for scattering coefficient computation. | |
185 | 185 | float fAerosolAbsorbtionScale DEFAULT_VALUE(0.1f); |
186 | 186 | |
187 | 187 | // Custom Rayleigh coefficients. |
127 | 127 | " BOOL bShowLightingOnly DEFAULT_VALUE(FALSE);\n" |
128 | 128 | " // Optimize sample locations to avoid oversampling. This should generally be TRUE.\n" |
129 | 129 | " BOOL bOptimizeSampleLocations DEFAULT_VALUE(TRUE);\n" |
130 | " // Wether to enable light shafts or render unshadowed inscattering.\n" | |
130 | " // Whether to enable light shafts or render unshadowed inscattering.\n" | |
131 | 131 | " // Setting this to FALSE increases performance, but reduces visual quality.\n" |
132 | 132 | " BOOL bEnableLightShafts DEFAULT_VALUE(TRUE);\n" |
133 | 133 | " // Number of inscattering integral steps taken when computing unshadowed inscattering (default is OK).\n" |
181 | 181 | " BOOL bUseCustomSctrCoeffs DEFAULT_VALUE(FALSE);\n" |
182 | 182 | " // Aerosol density scale to use for scattering coefficient computation.\n" |
183 | 183 | " float fAerosolDensityScale DEFAULT_VALUE(1.f);\n" |
184 | " // Aerosol absorbtion scale to use for scattering coefficient computation.\n" | |
184 | " // Aerosol absorption scale to use for scattering coefficient computation.\n" | |
185 | 185 | " float fAerosolAbsorbtionScale DEFAULT_VALUE(0.1f);\n" |
186 | 186 | "\n" |
187 | 187 | " // Custom Rayleigh coefficients.\n" |
190 | 190 | " fDistToRayEnd = max(fDistToRayEnd, f2RayAtmTopIsecs.x);\n" |
191 | 191 | " \n" |
192 | 192 | " // To properly compute scattering from the space, we must \n" |
193 | " // set up ray end position before extiting the loop\n" | |
193 | " // set up ray end position before exiting the loop\n" | |
194 | 194 | " f3RayEnd = f3CameraPos + f3ViewDir * fDistToRayEnd;\n" |
195 | 195 | " f3RayStart = f3CameraPos + f3ViewDir * fDistToRayStart;\n" |
196 | 196 | "\n" |
266 | 266 | " }\n" |
267 | 267 | " #endif\n" |
268 | 268 | "\n" |
269 | " // Calcualte ray step length in world space\n" | |
269 | " // Calculate ray step length in world space\n" | |
270 | 270 | " float fRayStepLengthWS = fRayLength * (fShadowMapUVStepLen / fTraceLenInShadowMapUVSpace);\n" |
271 | 271 | " // Note that fTraceLenInShadowMapUVSpace can be very small when looking directly at sun\n" |
272 | 272 | " // Since fShadowMapUVStepLen is at least one shadow map texel in size, \n" |
78 | 78 | " if( bIsValidThread )\n" |
79 | 79 | " {\n" |
80 | 80 | "#if REFINEMENT_CRITERION == REFINEMENT_CRITERION_DEPTH_DIFF\n" |
81 | " // Load camera space Z for this sample and for its right neighbour (remeber to use global sample index)\n" | |
81 | " // Load camera space Z for this sample and for its right neighbour (remember to use global sample index)\n" | |
82 | 82 | " float fCamSpaceZ = g_tex2DEpipolarCamSpaceZ.Load( int3(uiGlobalSampleInd, uiSliceInd, 0) );\n" |
83 | 83 | " float fRightNeighbCamSpaceZ = g_tex2DEpipolarCamSpaceZ.Load( int3( int(uiGlobalSampleInd)+1, uiSliceInd, 0) );\n" |
84 | 84 | " float fMaxZ = max(fCamSpaceZ, fRightNeighbCamSpaceZ);\n" |
94 | 94 | " // Compute minimum inscattering threshold based on the average scene luminance\n" |
95 | 95 | " float fAverageLum = GetAverageSceneLuminance(g_tex2DAverageLuminance);\n" |
96 | 96 | " // Inscattering threshold should be proportional to the average scene luminance and\n" |
97 | " // inversely proportional to the middle gray level (the higher middle gray, the briter the scene,\n" | |
98 | " // thus the less the theshold)\n" | |
97 | " // inversely proportional to the middle gray level (the higher middle gray, the brighter the scene,\n" | |
98 | " // thus the less the threshold)\n" | |
99 | 99 | " // It should also account for the fact that rgb channels contribute differently\n" |
100 | " // to the percieved brightness. For r channel the threshold should be smallest, \n" | |
100 | " // to the perceived brightness. For r channel the threshold should be smallest, \n" | |
101 | 101 | " // for b channel - the largest\n" |
102 | 102 | " float3 f3MinInsctrThreshold = (0.02 * fAverageLum / RGB_TO_LUMINANCE.xyz) / g_PPAttribs.ToneMapping.fMiddleGray;\n" |
103 | 103 | "\n" |
142 | 142 | " }\n" |
143 | 143 | " uint uiInitialSample1Ind = uiInitialSample0Ind + uiInitialSampleStep;\n" |
144 | 144 | "\n" |
145 | " // Remeber that the last sample in each epipolar slice must be ray marching one\n" | |
145 | " // Remember that the last sample in each epipolar slice must be ray marching one\n" | |
146 | 146 | " uint uiInterpolationTexWidth, uiInterpolationTexHeight;\n" |
147 | 147 | " g_rwtex2DInterpolationSource.GetDimensions(uiInterpolationTexWidth, uiInterpolationTexHeight);\n" |
148 | 148 | " if( Gid.x == uiInterpolationTexWidth/uint(THREAD_GROUP_SIZE) - 1u )\n" |
52 | 52 | " float4 f4Boundaries = GetOutermostScreenPixelCoords(g_PPAttribs.f4ScreenResolution);\n" |
53 | 53 | " bool4 b4IsCorrectIntersectionFlag = Greater( abs(f2RayDir.xyxy), 1e-5 * float4(1.0, 1.0, 1.0, 1.0) );\n" |
54 | 54 | " float4 f4DistToBoundaries = (f4Boundaries - g_PPAttribs.f4LightScreenPos.xyxy) / (f2RayDir.xyxy + BoolToFloat( Not(b4IsCorrectIntersectionFlag) ) );\n" |
55 | " // Addition of !b4IsCorrectIntersectionFlag is required to prevent divison by zero\n" | |
55 | " // Addition of !b4IsCorrectIntersectionFlag is required to prevent division by zero\n" | |
56 | 56 | " // Note that such incorrect lanes will be masked out anyway\n" |
57 | 57 | "\n" |
58 | 58 | " // We now need to find first intersection BEFORE the intersection with the exit boundary\n" |
134 | 134 | "\n" |
135 | 135 | " // Note that in fact the outermost visible screen pixels do not lie exactly on the boundary (+1 or -1), but are biased by\n" |
136 | 136 | " // 0.5 screen pixel size inwards. Using these adjusted boundaries improves precision and results in\n" |
137 | " // samller number of pixels which require inscattering correction\n" | |
137 | " // smaller number of pixels which require inscattering correction\n" | |
138 | 138 | " float4 f4OutermostScreenPixelCoords = GetOutermostScreenPixelCoords(g_PPAttribs.f4ScreenResolution);// xyzw = (left, bottom, right, top)\n" |
139 | 139 | "\n" |
140 | 140 | " // Check if there can definitely be no correct intersection with the boundary:\n" |