UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SingleLayerWaterRendering.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "RenderGraph.h"
6#include "PixelShaderUtils.h"
8#include "SingleLayerWaterDefinitions.h"
9#include "Froxel/Froxel.h"
10
11class FViewInfo;
13
15{
16 FTiledReflection TiledReflection = FTiledReflection{ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, SLW_TILE_SIZE_XY };
19};
20
29
30
45
46// Location relative to the base pass when to run the water depth prepass. If a full depth prepass is available,
47// the water depth prepass can run before the base pass, allowing certain optimizations to save work in the base pass.
49{
50 // The water depth prepass (if enabled) runs after the regular depth prepass and before the base pass.
52 // The water depth prepass (if enabled) runs after the base pass.
54};
55
61
83
84template<typename TPixelShaderClass, typename TPassParameters>
86 FRDGBuilder& GraphBuilder,
87 const FGlobalShaderMap* GlobalShaderMap,
88 FRDGEventName&& PassName,
92 const FIntRect& Viewport,
93 const FTiledReflection* TiledScreenSpaceReflection = nullptr,
94 FRHIBlendState* BlendState = nullptr,
95 FRHIRasterizerState* RasterizerState = nullptr,
96 FRHIDepthStencilState* DepthStencilState = nullptr,
98{
99 PassParameters->IndirectDrawParameter = TiledScreenSpaceReflection ? TiledScreenSpaceReflection->DrawIndirectParametersBuffer : nullptr;
100
101 PassParameters->VS.ViewUniformBuffer = ViewUniformBuffer;
102 PassParameters->VS.TileListData = TiledScreenSpaceReflection ? TiledScreenSpaceReflection->TileListDataBufferSRV : nullptr;
103
106
107 const bool bRunTiled = TiledScreenSpaceReflection != nullptr;
108 if (bRunTiled)
109 {
112
115
116 GraphBuilder.AddPass(
117 Forward<FRDGEventName>(PassName),
120 [PassParameters, GlobalShaderMap, Viewport, TiledScreenSpaceReflection, VertexShader, PixelShader, BlendState, RasterizerState, DepthStencilState, StencilRef](FRDGAsyncTask, FRHICommandList& RHICmdList)
121 {
122 RHICmdList.SetViewport(Viewport.Min.X, Viewport.Min.Y, 0.0f, Viewport.Max.X, Viewport.Max.Y, 1.0f);
123
124 FGraphicsPipelineStateInitializer GraphicsPSOInit;
125 FPixelShaderUtils::InitFullscreenPipelineState(RHICmdList, GlobalShaderMap, PixelShader, GraphicsPSOInit);
126
128 GraphicsPSOInit.BlendState = BlendState ? BlendState : GraphicsPSOInit.BlendState;
129 GraphicsPSOInit.RasterizerState = RasterizerState ? RasterizerState : GraphicsPSOInit.RasterizerState;
130 GraphicsPSOInit.DepthStencilState = DepthStencilState ? DepthStencilState : GraphicsPSOInit.DepthStencilState;
131 GraphicsPSOInit.BoundShaderState.VertexDeclarationRHI = GEmptyVertexDeclaration.VertexDeclarationRHI;
132 GraphicsPSOInit.BoundShaderState.VertexShaderRHI = VertexShader.GetVertexShader();
133 GraphicsPSOInit.BoundShaderState.PixelShaderRHI = PixelShader.GetPixelShader();
134
135 SetGraphicsPipelineState(RHICmdList, GraphicsPSOInit, StencilRef);
136
137 SetShaderParameters(RHICmdList, VertexShader, VertexShader.GetVertexShader(), PassParameters->VS);
138 SetShaderParameters(RHICmdList, PixelShader, PixelShader.GetPixelShader(), PassParameters->PS);
139
140 RHICmdList.DrawPrimitiveIndirect(PassParameters->IndirectDrawParameter->GetIndirectRHICallBuffer(), 0);
141 });
142 }
143 else
144 {
145 GraphBuilder.AddPass(
146 Forward<FRDGEventName>(PassName),
149 [PassParameters, GlobalShaderMap, Viewport, PixelShader, BlendState, RasterizerState, DepthStencilState, StencilRef](FRDGAsyncTask, FRHICommandList& RHICmdList)
150 {
151 RHICmdList.SetViewport(Viewport.Min.X, Viewport.Min.Y, 0.0f, Viewport.Max.X, Viewport.Max.Y, 1.0f);
152
153 FGraphicsPipelineStateInitializer GraphicsPSOInit;
154 FPixelShaderUtils::InitFullscreenPipelineState(RHICmdList, GlobalShaderMap, PixelShader, GraphicsPSOInit);
155
156 GraphicsPSOInit.BlendState = BlendState ? BlendState : GraphicsPSOInit.BlendState;
157 GraphicsPSOInit.RasterizerState = RasterizerState ? RasterizerState : GraphicsPSOInit.RasterizerState;
158 GraphicsPSOInit.DepthStencilState = DepthStencilState ? DepthStencilState : GraphicsPSOInit.DepthStencilState;
159
160 SetGraphicsPipelineState(RHICmdList, GraphicsPSOInit, StencilRef);
161
162 SetShaderParameters(RHICmdList, PixelShader, PixelShader.GetPixelShader(), PassParameters->PS);
163
165 });
166 }
167}
TGlobalResource< FEmptyVertexDeclaration, FRenderResource::EInitPhase::Pre > GEmptyVertexDeclaration
Definition CommonRenderResources.cpp:14
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
ECustomDepthPassLocation
Definition CustomDepthRendering.h:11
#define DECLARE_GLOBAL_SHADER(ShaderClass)
Definition GlobalShader.h:408
void SetGraphicsPipelineState(FRHICommandList &RHICmdList, const FGraphicsPipelineStateInitializer &Initializer, uint32 StencilRef, EApplyRendertargetOption ApplyFlags, bool bApplyAdditionalState)
Definition PipelineStateCache.cpp:1478
EPixelFormat
Definition PixelFormat.h:16
@ PT_RectList
Definition RHIDefinitions.h:844
@ PT_TriangleList
Definition RHIDefinitions.h:824
#define GRHISupportsRectTopology
Definition RHIGlobals.h:789
void ClearUnusedGraphResources(const TShaderRef< TShaderClass > &Shader, const FShaderParametersMetadata *ParametersMetadata, typename TShaderClass::FParameters *InoutParameters, std::initializer_list< FRDGResourceRef > ExcludeList={})
Definition RenderGraphUtils.h:195
#define SHADER_PARAMETER_RDG_BUFFER_SRV(ShaderType, MemberName)
Definition ShaderParameterMacros.h:1800
#define BEGIN_SHADER_PARAMETER_STRUCT(StructTypeName, DllStorage)
Definition ShaderParameterMacros.h:1482
#define SHADER_PARAMETER_STRUCT_REF(StructType, MemberName)
Definition ShaderParameterMacros.h:1909
#define END_SHADER_PARAMETER_STRUCT()
Definition ShaderParameterMacros.h:1485
void SetShaderParameters(FRHIBatchedShaderParameters &BatchedParameters, const FShaderParameterBindings &Bindings, const FShaderParametersMetadata *ParametersMetadata, const void *InParametersData)
Definition ShaderParameterStruct.cpp:883
#define SHADER_USE_PARAMETER_STRUCT(ShaderClass, ShaderParentClass)
Definition ShaderParameterStruct.h:62
void ValidateShaderParameters(const TShaderRef< FShader > &Shader, const FShaderParametersMetadata *ParametersMetadata, const void *ParametersData)
Definition ShaderParameterStruct.h:125
ESingleLayerWaterPrepassLocation
Definition SingleLayerWaterRendering.h:49
bool ShouldRenderSingleLayerWaterSkippedRenderEditorNotification(TArrayView< const FViewInfo > Views)
Definition SingleLayerWaterRendering.cpp:252
bool ShouldRenderSingleLayerWaterDepthPrepass(TArrayView< const FViewInfo > Views)
Definition SingleLayerWaterRendering.cpp:267
ESingleLayerWaterPrepassLocation GetSingleLayerWaterDepthPrepassLocation(bool bFullDepthPrepass, ECustomDepthPassLocation CustomDepthPassLocation)
Definition SingleLayerWaterRendering.cpp:276
bool ShouldUseBilinearSamplerForDepthWithoutSingleLayerWater(EPixelFormat DepthTextureFormat)
Definition SingleLayerWaterRendering.cpp:325
bool ShouldRenderSingleLayerWater(TArrayView< const FViewInfo > Views)
Definition SingleLayerWaterRendering.cpp:237
void SingleLayerWaterAddTiledFullscreenPass(FRDGBuilder &GraphBuilder, const FGlobalShaderMap *GlobalShaderMap, FRDGEventName &&PassName, TShaderRefBase< TPixelShaderClass, FShaderMapPointerTable > PixelShader, TPassParameters *PassParameters, const TUniformBufferRef< FViewUniformShaderParameters > &ViewUniformBuffer, const FIntRect &Viewport, const FTiledReflection *TiledScreenSpaceReflection=nullptr, FRHIBlendState *BlendState=nullptr, FRHIRasterizerState *RasterizerState=nullptr, FRHIDepthStencilState *DepthStencilState=nullptr, uint32 StencilRef=0)
Definition SingleLayerWaterRendering.h:85
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition GlobalShader.h:173
Definition GlobalShader.h:269
Definition RHIResources.h:4572
FBoundShaderStateInput BoundShaderState
Definition RHIResources.h:4754
FRHIBlendState * BlendState
Definition RHIResources.h:4755
FRHIRasterizerState * RasterizerState
Definition RHIResources.h:4756
FRHIDepthStencilState * DepthStencilState
Definition RHIResources.h:4757
EPrimitiveType PrimitiveType
Definition RHIResources.h:4760
Definition RenderGraphResources.h:1321
Definition RenderGraphBuilder.h:49
FRDGPassRef AddPass(FRDGEventName &&Name, const ParameterStructType *ParameterStruct, ERDGPassFlags Flags, ExecuteLambdaType &&ExecuteLambda)
Definition RenderGraphEvent.h:38
Definition RenderGraphResources.h:571
Definition RHIResources.h:696
Definition RHICommandList.h:3819
void DrawPrimitiveIndirect(FRHIBuffer *ArgumentBuffer, uint32 ArgumentOffset)
Definition RHICommandList.h:4127
void SetViewport(float MinX, float MinY, float MinZ, float MaxX, float MaxY, float MaxZ)
Definition RHICommandList.h:4015
Definition RHIResources.h:686
Definition RHIResources.h:679
Definition SceneRendering.h:1132
Definition SingleLayerWaterRendering.h:63
Definition Froxel.h:69
Definition ArrayView.h:139
Definition Array.h:670
Definition Shader.h:2629
Definition Shader.h:1021
Definition ShaderParameterMacros.h:136
FRHIPixelShader * PixelShaderRHI
Definition RHIResources.h:4510
FRHIVertexShader * VertexShaderRHI
Definition RHIResources.h:4509
FRHIVertexDeclaration * VertexDeclarationRHI
Definition RHIResources.h:4508
Definition GlobalShader.h:73
static RENDERCORE_API void DrawFullscreenTriangle(FRHICommandList &RHICmdList, uint32 InstanceCount=1)
Definition PixelShaderUtils.cpp:20
static RENDERCORE_API void InitFullscreenPipelineState(FRHICommandList &RHICmdList, const FGlobalShaderMap *GlobalShaderMap, const TShaderRef< FShader > &PixelShader, FGraphicsPipelineStateInitializer &GraphicsPSOInit)
Definition PixelShaderUtils.cpp:50
Definition RenderGraphDefinitions.h:103
Definition RenderGraphUtils.h:288
Definition SingleLayerWaterRendering.h:34
FVector4f MinMaxUV
Definition SingleLayerWaterRendering.h:36
FIntRect ViewRect
Definition SingleLayerWaterRendering.h:35
Definition SingleLayerWaterRendering.h:32
FRDGTextureRef ColorTexture
Definition SingleLayerWaterRendering.h:40
FRDGTextureRef DepthTexture
Definition SingleLayerWaterRendering.h:41
TArray< FView > Views
Definition SingleLayerWaterRendering.h:42
FRDGTextureRef SeparatedMainDirLightTexture
Definition SingleLayerWaterRendering.h:39
float RefractionDownsampleFactor
Definition SingleLayerWaterRendering.h:43
Definition ShaderCore.h:544
Definition SingleLayerWaterRendering.h:22
FRDGTextureRef RefractionMaskTexture
Definition SingleLayerWaterRendering.h:25
FRDGTextureRef SceneDepthWithoutWater
Definition SingleLayerWaterRendering.h:26
TArray< FSingleLayerWaterTileClassification > ViewTileClassification
Definition SingleLayerWaterRendering.h:27
FRDGTextureMSAA DepthPrepassTexture
Definition SingleLayerWaterRendering.h:24
Froxel::FRenderer Froxels
Definition SingleLayerWaterRendering.h:23
Definition SingleLayerWaterRendering.h:15
FIntPoint TiledViewRes
Definition SingleLayerWaterRendering.h:18
FRDGBufferRef TileMaskBuffer
Definition SingleLayerWaterRendering.h:17
FTiledReflection TiledReflection
Definition SingleLayerWaterRendering.h:16
Definition ScreenSpaceRayTracing.h:28
Definition ShaderPermutation.h:229
Definition IntPoint.h:25
IntType Y
Definition IntPoint.h:37
IntType X
Definition IntPoint.h:34
IntPointType Max
Definition IntRect.h:37
IntPointType Min
Definition IntRect.h:34