UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LightGridInjection.cpp File Reference
#include "CoreMinimal.h"
#include "Stats/Stats.h"
#include "HAL/IConsoleManager.h"
#include "RHI.h"
#include "UniformBuffer.h"
#include "ShaderParameters.h"
#include "RendererInterface.h"
#include "EngineDefines.h"
#include "PrimitiveSceneProxy.h"
#include "Shader.h"
#include "SceneUtils.h"
#include "PostProcess/SceneRenderTargets.h"
#include "LightSceneInfo.h"
#include "RectLightSceneProxy.h"
#include "GlobalShader.h"
#include "SceneRendering.h"
#include "DeferredShadingRenderer.h"
#include "BasePassRendering.h"
#include "RendererModule.h"
#include "ScenePrivate.h"
#include "ClearQuad.h"
#include "VolumetricFog.h"
#include "VolumetricCloudRendering.h"
#include "Components/LightComponent.h"
#include "Engine/MapBuildDataRegistry.h"
#include "PixelShaderUtils.h"
#include "ShaderPrint.h"
#include "ShaderPrintParameters.h"
#include "RenderUtils.h"
#include "MegaLights/MegaLights.h"
#include "LightGridDefinitions.h"
#include "LightViewData.h"

Classes

class  FLightGridInjectionCS
 
struct  FLightGrid
 
class  FDebugLightGridPS
 
class  FLightGridFeedbackStatusCS
 
class  FLightGridFeedbackStatus
 

Typedefs

typedef uint16 FLightIndexType
 
typedef uint32 FLightIndexType32
 

Enumerations

enum class  ELightBufferMode { VisibleLocalLights = 0 , VisibleLights = 1 , VisibleLightsStableIndices = 2 }
 

Functions

FAutoConsoleVariableRef CVarLightGridPixelSize (TEXT("r.Forward.LightGridPixelSize"), GLightGridPixelSize, TEXT("Size of a cell in the light grid, in pixels."), ECVF_Scalability|ECVF_RenderThreadSafe)
 
FAutoConsoleVariableRef CVarLightGridSizeZ (TEXT("r.Forward.LightGridSizeZ"), GLightGridSizeZ, TEXT("Number of Z slices in the light grid."), ECVF_Scalability|ECVF_RenderThreadSafe)
 
FAutoConsoleVariableRef CVarLightGridHZBCull (TEXT("r.Forward.LightGridHZBCull"), GLightGridHZBCull, TEXT("Whether to use HZB culling to skip occluded grid cells."), ECVF_Scalability|ECVF_RenderThreadSafe)
 
FAutoConsoleVariableRef CVarMaxCulledLightsPerCell (TEXT("r.Forward.MaxCulledLightsPerCell"), GMaxCulledLightsPerCell, TEXT("Controls how much memory is allocated for each cell for light culling. When r.Forward.LightLinkedListCulling is enabled, this is used to compute a global max instead of a per-cell limit on culled lights."), ECVF_Scalability|ECVF_RenderThreadSafe)
 
FAutoConsoleVariableRef CVarLightLinkedListCulling (TEXT("r.Forward.LightLinkedListCulling"), GLightLinkedListCulling, TEXT("Uses a reverse linked list to store culled lights, removing the fixed limit on how many lights can affect a cell - it becomes a global limit instead."), ECVF_Scalability|ECVF_RenderThreadSafe)
 
 DECLARE_GPU_STAT (LightGrid)
 
void LightGridFeedbackStatus (FRDGBuilder &GraphBuilder, FViewInfo &View, FRDGBufferRef CulledLightDataAllocatorBuffer, uint32 NumCulledLightDataEntries, FRDGBufferRef CulledLightLinkAllocatorBuffer, uint32 NumCulledLightLinks, bool bUseAsyncCompute)
 
bool ShouldVisualizeLightGrid (EShaderPlatform InShaderPlatform)
 
bool LightGridUses16BitBuffers (EShaderPlatform Platform)
 
void SetupDummyForwardLightUniformParameters (FRDGBuilder &GraphBuilder, FForwardLightUniformParameters &ForwardLightUniformParameters, EShaderPlatform ShaderPlatform)
 
