Files
UnrealEngineUWP/Engine/Source/Runtime/Renderer/Private/DeferredShadingRenderer.h
charles derousiers 61d2cdf491 Convert Standard deferred lights shader to use FParameters shader parameters and native RDG resources.
#rb none
#jira none
#preflight 61b285734111d88202f94c0e

#ROBOMERGE-AUTHOR: charles.derousiers
#ROBOMERGE-SOURCE: CL 18429384 in //UE5/Release-5.0/... via CL 18429385
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v897-18405271)

[CL 18429387 by charles derousiers in ue5-release-engine-test branch]
2021-12-10 03:43:29 -05:00

971 lines
40 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
/*=============================================================================
DeferredShadingRenderer.h: Scene rendering definitions.
=============================================================================*/
#pragma once
#include "CoreMinimal.h"
#include "Stats/Stats.h"
#include "RendererInterface.h"
#include "StaticBoundShaderState.h"
#include "ScenePrivateBase.h"
#include "LightSceneInfo.h"
#include "SceneRendering.h"
#include "DepthRendering.h"
#include "TranslucentRendering.h"
#include "ScreenSpaceDenoise.h"
#include "Lumen/LumenProbeHierarchy.h"
#include "Lumen/LumenSceneRendering.h"
#include "IndirectLightRendering.h"
#include "ScreenSpaceRayTracing.h"
#include "RenderGraphUtils.h"
enum class ERayTracingPrimaryRaysFlag : uint32;
class FLumenCardUpdateContext;
class FSceneTextureParameters;
class FDistanceFieldCulledObjectBufferParameters;
class FTileIntersectionParameters;
class FDistanceFieldAOParameters;
class UStaticMeshComponent;
class FExponentialHeightFogSceneInfo;
class FRaytracingLightDataPacked;
class FLumenCardScatterContext;
namespace LumenRadianceCache
{
class FRadianceCacheInputs;
class FRadianceCacheInterpolationParameters;
}
class FRenderLightParameters;
struct FSceneWithoutWaterTextures;
struct FRayTracingReflectionOptions;
struct FHairStrandsTransmittanceMaskData;
struct FVolumetricFogLocalLightFunctionInfo;
struct FTranslucencyLightingVolumeTextures;
/**
* Data for rendering meshes into Lumen Lighting Cards.
*/
class FLumenCardRenderer
{
public:
TArray<FCardPageRenderData, SceneRenderingAllocator> CardPagesToRender;
TArray<const FPrimitiveSceneInfo*, SceneRenderingAllocator> LandscapePrimitivesInRange;
int32 NumCardTexelsToCapture;
FMeshCommandOneFrameArray MeshDrawCommands;
TArray<int32, SceneRenderingAllocator> MeshDrawPrimitiveIds;
void Reset()
{
CardPagesToRender.Reset();
MeshDrawCommands.Reset();
MeshDrawPrimitiveIds.Reset();
NumCardTexelsToCapture = 0;
}
};
/** Encapsulation of the pipeline state of the renderer that have to deal with very large number of dimensions
* and make sure there is no cycle dependencies in the dimensions by setting them ordered by memory offset in the structure.
*/
template<typename PermutationVectorType>
class TPipelineState
{
public:
TPipelineState()
{
FPlatformMemory::Memset(&Vector, 0, sizeof(Vector));
}
/** Set a member of the pipeline state committed yet. */
template<typename DimensionType>
void Set(DimensionType PermutationVectorType::*Dimension, const DimensionType& DimensionValue)
{
SIZE_T ByteOffset = GetByteOffset(Dimension);
// Make sure not updating a value of the pipeline already initialized, to ensure there is no cycle in the dependency of the different dimensions.
checkf(ByteOffset >= InitializedOffset, TEXT("This member of the pipeline state has already been committed."));
Vector.*Dimension = DimensionValue;
// Update the initialised offset to make sure this is not set only once.
InitializedOffset = ByteOffset + sizeof(DimensionType);
}
/** Commit the pipeline state to its final immutable value. */
void Commit()
{
// Force the pipeline state to be initialized exactly once.
checkf(!IsCommitted(), TEXT("Pipeline state has already been committed."));
InitializedOffset = ~SIZE_T(0);
}
/** Returns whether the pipeline state has been fully committed to its final immutable value. */
bool IsCommitted() const
{
return InitializedOffset == ~SIZE_T(0);
}
/** Access a member of the pipeline state, even when the pipeline state hasn't been fully committed to it's final value yet. */
template<typename DimensionType>
const DimensionType& operator [](DimensionType PermutationVectorType::*Dimension) const
{
SIZE_T ByteOffset = GetByteOffset(Dimension);
checkf(ByteOffset < InitializedOffset, TEXT("This dimension has not been initialized yet."));
return Vector.*Dimension;
}
/** Access the fully committed pipeline state structure. */
const PermutationVectorType* operator->() const
{
// Make sure the pipeline state is committed to catch accesses to uninitialized settings.
checkf(IsCommitted(), TEXT("The pipeline state needs to be fully commited before being able to reference directly the pipeline state structure."));
return &Vector;
}
/** Access the fully committed pipeline state structure. */
const PermutationVectorType& operator * () const
{
// Make sure the pipeline state is committed to catch accesses to uninitialized settings.
checkf(IsCommitted(), TEXT("The pipeline state needs to be fully commited before being able to reference directly the pipeline state structure."));
return Vector;
}
private:
template<typename DimensionType>
static SIZE_T GetByteOffset(DimensionType PermutationVectorType::*Dimension)
{
return (SIZE_T)(&(((PermutationVectorType*) 0)->*Dimension));
}
PermutationVectorType Vector;
SIZE_T InitializedOffset = 0;
};
/**
* Scene renderer that implements a deferred shading pipeline and associated features.
*/
class FDeferredShadingSceneRenderer : public FSceneRenderer
{
public:
/** Defines which objects we want to render in the EarlyZPass. */
FDepthPassInfo DepthPass;
FLumenCardRenderer LumenCardRenderer;
FDeferredShadingSceneRenderer(const FSceneViewFamily* InViewFamily,FHitProxyConsumer* HitProxyConsumer);
/** Determine and commit the final state of the pipeline for the view family and views. */
void CommitFinalPipelineState();
/** Commit all the pipeline state for indirect ligthing. */
void CommitIndirectLightingState();
/** Clears a view */
void ClearView(FRHICommandListImmediate& RHICmdList);
/**
* Renders the scene's prepass for a particular view
* @return true if anything was rendered
*/
void RenderPrePassView(FRHICommandList& RHICmdList, const FViewInfo& View);
/**
* Renders the scene's prepass for a particular view in parallel
* @return true if the depth was cleared
*/
bool RenderPrePassViewParallel(const FViewInfo& View, FRHICommandListImmediate& ParentCmdList,TFunctionRef<void()> AfterTasksAreStarted, bool bDoPrePre);
/**
* Culls local lights and reflection probes to a grid in frustum space, builds one light list and grid per view in the current Views.
* Needed for forward shading or translucency using the Surface lighting mode, and clustered deferred shading.
*/
void GatherLightsAndComputeLightGrid(FRDGBuilder& GraphBuilder, bool bNeedLightGrid, FSortedLightSetSceneInfo &SortedLightSet);
void RenderBasePass(
FRDGBuilder& GraphBuilder,
FSceneTextures& SceneTextures,
const FDBufferTextures& DBufferTextures,
FExclusiveDepthStencil::Type BasePassDepthStencilAccess,
FRDGTextureRef ForwardShadowMaskTexture,
FInstanceCullingManager& InstanceCullingManager,
bool bNaniteEnabled,
const TArrayView<Nanite::FRasterResults>& NaniteRasterResults);
void RenderBasePassInternal(
FRDGBuilder& GraphBuilder,
const FSceneTextures& SceneTextures,
const FRenderTargetBindingSlots& BasePassRenderTargets,
FExclusiveDepthStencil::Type BasePassDepthStencilAccess,
const FForwardBasePassTextures& ForwardBasePassTextures,
const FDBufferTextures& DBufferTextures,
bool bParallelBasePass,
bool bRenderLightmapDensity,
FInstanceCullingManager& InstanceCullingManager,
bool bNaniteEnabled,
const TArrayView<Nanite::FRasterResults>& NaniteRasterResults);
void RenderAnisotropyPass(
FRDGBuilder& GraphBuilder,
FSceneTextures& SceneTextures,
bool bDoParallelPass);
void RenderSingleLayerWater(
FRDGBuilder& GraphBuilder,
const FSceneTextures& SceneTextures,
bool bShouldRenderVolumetricCloud,
FSceneWithoutWaterTextures& SceneWithoutWaterTextures);
void RenderSingleLayerWaterInner(
FRDGBuilder& GraphBuilder,
const FSceneTextures& SceneTextures,
const FSceneWithoutWaterTextures& SceneWithoutWaterTextures);
void RenderSingleLayerWaterReflections(
FRDGBuilder& GraphBuilder,
const FSceneTextures& SceneTextures,
const FSceneWithoutWaterTextures& SceneWithoutWaterTextures);
void RenderOcclusion(
FRDGBuilder& GraphBuilder,
const FSceneTextures& SceneTextures,
bool bIsOcclusionTesting);
bool RenderHzb(FRDGBuilder& GraphBuilder, FRDGTextureRef SceneDepthTexture);
/** Renders the view family. */
virtual void Render(FRDGBuilder& GraphBuilder) override;
/** Render the view family's hit proxies. */
virtual void RenderHitProxies(FRDGBuilder& GraphBuilder) override;
virtual bool ShouldRenderVelocities() const override;
virtual bool ShouldRenderPrePass() const override;
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
void RenderVisualizeTexturePool(FRHICommandListImmediate& RHICmdList);
#endif
private:
enum class EDiffuseIndirectMethod
{
Disabled,
SSGI,
RTGI,
Lumen,
};
enum class EAmbientOcclusionMethod
{
Disabled,
SSAO,
SSGI, // SSGI can produce AO buffer at same time to correctly comp SSGI within the other indirect light such as skylight and lightmass.
RTAO,
};
enum class EReflectionsMethod
{
Disabled,
SSR,
RTR,
Lumen
};
/** Structure that contains the final state of deferred shading pipeline for a FViewInfo */
struct FPerViewPipelineState
{
EDiffuseIndirectMethod DiffuseIndirectMethod;
IScreenSpaceDenoiser::EMode DiffuseIndirectDenoiser;
// Whether all indirect lighting should denoise using prove hierarchy denoiser.
bool bUseLumenProbeHierarchy;
// Method to use for ambient occlusion.
EAmbientOcclusionMethod AmbientOcclusionMethod;
// Method to use for reflections.
EReflectionsMethod ReflectionsMethod;
// Whether there is planar reflection to compose to the reflection.
bool bComposePlanarReflections;
// Whether need to generate HZB from the depth buffer.
bool bFurthestHZB;
bool bClosestHZB;
};
// Structure that contains the final state of deferred shading pipeline for the FSceneViewFamily
struct FFamilyPipelineState
{
// Whether Nanite is enabled.
bool bNanite;
// Whether the scene occlusion is made using HZB.
bool bHZBOcclusion;
};
/** Pipeline states that describe the high level topology of the entire renderer.
*
* Once initialized by CommitFinalPipelineState(), it becomes immutable for the rest of the execution of the renderer.
*/
TArray<TPipelineState<FPerViewPipelineState>, TInlineAllocator<1>> ViewPipelineStates;
TPipelineState<FFamilyPipelineState> FamilyPipelineState;
FORCEINLINE const FPerViewPipelineState& GetViewPipelineState(const FViewInfo& View) const
{
int32 ViewIndex = 0;
bool bFound = ViewFamily.Views.Find(&View, ViewIndex);
check(bFound);
return *ViewPipelineStates[ViewIndex];
}
virtual bool IsLumenEnabled(const FViewInfo& View) const override
{
return (GetViewPipelineState(View).DiffuseIndirectMethod == EDiffuseIndirectMethod::Lumen || GetViewPipelineState(View).ReflectionsMethod == EReflectionsMethod::Lumen);
}
virtual bool AnyViewHasGIMethodSupportingDFAO() const override
{
bool bAnyViewHasGIMethodSupportingDFAO = false;
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
{
if (GetViewPipelineState(Views[ViewIndex]).DiffuseIndirectMethod != EDiffuseIndirectMethod::Lumen)
{
bAnyViewHasGIMethodSupportingDFAO = true;
}
}
return bAnyViewHasGIMethodSupportingDFAO;
}
static FGraphEventRef TranslucencyTimestampQuerySubmittedFence[FOcclusionQueryHelpers::MaxBufferedOcclusionFrames + 1];
static FGlobalDynamicIndexBuffer DynamicIndexBufferForInitViews;
static FGlobalDynamicIndexBuffer DynamicIndexBufferForInitShadows;
static FGlobalDynamicVertexBuffer DynamicVertexBufferForInitViews;
static FGlobalDynamicVertexBuffer DynamicVertexBufferForInitShadows;
static TGlobalResource<FGlobalDynamicReadBuffer> DynamicReadBufferForInitViews;
static TGlobalResource<FGlobalDynamicReadBuffer> DynamicReadBufferForInitShadows;
FSeparateTranslucencyDimensions SeparateTranslucencyDimensions;
/** Creates a per object projected shadow for the given interaction. */
void CreatePerObjectProjectedShadow(
FRHICommandListImmediate& RHICmdList,
FLightPrimitiveInteraction* Interaction,
bool bCreateTranslucentObjectShadow,
bool bCreateInsetObjectShadow,
const TArray<FProjectedShadowInfo*, SceneRenderingAllocator>& ViewDependentWholeSceneShadows,
TArray<FProjectedShadowInfo*, SceneRenderingAllocator>& OutPreShadows);
void PreVisibilityFrameSetup(FRDGBuilder& GraphBuilder, const FSceneTexturesConfig& SceneTexturesConfig);
/** Determines which primitives are visible for each view. */
void InitViews(FRDGBuilder& GraphBuilder, const FSceneTexturesConfig& SceneTexturesConfig, FExclusiveDepthStencil::Type BasePassDepthStencilAccess, struct FILCUpdatePrimTaskData& ILCTaskData, FInstanceCullingManager& InstanceCullingManager);
void InitViewsBeforePrepass(FRDGBuilder& GraphBuilder, FInstanceCullingManager& InstanceCullingManager);
void InitViewsAfterPrepass(FRDGBuilder& GraphBuilder, struct FILCUpdatePrimTaskData& ILCTaskData, FInstanceCullingManager& InstanceCullingManager);
void BeginUpdateLumenSceneTasks(FRDGBuilder& GraphBuilder);
void UpdateLumenScene(FRDGBuilder& GraphBuilder);
void RenderLumenSceneLighting(FRDGBuilder& GraphBuilder, FViewInfo& View, FLumenSceneFrameTemporaries& FrameTemporaries);
void RenderDirectLightingForLumenScene(
FRDGBuilder& GraphBuilder,
const class FLumenCardTracingInputs& TracingInputs,
FGlobalShaderMap* GlobalShaderMap,
const FLumenCardUpdateContext& CardUpdateContext);
void RenderRadiosityForLumenScene(
FRDGBuilder& GraphBuilder,
const class FLumenCardTracingInputs& TracingInputs,
FGlobalShaderMap* GlobalShaderMap,
FRDGTextureRef RadiosityAtlas,
const FLumenCardUpdateContext& CardUpdateContext);
void ClearLumenSurfaceCacheAtlas(
FRDGBuilder& GraphBuilder,
const FViewInfo& View);
void UpdateLumenSurfaceCacheAtlas(
FRDGBuilder& GraphBuilder,
const FViewInfo& View,
const TArray<FCardPageRenderData, SceneRenderingAllocator>& CardPagesToRender,
FRDGBufferSRVRef CardCaptureRectBufferSRV,
const struct FCardCaptureAtlas& CardCaptureAtlas);
void ComputeLumenSceneVoxelLighting(FRDGBuilder& GraphBuilder, FLumenCardTracingInputs& TracingInputs, FGlobalShaderMap* GlobalShaderMap);
void ComputeLumenTranslucencyGIVolume(FRDGBuilder& GraphBuilder, FLumenCardTracingInputs& TracingInputs, FGlobalShaderMap* GlobalShaderMap);
void CreateIndirectCapsuleShadows();
void RenderPrePass(FRDGBuilder& GraphBuilder, FRDGTextureRef SceneDepthTexture, FInstanceCullingManager& InstanceCullingManager);
void RenderPrePassHMD(FRDGBuilder& GraphBuilder, FRDGTextureRef SceneDepthTexture);
void RenderFog(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
FRDGTextureRef LightShaftOcclusionTexture);
void RenderUnderWaterFog(
FRDGBuilder& GraphBuilder,
const FSceneWithoutWaterTextures& SceneWithoutWaterTextures,
TRDGUniformBufferRef<FSceneTextureUniformParameters> SceneTexturesWithDepth);
void RenderAtmosphere(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
FRDGTextureRef LightShaftOcclusionTexture);
// TODO: Address tech debt to that directly in RenderDiffuseIndirectAndAmbientOcclusion()
void SetupCommonDiffuseIndirectParameters(
FRDGBuilder& GraphBuilder,
const FSceneTextureParameters& SceneTextures,
const FViewInfo& View,
HybridIndirectLighting::FCommonParameters& OutCommonDiffuseParameters);
/** Render diffuse indirect (regardless of the method) of the views into the scene color. */
FSSDSignalTextures RenderLumenProbeHierarchy(
FRDGBuilder& GraphBuilder,
const FSceneTextures& SceneTextures,
FLumenSceneFrameTemporaries& FrameTemporaries,
const HybridIndirectLighting::FCommonParameters& CommonParameters,
const ScreenSpaceRayTracing::FPrevSceneColorMip& PrevSceneColor,
const FViewInfo& View,
FPreviousViewInfo* PreviousViewInfos);
/** Render diffuse indirect (regardless of the method) of the views into the scene color. */
void RenderDiffuseIndirectAndAmbientOcclusion(
FRDGBuilder& GraphBuilder,
FSceneTextures& SceneTextures,
FLumenSceneFrameTemporaries& FrameTemporaries,
FRDGTextureRef LightingChannelsTexture,
bool bIsVisualizePass);
/** Renders sky lighting and reflections that can be done in a deferred pass. */
void RenderDeferredReflectionsAndSkyLighting(
FRDGBuilder& GraphBuilder,
const FSceneTextures& SceneTextures,
FRDGTextureRef DynamicBentNormalAOTexture);
void RenderDeferredReflectionsAndSkyLightingHair(FRDGBuilder& GraphBuilder);
/** Computes DFAO, modulates it to scene color (which is assumed to contain diffuse indirect lighting), and stores the output bent normal for use occluding specular. */
void RenderDFAOAsIndirectShadowing(
FRDGBuilder& GraphBuilder,
const FSceneTextures& SceneTextures,
FRDGTextureRef& DynamicBentNormalAO);
bool ShouldRenderDistanceFieldLighting() const;
/** Render Ambient Occlusion using mesh distance fields and the surface cache, which supports dynamic rigid meshes. */
void RenderDistanceFieldLighting(
FRDGBuilder& GraphBuilder,
const FSceneTextures& SceneTextures,
const class FDistanceFieldAOParameters& Parameters,
FRDGTextureRef& OutDynamicBentNormalAO,
bool bModulateToSceneColor,
bool bVisualizeAmbientOcclusion);
/** Render Ambient Occlusion using mesh distance fields on a screen based grid. */
void RenderDistanceFieldAOScreenGrid(
FRDGBuilder& GraphBuilder,
const FSceneTextures& SceneTextures,
const FViewInfo& View,
const FDistanceFieldCulledObjectBufferParameters& CulledObjectBufferParameters,
FRDGBufferRef ObjectTilesIndirectArguments,
const FTileIntersectionParameters& TileIntersectionParameters,
const FDistanceFieldAOParameters& Parameters,
FRDGTextureRef DistanceFieldNormal,
FRDGTextureRef& OutDynamicBentNormalAO);
void RenderMeshDistanceFieldVisualization(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
const FDistanceFieldAOParameters& Parameters);
FSSDSignalTextures RenderLumenScreenProbeGather(
FRDGBuilder& GraphBuilder,
const FSceneTextures& SceneTextures,
FLumenSceneFrameTemporaries& FrameTemporaries,
FRDGTextureRef LightingChannelsTexture,
FViewInfo& View,
FPreviousViewInfo* PreviousViewInfos,
bool& bLumenUseDenoiserComposite,
class FLumenMeshSDFGridParameters& MeshSDFGridParameters,
class LumenRadianceCache::FRadianceCacheInterpolationParameters& RadianceCacheParameters,
class FLumenScreenSpaceBentNormalParameters& ScreenBentNormalParameters);
void StoreLumenDepthHistory(FRDGBuilder& GraphBuilder, const FSceneTextures& SceneTextures, FViewInfo& View);
FSSDSignalTextures RenderLumenIrradianceFieldGather(
FRDGBuilder& GraphBuilder,
const FSceneTextures& SceneTextures,
FLumenSceneFrameTemporaries& FrameTemporaries,
const FViewInfo& View);
void RenderLumenProbe(
FRDGBuilder& GraphBuilder,
const FViewInfo& View,
FLumenSceneFrameTemporaries& FrameTemporaries,
const LumenProbeHierarchy::FHierarchyParameters& HierarchyParameters,
const LumenProbeHierarchy::FIndirectLightingAtlasParameters& IndirectLightingAtlasParameters,
const LumenProbeHierarchy::FEmitProbeParameters& EmitProbeParameters);
void RenderLumenProbeOcclusion(
FRDGBuilder& GraphBuilder,
const FViewInfo& View,
FLumenSceneFrameTemporaries& FrameTemporaries,
const HybridIndirectLighting::FCommonParameters& CommonParameters,
const LumenProbeHierarchy::FIndirectLightingProbeOcclusionParameters& ProbeOcclusionParameters);
FRDGTextureRef RenderLumenReflections(
FRDGBuilder& GraphBuilder,
const FViewInfo& View,
const FSceneTextures& SceneTextures,
FLumenSceneFrameTemporaries& FrameTemporaries,
const class FLumenMeshSDFGridParameters& MeshSDFGridParameters,
const class LumenRadianceCache::FRadianceCacheInterpolationParameters& RadianceCacheParameters,
FLumenReflectionCompositeParameters& OutCompositeParameters);
void RenderLumenSceneVisualization(FRDGBuilder& GraphBuilder, const FMinimalSceneTextures& SceneTextures, FLumenSceneFrameTemporaries& FrameTemporaries);
void RenderLumenRadianceCacheVisualization(FRDGBuilder& GraphBuilder, const FMinimalSceneTextures& SceneTextures);
void LumenScenePDIVisualization();
/** Mark time line for gathering Lumen virtual surface cache feedback. */
void BeginGatheringLumenSurfaceCacheFeedback(FRDGBuilder& GraphBuilder, const FViewInfo& View, FLumenSceneFrameTemporaries& FrameTemporaries);
void FinishGatheringLumenSurfaceCacheFeedback(FRDGBuilder& GraphBuilder, const FViewInfo& View, FLumenSceneFrameTemporaries& FrameTemporaries);
/** Whether tiled deferred is supported and can be used at all. */
bool CanUseTiledDeferred() const;
/** Whether to use tiled deferred shading given a number of lights that support it. */
bool ShouldUseTiledDeferred(int32 NumTiledDeferredLights) const;
/**
* True if the 'r.UseClusteredDeferredShading' flag is 1 and sufficient feature level.
* NOTE: When true it takes precedence over the TiledDeferred path, since they handle the same lights.
*/
bool ShouldUseClusteredDeferredShading() const;
/**
* Have the lights been injected into the light grid?
*/
bool AreLightsInLightGrid() const;
/** Add a clustered deferred shading lighting render pass. Note: in the future it should take the RenderGraph builder as argument */
void AddClusteredDeferredShadingPass(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
const FSortedLightSetSceneInfo& SortedLightsSet,
FRDGTextureRef ShadowMaskBits,
FRDGTextureRef HairStrandsShadowMaskBits);
/** Renders the lights in SortedLights in the range [TiledDeferredLightsStart, TiledDeferredLightsEnd) using tiled deferred shading. */
void RenderTiledDeferredLighting(
FRDGBuilder& GraphBuilder,
FMinimalSceneTextures& SceneTextures,
const TArray<FSortedLightSceneInfo, SceneRenderingAllocator>& SortedLights,
int32 TiledDeferredLightsStart,
int32 TiledDeferredLightsEnd,
const FSimpleLightArray& SimpleLights);
/** Renders the scene's lighting. */
void RenderLights(
FRDGBuilder& GraphBuilder,
FMinimalSceneTextures& SceneTextures,
const FTranslucencyLightingVolumeTextures& TranslucencyLightingVolumeTextures,
FRDGTextureRef LightingChannelsTexture,
FSortedLightSetSceneInfo& SortedLightSet);
/** Render stationary light overlap as complexity to scene color. */
void RenderStationaryLightOverlap(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
FRDGTextureRef LightingChannelsTexture);
/** Renders the scene's translucency passes. */
void RenderTranslucency(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
const FTranslucencyLightingVolumeTextures& TranslucencyLightingVolumeTextures,
FSeparateTranslucencyTextures* OutSeparateTranslucencyTextures,
ETranslucencyView ViewsToRender,
FInstanceCullingManager& InstanceCullingManager);
/** Renders the scene's translucency given a specific pass. */
void RenderTranslucencyInner(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
const FTranslucencyLightingVolumeTextures& TranslucencyLightingVolumeTextures,
FSeparateTranslucencyTextures* OutSeparateTranslucencyTextures,
ETranslucencyView ViewsToRender,
FRDGTextureRef SceneColorCopyTexture,
ETranslucencyPass::Type TranslucencyPass,
FInstanceCullingManager& InstanceCullingManager);
/** Renders the scene's light shafts */
FRDGTextureRef RenderLightShaftOcclusion(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures);
void RenderLightShaftBloom(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
FSeparateTranslucencyTextures& OutSeparateTranslucencyTextures);
bool ShouldRenderDistortion() const;
void RenderDistortion(FRDGBuilder& GraphBuilder, FRDGTextureRef SceneColorTexture, FRDGTextureRef SceneDepthTexture);
/** Renders capsule shadows for all per-object shadows using it for the given light. */
bool RenderCapsuleDirectShadows(
FRDGBuilder& GraphBuilder,
TRDGUniformBufferRef<FSceneTextureUniformParameters> SceneTexturesUniformBuffer,
const FLightSceneInfo& LightSceneInfo,
FRDGTextureRef ScreenShadowMaskTexture,
TArrayView<const FProjectedShadowInfo* const> CapsuleShadows,
bool bProjectingForForwardShading) const;
/** Renders indirect shadows from capsules modulated onto scene color. */
void RenderIndirectCapsuleShadows(FRDGBuilder& GraphBuilder, const FSceneTextures& SceneTextures) const;
/** Renders capsule shadows for movable skylights, using the cone of visibility (bent normal) from DFAO. */
void RenderCapsuleShadowsForMovableSkylight(
FRDGBuilder& GraphBuilder,
TRDGUniformBufferRef<FSceneTextureUniformParameters> SceneTexturesUniformBuffer,
FRDGTextureRef& BentNormalOutput) const;
void RenderDeferredShadowProjections(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
const FTranslucencyLightingVolumeTextures& TranslucencyLightingVolumeTextures,
const FLightSceneInfo* LightSceneInfo,
FRDGTextureRef ScreenShadowMaskTexture,
FRDGTextureRef ScreenShadowMaskSubPixelTexture,
bool& bInjectedTranslucentVolume);
void RenderForwardShadowProjections(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
FRDGTextureRef& ForwardScreenSpaceShadowMask,
FRDGTextureRef& ForwardScreenSpaceShadowMaskSubPixel);
/** Used by RenderLights to render a light function to the attenuation buffer. */
bool RenderLightFunction(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
const FLightSceneInfo* LightSceneInfo,
FRDGTextureRef ScreenShadowMaskTexture,
bool bLightAttenuationCleared,
bool bProjectingForForwardShading,
bool bUseHairStrands);
/** Renders a light function indicating that whole scene shadowing being displayed is for previewing only, and will go away in game. */
bool RenderPreviewShadowsIndicator(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
const FLightSceneInfo* LightSceneInfo,
FRDGTextureRef ScreenShadowMaskTexture,
bool bLightAttenuationCleared,
bool bUseHairStrands);
/** Renders a light function with the given material. */
bool RenderLightFunctionForMaterial(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
const FLightSceneInfo* LightSceneInfo,
FRDGTextureRef ScreenShadowMaskTexture,
const FMaterialRenderProxy* MaterialProxy,
bool bLightAttenuationCleared,
bool bProjectingForForwardShading,
bool bRenderingPreviewShadowsIndicator,
bool bUseHairStrands);
void RenderLightsForHair(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
FSortedLightSetSceneInfo& SortedLightSet,
FRDGTextureRef InScreenShadowMaskSubPixelTexture,
FRDGTextureRef LightingChannelsTexture);
/** Specialized version of RenderLight for hair (run lighting evaluation on at sub-pixel rate, without depth bound) */
void RenderLightForHair(
FRDGBuilder& GraphBuilder,
FViewInfo& View,
const FMinimalSceneTextures& SceneTextures,
const FLightSceneInfo* LightSceneInfo,
FRDGTextureRef ScreenShadowMaskSubPixelTexture,
FRDGTextureRef LightingChannelsTexture,
const FHairStrandsTransmittanceMaskData& InTransmittanceMaskData,
const bool bForwardRendering);
/** Renders an array of simple lights using standard deferred shading. */
void RenderSimpleLightsStandardDeferred(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
const FSimpleLightArray& SimpleLights);
FRDGTextureRef CopyStencilToLightingChannelTexture(
FRDGBuilder& GraphBuilder,
FRDGTextureSRVRef SceneStencilTexture);
bool ShouldRenderVolumetricFog() const;
void SetupVolumetricFog();
void RenderLocalLightsForVolumetricFog(
FRDGBuilder& GraphBuilder,
FViewInfo& View,
bool bUseTemporalReprojection,
const struct FVolumetricFogIntegrationParameterData& IntegrationData,
const FExponentialHeightFogSceneInfo& FogInfo,
FIntVector VolumetricFogGridSize,
FVector GridZParams,
const FRDGTextureDesc& VolumeDesc,
FRDGTexture*& OutLocalShadowedLightScattering,
FRDGTextureRef ConservativeDepthTexture);
void RenderLightFunctionForVolumetricFog(
FRDGBuilder& GraphBuilder,
FViewInfo& View,
const FSceneTextures& SceneTextures,
FIntVector VolumetricFogGridSize,
float VolumetricFogMaxDistance,
FMatrix& OutLightFunctionWorldToShadow,
FRDGTexture*& OutLightFunctionTexture,
bool& bOutUseDirectionalLightShadowing);
void VoxelizeFogVolumePrimitives(
FRDGBuilder& GraphBuilder,
const FViewInfo& View,
const FVolumetricFogIntegrationParameterData& IntegrationData,
FIntVector VolumetricFogGridSize,
FVector GridZParams,
float VolumetricFogDistance,
bool bVoxelizeEmissive);
void ComputeVolumetricFog(FRDGBuilder& GraphBuilder,
const FSceneTextures& SceneTextures);
void VisualizeVolumetricLightmap(FRDGBuilder& GraphBuilder, const FSceneTextures& SceneTextures);
/** Render image based reflections (SSR, Env, SkyLight) without compute shaders */
void RenderStandardDeferredImageBasedReflections(FRHICommandListImmediate& RHICmdList, FGraphicsPipelineStateInitializer& GraphicsPSOInit, bool bReflectionEnv, const TRefCountPtr<IPooledRenderTarget>& DynamicBentNormalAO, TRefCountPtr<IPooledRenderTarget>& VelocityRT);
bool HasDeferredPlanarReflections(const FViewInfo& View) const;
void RenderDeferredPlanarReflections(FRDGBuilder& GraphBuilder, const FSceneTextureParameters& SceneTextures, const FViewInfo& View, FRDGTextureRef& ReflectionsOutput);
bool ShouldDoReflectionEnvironment() const;
bool ShouldRenderDistanceFieldAO() const;
bool IsNaniteEnabled() const;
void SetupImaginaryReflectionTextureParameters(
FRDGBuilder& GraphBuilder,
const FViewInfo& View,
FSceneTextureParameters* OutTextures);
void RenderRayTracingReflections(
FRDGBuilder& GraphBuilder,
const FSceneTextures& SceneTextures,
const FViewInfo& View,
int DenoiserMode,
const FRayTracingReflectionOptions& Options,
IScreenSpaceDenoiser::FReflectionsInputs* OutDenoiserInputs);
void RenderRayTracingDeferredReflections(
FRDGBuilder& GraphBuilder,
const FSceneTextureParameters& SceneTextures,
const FViewInfo& View,
int DenoiserMode,
const FRayTracingReflectionOptions& Options,
IScreenSpaceDenoiser::FReflectionsInputs* OutDenoiserInputs);
void RenderDitheredLODFadingOutMask(FRDGBuilder& GraphBuilder, const FViewInfo& View, FRDGTextureRef SceneDepthTexture);
void RenderRayTracingShadows(
FRDGBuilder& GraphBuilder,
const FSceneTextureParameters& SceneTextures,
const FViewInfo& View,
const FLightSceneInfo& LightSceneInfo,
const IScreenSpaceDenoiser::FShadowRayTracingConfig& RayTracingConfig,
const IScreenSpaceDenoiser::EShadowRequirements DenoiserRequirements,
FRDGTextureRef LightingChannelsTexture,
FRDGTextureUAV* OutShadowMaskUAV,
FRDGTextureUAV* OutRayHitDistanceUAV,
FRDGTextureUAV* SubPixelRayTracingShadowMaskUAV);
void CompositeRayTracingSkyLight(
FRDGBuilder& GraphBuilder,
const FMinimalSceneTextures& SceneTextures,
FRDGTextureRef SkyLightRT,
FRDGTextureRef HitDistanceRT);
bool RenderRayTracingGlobalIllumination(
FRDGBuilder& GraphBuilder,
FSceneTextureParameters& SceneTextures,
FViewInfo& View,
IScreenSpaceDenoiser::FAmbientOcclusionRayTracingConfig* RayTracingConfig,
IScreenSpaceDenoiser::FDiffuseIndirectInputs* OutDenoiserInputs);
void RenderRayTracingGlobalIlluminationBruteForce(
FRDGBuilder& GraphBuilder,
FSceneTextureParameters& SceneTextures,
FViewInfo& View,
const IScreenSpaceDenoiser::FAmbientOcclusionRayTracingConfig& RayTracingConfig,
int32 UpscaleFactor,
IScreenSpaceDenoiser::FDiffuseIndirectInputs* OutDenoiserInputs);
void RayTracingGlobalIlluminationCreateGatherPoints(
FRDGBuilder& GraphBuilder,
FSceneTextureParameters& SceneTextures,
FViewInfo& View,
int32 UpscaleFactor,
int32 SampleIndex,
FRDGBufferRef& GatherPointsBuffer,
FIntVector& GatherPointsResolution);
void RenderRayTracingGlobalIlluminationFinalGather(
FRDGBuilder& GraphBuilder,
FSceneTextureParameters& SceneTextures,
FViewInfo& View,
const IScreenSpaceDenoiser::FAmbientOcclusionRayTracingConfig& RayTracingConfig,
int32 UpscaleFactor,
IScreenSpaceDenoiser::FDiffuseIndirectInputs* OutDenoiserInputs);
void RenderRayTracingAmbientOcclusion(
FRDGBuilder& GraphBuilder,
FViewInfo& View,
const FSceneTextureParameters& SceneTextures,
FRDGTextureRef* OutAmbientOcclusionTexture);
#if RHI_RAYTRACING
template <int TextureImportanceSampling>
void RenderRayTracingRectLightInternal(
FRDGBuilder& GraphBuilder,
TRDGUniformBufferRef<FSceneTextureUniformParameters> SceneTexturesUniformBuffer,
const TArray<FViewInfo>& Views,
const FLightSceneInfo& RectLightSceneInfo,
FRDGTextureRef ScreenShadowMaskTexture,
FRDGTextureRef RayDistanceTexture);
void VisualizeRectLightMipTree(FRHICommandListImmediate& RHICmdList, const FViewInfo& View, const FRWBuffer& RectLightMipTree, const FIntVector& RectLightMipTreeDimensions);
void VisualizeSkyLightMipTree(FRHICommandListImmediate& RHICmdList, const FViewInfo& View, const TRefCountPtr<IPooledRenderTarget>& SceneColor, FRWBuffer& SkyLightMipTreePosX, FRWBuffer& SkyLightMipTreePosY, FRWBuffer& SkyLightMipTreePosZ, FRWBuffer& SkyLightMipTreeNegX, FRWBuffer& SkyLightMipTreeNegY, FRWBuffer& SkyLightMipTreeNegZ, const FIntVector& SkyLightMipDimensions);
void RenderRayTracingSkyLight(
FRDGBuilder& GraphBuilder,
FRDGTextureRef SceneColorTexture,
FRDGTextureRef& OutSkyLightTexture,
FRDGTextureRef& OutHitDistanceTexture);
void RenderRayTracingPrimaryRaysView(
FRDGBuilder& GraphBuilder,
const FViewInfo& View,
FRDGTextureRef* InOutColorTexture,
FRDGTextureRef* InOutRayHitDistanceTexture,
int32 SamplePerPixel,
int32 HeightFog,
float ResolutionFraction,
ERayTracingPrimaryRaysFlag Flags);
void RenderRayTracingTranslucency(FRDGBuilder& GraphBuilder, FRDGTextureMSAA SceneColorTexture);
void RenderRayTracingTranslucencyView(
FRDGBuilder& GraphBuilder,
const FViewInfo& View,
FRDGTextureRef* OutColorTexture,
FRDGTextureRef* OutRayHitDistanceTexture,
int32 SamplePerPixel,
int32 HeightFog,
float ResolutionFraction);
/** Lighting Evaluation shader setup (used by ray traced reflections and translucency) */
void SetupRayTracingLightingMissShader(FRHICommandListImmediate& RHICmdList, const FViewInfo& View);
/** Path tracing functions. */
void RenderPathTracing(
FRDGBuilder& GraphBuilder,
const FViewInfo& View,
TRDGUniformBufferRef<FSceneTextureUniformParameters> SceneTexturesUniformBuffer,
FRDGTextureRef SceneColorOutputTexture);
void ComputePathCompaction(FRHICommandListImmediate& RHICmdList, const FViewInfo& View, FRHITexture* RadianceTexture, FRHITexture* SampleCountTexture, FRHITexture* PixelPositionTexture,
FRHIUnorderedAccessView* RadianceSortedRedUAV, FRHIUnorderedAccessView* RadianceSortedGreenUAV, FRHIUnorderedAccessView* RadianceSortedBlueUAV, FRHIUnorderedAccessView* RadianceSortedAlphaUAV, FRHIUnorderedAccessView* SampleCountSortedUAV);
void WaitForRayTracingScene(FRDGBuilder& GraphBuilder, FRDGBufferRef DynamicGeometryScratchBuffer);
/** Debug ray tracing functions. */
void RenderRayTracingDebug(FRDGBuilder& GraphBuilder, const FViewInfo& View, FRDGTextureRef SceneColorOutputTexture);
void RenderRayTracingBarycentrics(FRDGBuilder& GraphBuilder, const FViewInfo& View, FRDGTextureRef SceneColorOutputTexture);
/** Fills RayTracingScene instance list for the given View and adds relevant ray tracing data to the view. Does not reset previous scene contents. */
bool GatherRayTracingWorldInstancesForView(FRDGBuilder& GraphBuilder, FViewInfo& View, FRayTracingScene& RayTracingScene);
bool SetupRayTracingPipelineStates(FRHICommandListImmediate& RHICmdList);
bool DispatchRayTracingWorldUpdates(FRDGBuilder& GraphBuilder, FRDGBufferRef& OutDynamicGeometryScratchBuffer);
FRayTracingPipelineState* BindRayTracingMaterialPipeline(FRHICommandList& RHICmdList, FViewInfo& View, const TArrayView<FRHIRayTracingShader*>& RayGenShaderTable);
FRayTracingPipelineState* BindRayTracingDeferredMaterialGatherPipeline(FRHICommandList& RHICmdList, const FViewInfo& View, const TArrayView<FRHIRayTracingShader*>& RayGenShaderTable);
FRayTracingPipelineState* BindLumenHardwareRayTracingMaterialPipeline(FRHICommandList& RHICmdList, const FViewInfo& View, const TArrayView<FRHIRayTracingShader*>& RayGenShaderTable, FRHIBuffer* OutHitGroupDataBuffer);
void SetupLumenHardwareRayTracingHitGroupBuffer(FViewInfo& View);
// #dxr_todo: UE-72565: refactor ray tracing effects to not be member functions of DeferredShadingRenderer. Register each effect at startup and just loop over them automatically
static void PrepareRayTracingReflections(const FViewInfo& View, const FScene& Scene, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareRayTracingDeferredReflections(const FViewInfo& View, const FScene& Scene, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareSingleLayerWaterRayTracingReflections(const FViewInfo& View, const FScene& Scene, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareRayTracingShadows(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareRayTracingAmbientOcclusion(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareRayTracingSkyLight(const FViewInfo& View, const FScene& Scene, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareRayTracingGlobalIllumination(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareRayTracingTranslucency(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareRayTracingDebug(const FSceneViewFamily& ViewFamily, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PreparePathTracing(const FSceneViewFamily& ViewFamily, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareLumenHardwareRayTracingScreenProbeGather(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareLumenHardwareRayTracingScreenProbeGatherDeferredMaterial(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareLumenHardwareRayTracingRadianceCache(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareLumenHardwareRayTracingRadianceCacheDeferredMaterial(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareLumenHardwareRayTracingTranslucencyVolume(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareLumenHardwareRayTracingReflections(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareLumenHardwareRayTracingReflectionsDeferredMaterial(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareLumenHardwareRayTracingVisualize(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareLumenHardwareRayTracingVisualizeDeferredMaterial(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
// Versions for setting up the deferred material pipeline
static void PrepareRayTracingReflectionsDeferredMaterial(const FViewInfo& View, const FScene& Scene, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareRayTracingDeferredReflectionsDeferredMaterial(const FViewInfo& View, const FScene& Scene, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareRayTracingGlobalIlluminationDeferredMaterial(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
// Versions for setting up the lumen material pipeline
static void PrepareLumenHardwareRayTracingVisualizeLumenMaterial(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareLumenHardwareRayTracingReflectionsLumenMaterial(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareLumenHardwareRayTracingScreenProbeGatherLumenMaterial(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareLumenHardwareRayTracingRadianceCacheLumenMaterial(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareLumenHardwareRayTracingRadiosityLumenMaterial(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
static void PrepareLumenHardwareRayTracingDirectLightingLumenMaterial(const FViewInfo& View, TArray<FRHIRayTracingShader*>& OutRayGenShaders);
/** Lighting evaluation shader registration */
static FRHIRayTracingShader* GetRayTracingLightingMissShader(FViewInfo& View);
const FRHITransition* RayTracingDynamicGeometryUpdateEndTransition = nullptr; // Signaled when all AS for this frame are built
#endif // RHI_RAYTRACING
/** Set to true if lights were injected into the light grid (this controlled by somewhat complex logic, this flag is used to cross-check). */
bool bAreLightsInLightGrid;
FDynamicShadowsTaskData* CurrentDynamicShadowsTaskData{};
};
DECLARE_CYCLE_STAT_EXTERN(TEXT("PrePass"), STAT_CLM_PrePass, STATGROUP_CommandListMarkers, );