UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ShadowSceneRenderer.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
7#include "Containers/Array.h"
8#include "Tasks/Task.h"
9#include "LightSceneInfo.h"
10#include "ShadowScene.h"
13
17class FRDGBuilder;
21
23{
24 class IShadowInvalidatingInstances;
25}
26
31{
32 enum Type : uint32
33 {
34 // Regular clipmap
36 // First-person (3rd person) shadow map,
38
39 Max
40 };
41}
42
47{
48public:
50
52
57
60 virtual void PreInitViews(FRDGBuilder& GraphBuilder) override;
61
72
77
82
84
88 bool HasVirtualShadowMap(FLightSceneInfo::FPersistentId LightId) const { return CommonSetups[LightId].bHasVirtualShadowMap; }
89
93 bool HasVirtualClipMap(FLightSceneInfo::FPersistentId LightId) const { return CommonSetups[LightId].bHasVirtualShadowMap && CommonSetups[LightId].bIsDirectional; }
94
98 FRDGBuilder& GraphBuilder,
102
105 void RenderVirtualShadowMaps(FRDGBuilder& GraphBuilder, bool bNaniteEnabled);
106
107 /* Does any one pass shadow projection and generates screen space shadow mask bits
108 * Call before beginning light loop/shadow projection, but after shadow map rendering
109 */
111 FRDGBuilder& GraphBuilder,
112 FMinimalSceneTextures& SceneTextures);
113
115 FRDGBuilder& GraphBuilder,
116 const FMinimalSceneTextures& SceneTextures,
118 const FViewInfo& View, int32 ViewIndex,
119 const FIntRect ScissorRect,
121 bool bModulateRGB,
124
125
130
136 FRDGBuilder& GraphBuilder,
137 const FMinimalSceneTextures& SceneTextures,
138 const FLightSceneInfo* LightSceneInfo,
141
142 // One pass projection stuff. Set up in RenderVitualShadowMapProjectionMaskBits
146
148 {
149 return VirtualShadowMapMaskBits != nullptr;
150 }
151
153 {
154 return RendererSetupTask;
155 }
156
158 {
159 return bNeedMegaLightsProjection;
160 }
161
163 {
164 return LocalLights.Num() > 0;
165 }
166
168 {
169 return NaniteVisibilityQuery != nullptr;
170 }
171
173
174 FVirtualShadowMapArray& GetVirtualShadowMapArray() { return VirtualShadowMapArray; }
175 const FVirtualShadowMapArray& GetVirtualShadowMapArray() const { return VirtualShadowMapArray; }
176
177private:
181
182 struct FViewData
183 {
184 float ClipToViewSizeScale = 0.0f;
185 float ClipToViewSizeBias = 0.0f;
186 };
187
188 // Generally only one pass, but we collect this to handle exceptional cases
189 struct FNaniteRenderPass
190 {
191 FSceneInstanceCullingQuery *SceneInstanceCullingQuery = nullptr;
193 uint32 TotalPrimaryViews = 0;
194 uint32 MaxNumMips = 0;
195 Nanite::FPackedViewArray* VirtualShadowMapViews = nullptr;
196 };
197
198 UE::Tasks::FTask RendererSetupTask;
199
200 FVirtualShadowMapProjectionShaderData GetLocalLightProjectionShaderData(
202 const FProjectedShadowInfo* ProjectedShadowInfo,
203 int32 MapIndex) const;
204
205 void UpdateLocalLightProjectionShaderDataMatrices(
206 const FProjectedShadowInfo* ProjectedShadowInfo,
207 int32 MapIndex,
209
210 void CreateNaniteRenderPasses(
211 FRDGBuilder& GraphBuilder,
214
215 static void CreateNaniteViewsForPass(
216 FRDGBuilder& GraphBuilder,
217 const FVirtualShadowMapArray& VirtualShadowMapArray,
221
222 void AllocateVirtualShadowMapIds();
223
224 struct FLightCommonFrameSetup
225 {
226 uint32 bHasVirtualShadowMap : 1;
227 uint32 bIsDirectional : 1;
228 // index into respective setup array, for a directional light this is the offset to the setup for the first view index
229 uint32 SetupIndex : 30;
230 };
231
232 // Indexed by light scene ID
234
235 struct FLocalLightShadowFrameSetup
236 {
238 // link to legacy system stuff, to be removed in due time
239 FProjectedShadowInfo* ProjectedShadowInfo = nullptr;
240 FLightSceneInfo* LightSceneInfo = nullptr;
241 };
242
243 // Indexed by order of allocation, represented in CommonSetups[LightId].SetupIndex
245
246 struct FDirectionalLightShadowFrameSetup
247 {
248 // Search key
250 // A clipmap may belong to more than one view (in stereo mode, specifically)
251 uint32 ViewMask = 0u;
252
253 FDirectionalLightShadowFrameSetup(FLightSceneInfo::FPersistentId InLightId, uint32 InViewMask)
254 : LightId(InLightId)
255 , ViewMask(InViewMask)
256 {
257 }
258
260 {
262 // for culling and other misc reasons.
264 };
265
266 // clipmaps, Indexed by the EVirtualShadowTypeId.
268 };
269
270 // Indexed by CommonSetups[LightId].SetupIndex + ViewIndex
272
273 FDirectionalLightShadowFrameSetup* FindDirectional(const FLightSceneInfo::FPersistentId LightId, int32 ViewIndex);
274
275 // Links to other systems etc.
276 FDeferredShadingSceneRenderer& SceneRenderer;
277 FScene& Scene;
278 FShadowScene& ShadowScene;
279 FVirtualShadowMapArray& VirtualShadowMapArray;
280
282
283 FNaniteVisibilityQuery* NaniteVisibilityQuery = nullptr;
285
286 // One pass projection stuff. Set up in RenderVitualShadowMapProjectionMaskBits
287 bool bShouldUseVirtualShadowMapOnePassProjection = false;
288
289 // Base the distant light cutoff on the minimum mip level instead of the shadow resolution calculated through the old path.
290 bool bUseConservativeDistantLightThreshold = false;
291 int32 DistantLightMode = 0;
292
293 // Tracking for a given frame/render of which passes we need - clear in BeginRender
294 bool bNeedVSMOnePassProjection = false;
295 bool bNeedMegaLightsProjection = false;
296
297 TArray<uint32, SceneRenderingAllocator> ExplicitChunkDrawInstanceIds;
298};
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
EVirtualShadowMapProjectionInputType
Definition VirtualShadowMapProjection.h:31
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition DeferredShadingRenderer.h:317
Definition LightSceneInfo.h:208
int32 FPersistentId
Definition LightSceneInfo.h:220
Definition ShadowRendering.h:279
Definition RenderGraphResources.h:1321
Definition RenderGraphBuilder.h:49
Definition RenderGraphResources.h:571
Definition SceneCullingRenderer.h:80
Definition SceneView.h:1425
Definition ScenePrivate.h:2875
Definition ShadowSceneRenderer.h:47
void BeginMarkVirtualShadowMapPages(FRDGBuilder &GraphBuilder, const FSingleLayerWaterPrePassResult *SingleLayerWaterPrePassResult, const FFrontLayerTranslucencyData &FrontLayerTranslucencyData, const Froxel::FRenderer &FroxelRenderer)
Definition ShadowSceneRenderer.cpp:895
bool HasVirtualShadowMap(FLightSceneInfo::FPersistentId LightId) const
Definition ShadowSceneRenderer.h:88
void PostSetupDebugRender()
Definition ShadowSceneRenderer.cpp:845
FRDGBufferRef HairTransmittanceMaskBits
Definition ShadowSceneRenderer.h:145
bool HasVirtualClipMap(FLightSceneInfo::FPersistentId LightId) const
Definition ShadowSceneRenderer.h:93
FRDGTextureRef VirtualShadowMapMaskBits
Definition ShadowSceneRenderer.h:143
virtual void PreInitViews(FRDGBuilder &GraphBuilder) override
Definition ShadowSceneRenderer.cpp:178
void ApplyVirtualShadowMapProjectionForLight(FRDGBuilder &GraphBuilder, const FMinimalSceneTextures &SceneTextures, const FLightSceneInfo *LightSceneInfo, const EVirtualShadowMapProjectionInputType InputType, FRDGTextureRef OutputScreenShadowMaskTexture)
Definition ShadowSceneRenderer.cpp:1043
void RenderVirtualShadowMapProjection(FRDGBuilder &GraphBuilder, const FMinimalSceneTextures &SceneTextures, FLightSceneInfo::FPersistentId LightId, const FViewInfo &View, int32 ViewIndex, const FIntRect ScissorRect, EVirtualShadowMapProjectionInputType InputType, bool bModulateRGB, FTiledVSMProjection *TiledVSMProjection, FRDGTextureRef OutputShadowMaskTexture)
Definition ShadowSceneRenderer.cpp:993
FVirtualShadowMapArray & GetVirtualShadowMapArray()
Definition ShadowSceneRenderer.h:174
const FVirtualShadowMapArray & GetVirtualShadowMapArray() const
Definition ShadowSceneRenderer.h:175
bool UsePackedShadowMaskBits() const
Definition ShadowSceneRenderer.h:147
static float ComputeNaniteShadowsLODScaleFactor()
Definition ShadowSceneRenderer.cpp:159
bool AreAnyLocalLightsPresent() const
Definition ShadowSceneRenderer.h:162
void RenderVirtualShadowMaps(FRDGBuilder &GraphBuilder, bool bNaniteEnabled)
Definition ShadowSceneRenderer.cpp:921
TSharedPtr< FVirtualShadowMapPerLightCacheEntry > AddLocalLightShadow(const FWholeSceneProjectedShadowInitializer &Initializer, FProjectedShadowInfo *ProjectedShadowInfo, FLightSceneInfo *LightSceneInfo, float MaxScreenRadius)
Definition ShadowSceneRenderer.cpp:357
void RenderVirtualShadowMapProjectionMaskBits(FRDGBuilder &GraphBuilder, FMinimalSceneTextures &SceneTextures)
Definition ShadowSceneRenderer.cpp:939
UE::Renderer::Private::IShadowInvalidatingInstances * GetInvalidatingInstancesInterface(const FSceneView *SceneView)
Definition ShadowSceneRenderer.cpp:279
void DispatchVirtualShadowMapViewAndCullingSetup(FRDGBuilder &GraphBuilder, TConstArrayView< FProjectedShadowInfo * > VirtualShadowMapShadows)
Definition ShadowSceneRenderer.cpp:826
DECLARE_SCENE_EXTENSION_RENDERER(FShadowSceneRenderer, FShadowScene)
void PostInitDynamicShadowsSetup()
Definition ShadowSceneRenderer.cpp:711
UE::Tasks::FTask GetRendererSetupTask() const
Definition ShadowSceneRenderer.h:152
FRDGTextureRef VirtualShadowMapMaskBitsHairStrands
Definition ShadowSceneRenderer.h:144
void AddDirectionalLightShadow(FLightSceneInfo &LightSceneInfo, FViewInfo &View, float MaxNonFarCascadeDistance, TArray< FProjectedShadowInfo *, SceneRenderingAllocator > &OutShadowInfosThatNeedCulling)
Definition ShadowSceneRenderer.cpp:537
TArray< int32, SceneRenderingAllocator > GatherClipmapIds(int32 ViewIndex) const
Definition ShadowSceneRenderer.cpp:1022
bool AreAnyLightsUsingMegaLightsVSM() const
Definition ShadowSceneRenderer.h:157
bool HasNaniteVisibilityQuery() const
Definition ShadowSceneRenderer.h:167
Definition ShadowScene.h:27
Definition SceneRendering.h:1132
Definition VirtualShadowMapArray.h:291
Definition VirtualShadowMapCacheManager.h:93
Definition SceneManagement.h:1047
Definition Froxel.h:69
Definition SceneExtensions.h:69
Definition NaniteShared.h:99
Definition Array.h:670
Definition SharedPointer.h:692
Definition StaticArray.h:26
Definition SceneRendererInterface.h:24
Definition ShadowSceneRenderer.h:31
Type
Definition ShadowSceneRenderer.h:33
@ Max
Definition ShadowSceneRenderer.h:39
@ Regular
Definition ShadowSceneRenderer.h:35
@ FirstPerson
Definition ShadowSceneRenderer.h:37
Definition SceneView.h:41
Definition LumenFrontLayerTranslucency.h:22
Definition SceneTextures.h:52
Definition VirtualShadowMapArray.h:48
Definition NaniteVisibility.cpp:54
FProjectedShadowInfo * ProjectedShadowInfo
Definition ShadowSceneRenderer.h:263
TSharedPtr< FVirtualShadowMapClipmap > Clipmap
Definition ShadowSceneRenderer.h:261
Definition SingleLayerWaterRendering.h:22
Definition VirtualShadowMapProjection.h:22
Definition VirtualShadowMapArray.h:100