TRDGUniformBufferRef< FForwardLightUniformParametersCreateDummyForwardLightUniformBuffer (FRDGBuilder &GraphBuilder, EShaderPlatform ShaderPlatform)
 
void SetDummyForwardLightUniformBufferOnViews (FRDGBuilder &GraphBuilder, EShaderPlatform ShaderPlatform, TArray< FViewInfo > &Views)
 
 IMPLEMENT_GLOBAL_SHADER_PARAMETER_STRUCT (FForwardLightUniformParameters, "ForwardLightStruct")
 
 IMPLEMENT_GLOBAL_SHADER (FLightGridInjectionCS, "/Engine/Private/LightGridInjection.usf", "LightGridInjectionCS", SF_Compute)
 
FORCEINLINE float GetTanRadAngleOrZero (float coneAngle)
 
FVector GetLightGridZParams (float NearPlane, float FarPlane)
 
uint32 PackRG16 (float In0, float In1)
 
FLightGrid LightGridInjection (FRDGBuilder &GraphBuilder, FViewInfo &View, FIntVector GridSize, uint32 LightGridPixelSizeShift, uint32 ZSliceScale, uint32 MaxNumCells, FVector3f ZParams, uint32 LightGridCullMarginXY, uint32 LightGridCullMarginZ, FVector3f LightGridCullMarginZParams, uint32 LightGridCullMaxZ, uint32 NumLocalLights, uint32 NumReflectionCaptures, uint32 MegaLightsSupportedStartIndex, bool bUse16BitBuffers, bool bRefineRectLightBounds, FRDGBufferSRVRef LightViewSpacePositionAndRadiusSRV, FRDGBufferSRVRef LightViewSpaceDirAndPreprocAngleSRV, FRDGBufferSRVRef LightViewSpaceRectPlanesSRV, FRDGBufferSRVRef IndirectionIndicesSRV, bool bThreadGroupPerCell, bool bThreadGroupSize32, FRDGBufferSRVRef ParentNumCulledLightsGridSRV, FRDGBufferSRVRef ParentCulledLightDataGridSRV, uint32 ParentGridSizeFactor)
 
 IMPLEMENT_GLOBAL_SHADER (FDebugLightGridPS, "/Engine/Private/LightGridInjection.usf", "DebugLightGridPS", SF_Pixel)
 
FScreenPassTexture AddVisualizeLightGridPass (FRDGBuilder &GraphBuilder, const FViewInfo &View, FScreenPassTexture ScreenPassSceneColor, FScreenPassTexture SceneDepthTexture)
 
 IMPLEMENT_GLOBAL_SHADER (FLightGridFeedbackStatusCS, "/Engine/Private/LightGridInjection.usf", "FeedbackStatusCS", SF_Compute)
 

Variables

int32 GLightGridPixelSize = 64
 
int32 GLightGridSizeZ = 32
 
int32 GForwardLightGridDebug = 0
 
FAutoConsoleVariableRef CVarLightGridDebug (TEXT("r.Forward.LightGridDebug"), GForwardLightGridDebug, TEXT(" 3: on - showing max light count per tile accoung for each slice and the last one \n"), ECVF_RenderThreadSafe)
 
int32 GForwardLightGridDebugMaxThreshold = 8
 
FAutoConsoleVariableRef CVarLightGridDebugMaxThreshold (TEXT("r.Forward.LightGridDebug.MaxThreshold"), GForwardLightGridDebugMaxThreshold, TEXT("Maximum light threshold for heat map visualization. (default = 8)\n"), ECVF_RenderThreadSafe)
 
int32 GLightGridHZBCull = 1
 
int32 GLightGridRefineRectLightBounds = 1
 
FAutoConsoleVariableRef CVarLightGridRefineRectLightBounds (TEXT("r.Forward.LightGridDebug.RectLightBounds"), GLightGridRefineRectLightBounds, TEXT("Whether to refine rect light bounds (should only be disabled for debugging purposes)."), ECVF_RenderThreadSafe)
 
