UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MegaLightsInternal.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "RendererPrivate.h"
7#include "BlueNoise.h"
8#include "MegaLightsDefinitions.h"
9
15 SHADER_PARAMETER_RDG_UNIFORM_BUFFER(FSceneUniformParameters, Scene)
31 SHADER_PARAMETER(FIntPoint, DownsampleFactor)
38 SHADER_PARAMETER(int32, DebugMode)
48 SHADER_PARAMETER(FIntPoint, VisibleLightHashViewMinInTiles)
49 SHADER_PARAMETER(FIntPoint, VisibleLightHashViewSizeInTiles)
50 SHADER_PARAMETER_RDG_TEXTURE(Texture2D<float>, DownsampledSceneDepth)
51 SHADER_PARAMETER_RDG_TEXTURE(Texture2D<UNORM float3>, DownsampledSceneWorldNormal)
53
63 SHADER_PARAMETER(FIntVector, VolumeViewSize)
80
82{
83 GBuffer,
85 Count
86};
87
88// Internal functions, don't use outside of the MegaLights
89namespace MegaLights
90{
92 const FSceneViewFamily& ViewFamily,
93 const FViewInfo& View, int32 ViewIndex,
94 FRDGBuilder& GraphBuilder,
95 const FSceneTextures& SceneTextures,
96 const FVirtualShadowMapArray* VirtualShadowMapArray,
98 const FIntPoint SampleBufferSize,
99 FRDGTextureRef LightSamples,
100 FRDGTextureRef LightSampleRays,
101 FIntVector VolumeSampleBufferSize,
102 FRDGTextureRef VolumeLightSamples,
103 FRDGTextureRef VolumeLightSampleRays,
104 FIntVector TranslucencyVolumeSampleBufferSize,
105 TArrayView<FRDGTextureRef> TranslucencyVolumeLightSamples,
106 TArrayView<FRDGTextureRef> TranslucencyVolumeLightSampleRays,
107 const FMegaLightsParameters& MegaLightsParameters,
108 const FMegaLightsVolumeParameters& MegaLightsVolumeParameters,
109 const FMegaLightsVolumeParameters& MegaLightsTranslucencyVolumeParameters,
110 EMegaLightsInput InputType,
111 bool bDebug
112 );
113
114 void MarkVSMPages(
115 const FViewInfo& View, int32 ViewIndex,
116 FRDGBuilder& GraphBuilder,
117 const FVirtualShadowMapArray& VirtualShadowMapArray,
118 const FIntPoint SampleBufferSize,
119 FRDGTextureRef LightSamples,
120 FRDGTextureRef LightSampleRays,
121 const FMegaLightsParameters& MegaLightsParameters,
122 EMegaLightsInput InputType);
123
124 bool UseWaveOps(EShaderPlatform ShaderPlatform);
126
129
133
135
136 bool UseSpatialFilter();
137 bool UseTemporalFilter();
138
140
141 // Keep in sync with TILE_TYPE_* in shaders
166
167 bool IsRectLightTileType(ETileType TileType);
168 bool IsTexturedLightTileType(ETileType TileType);
169 bool IsComplexTileType(ETileType TileType);
171 const TCHAR* GetTileTypeString(ETileType TileType);
172};
173
174namespace MegaLightsVolume
175{
177 bool UsesLightFunction();
178};
179
181{
183 bool UsesLightFunction();
184};
185
191 SHADER_PARAMETER(FVector3f, GridZParams)
196
198{
199public:
202 const int32 InViewIndex,
203 const FViewInfo& InView,
205 const FScene* InScene,
207 bool bInUseVSM)
208 : GraphBuilder(InGraphBuilder)
209 , ViewIndex(InViewIndex)
210 , View(InView)
211 , ViewFamily(InViewFamily)
212 , Scene(InScene)
213 , SceneTextures(InSceneTextures)
214 , bUseVSM(bInUseVSM)
215 {
216 }
217
218 FRDGTextureRef TileClassificationMark(uint32 ShadingPassIndex);
219
220 void Setup(
221 FRDGTextureRef LightingChannelsTexture,
222 const FLumenSceneFrameTemporaries& LumenFrameTemporaries,
227
228 void GenerateSamples(
229 FRDGTextureRef LightingChannelsTexture,
231
232 void MarkVSMPages(
233 const FVirtualShadowMapArray& VirtualShadowMapArray);
234
235 void RayTrace(
236 const FVirtualShadowMapArray& VirtualShadowMapArray,
239
240 void Resolve(
244
245 void DenoiseLighting(FRDGTextureRef OutputColorTarget);
246
248 {
249 return bSamplesGenerated;
250 }
251
252 uint32 GetReferenceShadingPassCount() const { return ReferenceShadingPassCount; }
253
254private:
255 FRDGBuilder& GraphBuilder;
256 const int32 ViewIndex;
257 const FViewInfo& View;
258 const FSceneViewFamily& ViewFamily;
259 const FScene* Scene;
260 const FSceneTextures& SceneTextures;
261 const bool bUseVSM;
262
263 bool bSamplesGenerated = false;
264
265 EMegaLightsInput InputType;
266
267 bool bUnifiedVolume;
268 bool bVolumeEnabled;
269 bool bGuideByHistory = true;
270 bool bGuideAreaLightsByHistory = true;
271 bool bVolumeGuideByHistory;
272 bool bTranslucencyVolumeGuideByHistory;
273 bool bDebug;
274 bool bVolumeDebug;
275 bool bTranslucencyVolumeDebug;
276 bool bUseLightFunctionAtlas;
277 bool bSpatial;
278 bool bTemporal;
279 bool bSubPixelShading;
280 bool bShouldRenderVolumetricFog;
281 bool bShouldRenderTranslucencyVolume;
282
283 int32 DebugTileClassificationMode = 0;
284 int32 VisualizeLightLoopIterationsMode = 0;
285
286 FMegaLightsParameters MegaLightsParameters;
287 FMegaLightsVolumeParameters MegaLightsVolumeParameters;
288 FMegaLightsVolumeParameters MegaLightsTranslucencyVolumeParameters;
289
290 FMegaLightsVolumeData VolumeParameters;
291 FVolumetricFogGlobalData VolumetricFogParamaters;
292
293 FIntPoint DownsampleFactor;
294 FIntPoint SampleBufferSize;
295 FIntPoint DonwnsampledSampleBufferSize;
296
297 FIntPoint NumSamplesPerPixel2d;
298 FIntVector NumSamplesPerVoxel3d;
299 FIntVector NumSamplesPerTranslucencyVoxel3d;
300
301 FIntPoint ViewSizeInTiles;
302
303 uint32 VisibleLightHashBufferSize;
304 FIntPoint VisibleLightHashSizeInTiles;
305 FIntPoint VisibleLightHashViewMinInTiles;
306 FIntPoint VisibleLightHashViewSizeInTiles;
307
308 uint32 VolumeDownsampleFactor;
309 FIntVector VolumeBufferSize;
310 FIntVector VolumeSampleBufferSize;
311 FIntVector VolumeViewSize;
312
313 FRDGTextureRef VolumeLightSamples = nullptr;
314 FRDGTextureRef VolumeLightSampleRays = nullptr;
315
316 uint32 VolumeVisibleLightHashBufferSize;
317 FIntVector VolumeVisibleLightHashTileSize;
318 FIntVector VolumeVisibleLightHashSizeInTiles;
319 FIntVector VolumeVisibleLightHashViewSizeInTiles;
320 FIntVector VolumeDownsampledViewSize;
321
322 uint32 TranslucencyVolumeDownsampleFactor;
323 FIntVector TranslucencyVolumeBufferSize;
324 FIntVector TranslucencyVolumeSampleBufferSize;
325 FIntVector TranslucencyVolumeDownsampledBufferSize;
326
327 TArray<FRDGTextureRef, TInlineAllocator<TVC_MAX>> TranslucencyVolumeLightSamples;
328 TArray<FRDGTextureRef, TInlineAllocator<TVC_MAX>> TranslucencyVolumeLightSampleRays;
329
330 uint32 TranslucencyVolumeVisibleLightHashBufferSize;
331 FIntVector TranslucencyVolumeVisibleLightHashTileSize;
332 FIntVector TranslucencyVolumeVisibleLightHashSizeInTiles;
333
334 FRDGTextureRef SceneDepth = nullptr;
335 FRDGTextureRef SceneWorldNormal = nullptr;
336 FRDGTextureRef DownsampledSceneDepth = nullptr;
337 FRDGTextureRef DownsampledSceneWorldNormal = nullptr;
338
339 FRDGBufferRef TileIndirectArgs = nullptr;
340 FRDGBufferRef TileAllocator = nullptr;
341 FRDGBufferRef TileData = nullptr;
342 FRDGBufferRef DownsampledTileIndirectArgs = nullptr;
343 FRDGBufferRef DownsampledTileAllocator = nullptr;
344 FRDGBufferRef DownsampledTileData = nullptr;
345
346 FRDGTextureRef LightSamples = nullptr;
347 FRDGTextureRef LightSampleRays = nullptr;
348
349 TArray<int32> ShadingTileTypes;
350
351 FVector4f HistoryScreenPositionScaleBias = FVector4f(0.0f, 0.0f, 0.0f, 0.0f);
352 FVector4f HistoryUVMinMax = FVector4f(0.0f, 0.0f, 0.0f, 0.0f);
353 FVector4f HistoryGatherUVMinMax = FVector4f(0.0f, 0.0f, 0.0f, 0.0f);
354 FVector4f HistoryBufferSizeAndInvSize = FVector4f(0.0f, 0.0f, 0.0f, 0.0f);
355 FIntPoint HistoryVisibleLightHashViewMinInTiles = 0;
356 FIntPoint HistoryVisibleLightHashViewSizeInTiles = 0;
357 FRDGTextureRef DiffuseLightingHistory = nullptr;
358 FRDGTextureRef SpecularLightingHistory = nullptr;
359 FRDGTextureRef LightingMomentsHistory = nullptr;
360 FRDGTextureRef SceneDepthHistory = nullptr;
361 FRDGTextureRef SceneNormalAndShadingHistory = nullptr;
362 FRDGTextureRef NumFramesAccumulatedHistory = nullptr;
363 FRDGBufferRef VisibleLightHashHistory = nullptr;
364 FRDGBufferRef VisibleLightMaskHashHistory = nullptr;
365
366 FRDGTextureRef EncodedReprojectionVector = nullptr;
367 FRDGTextureRef PackedPixelData = nullptr;
368
369 FIntVector HistoryVolumeVisibleLightHashViewSizeInTiles = FIntVector::ZeroValue;
370 FRDGBufferRef VolumeVisibleLightHashHistory = nullptr;
371
372 FIntVector HistoryTranslucencyVolumeVisibleLightHashSizeInTiles = FIntVector::ZeroValue;
373 FRDGBufferRef TranslucencyVolumeVisibleLightHashHistory[TVC_MAX] = {};
374
375 // State for the shading loop; much of this gets lazily created in the loop
376 // This should perhaps be moved to a separate context structure in the future
377 uint32 ReferenceShadingPassCount;
378 bool bReferenceMode;
379 uint32 FirstPassStateFrameIndex;
380 EPixelFormat AccumulatedRGBLightingDataFormat;
381 EPixelFormat AccumulatedRGBALightingDataFormat;
382 EPixelFormat AccumulatedConfidenceDataFormat;
383
384 FRDGTextureRef ResolvedDiffuseLighting = nullptr;
385 FRDGTextureRef ResolvedSpecularLighting = nullptr;
386 FRDGTextureRef ShadingConfidence = nullptr;
387 FRDGTextureRef VolumeResolvedLighting = nullptr;
388 FRDGBufferRef VisibleLightHash = nullptr;
389 FRDGBufferRef VisibleLightMaskHash = nullptr;
390 FRDGBufferRef VolumeVisibleLightHash = nullptr;
391 FRDGTextureRef TranslucencyVolumeResolvedLightingAmbient[TVC_MAX] = {};
392 FRDGTextureRef TranslucencyVolumeResolvedLightingDirectional[TVC_MAX] = {};
393 FRDGBufferRef TranslucencyVolumeVisibleLightHash[TVC_MAX] = {};
394};
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
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
UE::Math::TVector4< float > FVector4f
Definition MathFwd.h:75
EMegaLightsInput
Definition MegaLightsInternal.h:82
EPixelFormat
Definition PixelFormat.h:16
EShaderPlatform
Definition RHIShaderPlatform.h:11
@ TVC_MAX
Definition SceneView.h:839
#define SHADER_PARAMETER_RDG_TEXTURE(ShaderType, MemberName)
Definition ShaderParameterMacros.h:1752
#define SHADER_PARAMETER_TEXTURE(ShaderType, MemberName)
Definition ShaderParameterMacros.h:1708
#define SHADER_PARAMETER_SAMPLER(ShaderType, MemberName)
Definition ShaderParameterMacros.h:1740
#define BEGIN_SHADER_PARAMETER_STRUCT(StructTypeName, DllStorage)
Definition ShaderParameterMacros.h:1482
#define SHADER_PARAMETER_STRUCT_REF(StructType, MemberName)
Definition ShaderParameterMacros.h:1909
#define SHADER_PARAMETER_STRUCT_INCLUDE(StructType, MemberName)
Definition ShaderParameterMacros.h:1895
#define SHADER_PARAMETER_RDG_UNIFORM_BUFFER(StructType, MemberName)
Definition ShaderParameterMacros.h:1823
#define END_SHADER_PARAMETER_STRUCT()
Definition ShaderParameterMacros.h:1485
#define SHADER_PARAMETER(MemberType, MemberName)
Definition ShaderParameterMacros.h:1684
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition MegaLightsInternal.h:198
bool AreSamplesGenerated()
Definition MegaLightsInternal.h:247
uint32 GetReferenceShadingPassCount() const
Definition MegaLightsInternal.h:252
FMegaLightsViewContext(FRDGBuilder &InGraphBuilder, const int32 InViewIndex, const FViewInfo &InView, const FSceneViewFamily &InViewFamily, const FScene *InScene, const FSceneTextures &InSceneTextures, bool bInUseVSM)
Definition MegaLightsInternal.h:200
Definition MegaLights.h:28
Definition RenderGraphResources.h:1321
Definition RenderGraphBuilder.h:49
Definition RenderGraphResources.h:571
Definition SceneView.h:2212
Definition ScenePrivate.h:2875
Definition SceneRendering.h:1132
Definition VirtualShadowMapArray.h:291
Definition ArrayView.h:139
Definition Array.h:670
Definition ShaderParameterMacros.h:136
Definition HairStrandsData.h:476
Definition LightFunctionAtlas.cpp:122
Definition MegaLights.cpp:903
int32 GetDebugMode()
Definition MegaLights.cpp:927
bool UsesLightFunction()
Definition MegaLights.cpp:922
Definition MegaLights.cpp:871
bool UsesLightFunction()
Definition MegaLights.cpp:891
int32 GetDebugMode()
Definition MegaLights.cpp:896
Definition MegaLights.cpp:462
void RayTraceLightSamples(const FSceneViewFamily &ViewFamily, const FViewInfo &View, int32 ViewIndex, FRDGBuilder &GraphBuilder, const FSceneTextures &SceneTextures, const FVirtualShadowMapArray *VirtualShadowMapArray, const TArrayView< FRDGTextureRef > NaniteShadingMasks, const FIntPoint SampleBufferSize, FRDGTextureRef LightSamples, FRDGTextureRef LightSampleRays, FIntVector VolumeSampleBufferSize, FRDGTextureRef VolumeLightSamples, FRDGTextureRef VolumeLightSampleRays, FIntVector TranslucencyVolumeSampleBufferSize, TArrayView< FRDGTextureRef > TranslucencyVolumeLightSamples, TArrayView< FRDGTextureRef > TranslucencyVolumeLightSampleRays, const FMegaLightsParameters &MegaLightsParameters, const FMegaLightsVolumeParameters &MegaLightsVolumeParameters, const FMegaLightsVolumeParameters &MegaLightsTranslucencyVolumeParameters, EMegaLightsInput InputType, bool bDebug)
Definition MegaLightsRayTracing.cpp:1428
bool IsComplexTileType(ETileType TileType)
Definition MegaLights.cpp:822
TArray< int32 > GetShadingTileTypes(EMegaLightsInput InputType)
Definition MegaLights.cpp:832
bool UseTemporalFilter()
Definition MegaLightsDenoising.cpp:85
bool SupportsSpatialFilter(EMegaLightsInput InputType)
Definition MegaLights.cpp:751
bool IsDebugEnabledForShadingPass(int32 ShadingPassIndex, EShaderPlatform InPlatform)
Definition MegaLights.cpp:737
bool UseSpatialFilter()
Definition MegaLightsDenoising.cpp:80
bool IsRectLightTileType(ETileType TileType)
Definition MegaLights.cpp:801
void MarkVSMPages(const FViewInfo &View, int32 ViewIndex, FRDGBuilder &GraphBuilder, const FVirtualShadowMapArray &VirtualShadowMapArray, const FIntPoint SampleBufferSize, FRDGTextureRef LightSamples, FRDGTextureRef LightSampleRays, const FMegaLightsParameters &MegaLightsParameters, EMegaLightsInput InputType)
Definition MegaLightsRayTracing.cpp:1384
int32 GetDebugMode(EMegaLightsInput InputType)
Definition MegaLights.cpp:720
FIntPoint GetNumSamplesPerPixel2d(int32 NumSamplesPerPixel1d)
Definition MegaLights.cpp:677
EPixelFormat GetLightingDataFormat()
Definition MegaLights.cpp:499
ETileType
Definition MegaLightsInternal.h:143
FIntVector GetNumSamplesPerVoxel3d(int32 NumSamplesPerVoxel1d)
Definition MegaLights.cpp:703
const TCHAR * GetTileTypeString(ETileType TileType)
Definition MegaLights.cpp:775
void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment &OutEnvironment)
Definition MegaLights.cpp:768
bool UseWaveOps(EShaderPlatform ShaderPlatform)
Definition MegaLights.cpp:761
bool IsTexturedLightTileType(ETileType TileType)
Definition MegaLights.cpp:814
Definition ShaderPrint.cpp:22
Definition RenderUtils.cpp:2080
Definition LumenSceneData.h:895
Definition SceneTextures.h:110
Definition ShaderCore.h:544
Definition IntPoint.h:25
static const TIntVector3 ZeroValue
Definition IntVector.h:45