MCPcopy Create free account
hub / github.com/NVIDIA-RTX/Donut / SetupDynamicDirectionalLightView

Method SetupDynamicDirectionalLightView

src/render/PlanarShadowMap.cpp:113–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113bool PlanarShadowMap::SetupDynamicDirectionalLightView(const DirectionalLight& light, float3 anchor, float3 halfShadowBoxSize, float3 preViewTranslation, float fadeRangeWorld)
114{
115 daffine3 viewToWorld = light.GetNode()->GetLocalToWorldTransform();
116 // Zero the translation component to ignore where the actual light scene node is located, we only care about direction
117 viewToWorld.m_translation = dm::double3(0.0);
118 viewToWorld = dm::scaling(dm::double3(1.0, 1.0, -1.0)) * viewToWorld;
119 affine3 worldToView = affine3(inverse(viewToWorld));
120
121 // Snap the anchor to the texel grid to avoid jitter
122 float2 texelSize = float2(2.f) * halfShadowBoxSize.xy() / m_ShadowMapSize;
123
124 float3 anchorView = worldToView.transformPoint(anchor - preViewTranslation);
125 anchorView.xy() = float2(round(anchorView.xy() / texelSize)) * texelSize; // why doesn't it compile without float2(...) ?
126 float3 center = float3(viewToWorld.transformPoint(double3(anchorView))) + preViewTranslation;
127
128 // Make sure we didn't move the anchor too far
129 assert(length(center - anchor) < max(texelSize.x, texelSize.y) * 2);
130
131 worldToView = translation(-center) * worldToView;
132
133 // Build the projection matrix
134 float4x4 projection = orthoProjD3DStyle(
135 -halfShadowBoxSize.x, halfShadowBoxSize.x,
136 -halfShadowBoxSize.y, halfShadowBoxSize.y,
137 -halfShadowBoxSize.z, halfShadowBoxSize.z);
138
139 bool viewIsModified = m_View->GetViewMatrix() != worldToView || any(m_View->GetProjectionMatrix(false) != projection);
140
141 m_View->SetMatrices(worldToView, projection);
142 m_View->UpdateCache();
143
144 m_FadeRangeTexels = clamp(
145 float2(fadeRangeWorld * m_ShadowMapSize) / (halfShadowBoxSize.xy() * 2.f),
146 float2(1.f),
147 m_ShadowMapSize * 0.5f);
148
149 return viewIsModified;
150}
151
152void PlanarShadowMap::SetupProxyView()
153{

Callers 3

SetupForPlanarViewMethod · 0.80
SetupForCubemapViewMethod · 0.80

Calls 14

scalingFunction · 0.85
lengthFunction · 0.85
translationFunction · 0.85
orthoProjD3DStyleFunction · 0.85
clampFunction · 0.85
GetNodeMethod · 0.80
SetMatricesMethod · 0.80
UpdateCacheMethod · 0.80
inverseFunction · 0.50
roundFunction · 0.50
maxFunction · 0.50
transformPointMethod · 0.45

Tested by

no test coverage detected