int32 GMaxCulledLightsPerCell = 32
 
int32 GLightLinkedListCulling = 1
 
int32 GLightCullingQuality = 1
 
FAutoConsoleVariableRef CVarLightCullingQuality (TEXT("r.LightCulling.Quality"), GLightCullingQuality, TEXT(" 1: on (default)\n"), ECVF_RenderThreadSafe)
 
float GLightCullingMaxDistanceOverrideKilometers = -1.0f
 
FAutoConsoleVariableRef CVarLightCullingMaxDistanceOverride (TEXT("r.LightCulling.MaxDistanceOverrideKilometers"), GLightCullingMaxDistanceOverrideKilometers, TEXT(" >0: the far distance in kilometers.\n"), ECVF_RenderThreadSafe)
 
int32 NumCulledLightsGridStride = 2
 
int32 NumCulledGridPrimitiveTypes = 2
 
int32 LightLinkStride = 2
 
TGlobalResource< FLightGridFeedbackStatusGLightGridFeedbackStatus
 

Typedef Documentation

◆ FLightIndexType

◆ FLightIndexType32

Enumeration Type Documentation

◆ ELightBufferMode

enum class ELightBufferMode
strong
Enumerator
VisibleLocalLights 
VisibleLights 
VisibleLightsStableIndices 

Function Documentation

◆ AddVisualizeLightGridPass()

FScreenPassTexture AddVisualizeLightGridPass ( FRDGBuilder GraphBuilder,
const FViewInfo View,
FScreenPassTexture  ScreenPassSceneColor,
FScreenPassTexture  SceneDepthTexture 
)

◆ CreateDummyForwardLightUniformBuffer()

TRDGUniformBufferRef< FForwardLightUniformParameters > CreateDummyForwardLightUniformBuffer ( FRDGBuilder GraphBuilder,
EShaderPlatform  ShaderPlatform 
)

◆ CVarLightGridHZBCull()

FAutoConsoleVariableRef CVarLightGridHZBCull ( TEXT("r.Forward.LightGridHZBCull")  ,
GLightGridHZBCull  ,
TEXT("Whether to use HZB culling to skip occluded grid cells." ,
ECVF_Scalability ECVF_RenderThreadSafe 
)

◆ CVarLightGridPixelSize()

FAutoConsoleVariableRef CVarLightGridPixelSize ( TEXT("r.Forward.LightGridPixelSize")  ,
GLightGridPixelSize  ,
TEXT("Size of a cell in the light grid, in pixels." ,
ECVF_Scalability ECVF_RenderThreadSafe 
)

◆ CVarLightGridSizeZ()

FAutoConsoleVariableRef CVarLightGridSizeZ ( TEXT("r.Forward.LightGridSizeZ")  ,
GLightGridSizeZ  ,
TEXT("Number of Z slices in the light grid." ,
ECVF_Scalability ECVF_RenderThreadSafe 
)

◆ CVarLightLinkedListCulling()

FAutoConsoleVariableRef CVarLightLinkedListCulling ( TEXT("r.Forward.LightLinkedListCulling")  ,
GLightLinkedListCulling  ,
TEXT("Uses a reverse linked list to store culled lights, removing the fixed limit on how many lights can affect a cell - it becomes a global limit instead." ,
ECVF_Scalability ECVF_RenderThreadSafe 
)

◆ CVarMaxCulledLightsPerCell()

FAutoConsoleVariableRef CVarMaxCulledLightsPerCell ( TEXT("r.Forward.MaxCulledLightsPerCell")  ,
GMaxCulledLightsPerCell  ,
TEXT("Controls how much memory is allocated for each cell for light culling. When r.Forward.LightLinkedListCulling is enabled, this is used to compute a global max instead of a per-cell limit on culled lights." ,
ECVF_Scalability ECVF_RenderThreadSafe 
)

◆ DECLARE_GPU_STAT()

DECLARE_GPU_STAT ( LightGrid  )

◆ GetLightGridZParams()

FVector GetLightGridZParams ( float  NearPlane,
float  FarPlane 
)

◆ GetTanRadAngleOrZero()

FORCEINLINE float GetTanRadAngleOrZero ( float  coneAngle)

◆ IMPLEMENT_GLOBAL_SHADER() [1/3]

IMPLEMENT_GLOBAL_SHADER ( FDebugLightGridPS  ,
"/Engine/Private/LightGridInjection.usf"  ,
"DebugLightGridPS"  ,
SF_Pixel   
)

◆ IMPLEMENT_GLOBAL_SHADER() [2/3]

IMPLEMENT_GLOBAL_SHADER ( FLightGridFeedbackStatusCS  ,
"/Engine/Private/LightGridInjection.usf"  ,
"FeedbackStatusCS"  ,
SF_Compute   
)

◆ IMPLEMENT_GLOBAL_SHADER() [3/3]

IMPLEMENT_GLOBAL_SHADER ( FLightGridInjectionCS  ,
"/Engine/Private/LightGridInjection.usf"  ,
"LightGridInjectionCS"  ,
SF_Compute   
)

◆ IMPLEMENT_GLOBAL_SHADER_PARAMETER_STRUCT()

IMPLEMENT_GLOBAL_SHADER_PARAMETER_STRUCT ( FForwardLightUniformParameters  ,
"ForwardLightStruct"   
)

◆ LightGridFeedbackStatus()

void LightGridFeedbackStatus ( FRDGBuilder GraphBuilder,
FViewInfo View,
FRDGBufferRef  CulledLightDataAllocatorBuffer,
uint32  NumCulledLightDataEntries,
FRDGBufferRef  CulledLightLinkAllocatorBuffer,
uint32  NumCulledLightLinks,
bool  bUseAsyncCompute 
)

◆ LightGridInjection()

FLightGrid LightGridInjection ( FRDGBuilder GraphBuilder,
FViewInfo View,
FIntVector  GridSize,
uint32  LightGridPixelSizeShift,
uint32  ZSliceScale,
uint32  MaxNumCells,
FVector3f  ZParams,
uint32  LightGridCullMarginXY,
uint32  LightGridCullMarginZ,
FVector3f  LightGridCullMarginZParams,
uint32  LightGridCullMaxZ,
uint32  NumLocalLights,
uint32  NumReflectionCaptures,
uint32  MegaLightsSupportedStartIndex,
bool  bUse16BitBuffers,
bool  bRefineRectLightBounds,
FRDGBufferSRVRef  LightViewSpacePositionAndRadiusSRV,
FRDGBufferSRVRef  LightViewSpaceDirAndPreprocAngleSRV,
FRDGBufferSRVRef  LightViewSpaceRectPlanesSRV,
FRDGBufferSRVRef  IndirectionIndicesSRV,
bool  bThreadGroupPerCell,
bool  bThreadGroupSize32,
FRDGBufferSRVRef  ParentNumCulledLightsGridSRV,
FRDGBufferSRVRef  ParentCulledLightDataGridSRV,
uint32  ParentGridSizeFactor 
)

◆ LightGridUses16BitBuffers()

bool LightGridUses16BitBuffers ( EShaderPlatform  Platform)

◆ PackRG16()

uint32 PackRG16 ( float  In0,
float  In1 
)

◆ SetDummyForwardLightUniformBufferOnViews()

void SetDummyForwardLightUniformBufferOnViews ( FRDGBuilder GraphBuilder,
EShaderPlatform  ShaderPlatform,
TArray< FViewInfo > &  Views 
)

◆ SetupDummyForwardLightUniformParameters()

void SetupDummyForwardLightUniformParameters ( FRDGBuilder GraphBuilder,
FForwardLightUniformParameters ForwardLightUniformParameters,
EShaderPlatform  ShaderPlatform 
)

◆ ShouldVisualizeLightGrid()

bool ShouldVisualizeLightGrid ( EShaderPlatform  InShaderPlatform)

Variable Documentation

◆ CVarLightCullingMaxDistanceOverride

FAutoConsoleVariableRef CVarLightCullingMaxDistanceOverride(TEXT("r.LightCulling.MaxDistanceOverrideKilometers"), GLightCullingMaxDistanceOverrideKilometers, TEXT(" >0: the far distance in kilometers.\n"), ECVF_RenderThreadSafe) ( TEXT("r.LightCulling.MaxDistanceOverrideKilometers")  ,
GLightCullingMaxDistanceOverrideKilometers  ,
TEXT(" >0: the far distance in kilometers.\n" ,
ECVF_RenderThreadSafe   
)

◆ CVarLightCullingQuality

FAutoConsoleVariableRef CVarLightCullingQuality(TEXT("r.LightCulling.Quality"), GLightCullingQuality, TEXT(" 1: on (default)\n"), ECVF_RenderThreadSafe) ( TEXT("r.LightCulling.Quality")  ,
GLightCullingQuality  ,
TEXT(" 1: on (default)\n" ,
ECVF_RenderThreadSafe   
)

◆ CVarLightGridDebug

FAutoConsoleVariableRef CVarLightGridDebug(TEXT("r.Forward.LightGridDebug"), GForwardLightGridDebug, TEXT(" 3: on - showing max light count per tile accoung for each slice and the last one \n"), ECVF_RenderThreadSafe) ( TEXT("r.Forward.LightGridDebug")  ,
GForwardLightGridDebug  ,
TEXT(" 3: on - showing max light count per tile accoung for each slice and the last one \n" ,
ECVF_RenderThreadSafe   
)

◆ CVarLightGridDebugMaxThreshold

FAutoConsoleVariableRef CVarLightGridDebugMaxThreshold(TEXT("r.Forward.LightGridDebug.MaxThreshold"), GForwardLightGridDebugMaxThreshold, TEXT("Maximum light threshold for heat map visualization. (default = 8)\n"), ECVF_RenderThreadSafe) ( TEXT("r.Forward.LightGridDebug.MaxThreshold")  ,
GForwardLightGridDebugMaxThreshold  ,
TEXT("Maximum light threshold for heat map visualization. (default = 8)\n" ,
ECVF_RenderThreadSafe   
)

◆ CVarLightGridRefineRectLightBounds

FAutoConsoleVariableRef CVarLightGridRefineRectLightBounds(TEXT("r.Forward.LightGridDebug.RectLightBounds"), GLightGridRefineRectLightBounds, TEXT("Whether to refine rect light bounds (should only be disabled for debugging purposes)."), ECVF_RenderThreadSafe) ( TEXT("r.Forward.LightGridDebug.RectLightBounds")  ,
GLightGridRefineRectLightBounds  ,
TEXT("Whether to refine rect light bounds (should only be disabled for debugging purposes).")  ,
ECVF_RenderThreadSafe   
)

◆ GForwardLightGridDebug

int32 GForwardLightGridDebug = 0

◆ GForwardLightGridDebugMaxThreshold

int32 GForwardLightGridDebugMaxThreshold = 8

◆ GLightCullingMaxDistanceOverrideKilometers

float GLightCullingMaxDistanceOverrideKilometers = -1.0f

◆ GLightCullingQuality

int32 GLightCullingQuality = 1

◆ GLightGridFeedbackStatus

TGlobalResource<FLightGridFeedbackStatus> GLightGridFeedbackStatus

◆ GLightGridHZBCull

int32 GLightGridHZBCull = 1

◆ GLightGridPixelSize

int32 GLightGridPixelSize = 64

◆ GLightGridRefineRectLightBounds

int32 GLightGridRefineRectLightBounds = 1

◆ GLightGridSizeZ

int32 GLightGridSizeZ = 32

◆ GLightLinkedListCulling

int32 GLightLinkedListCulling = 1

◆ GMaxCulledLightsPerCell

int32 GMaxCulledLightsPerCell = 32

◆ LightLinkStride

int32 LightLinkStride = 2

◆ NumCulledGridPrimitiveTypes

int32 NumCulledGridPrimitiveTypes = 2

◆ NumCulledLightsGridStride

int32 NumCulledLightsGridStride = 2