You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
- Avoid gotchas with max texture size when static separate enabled - Simplify addressing logic in a number of places - Avoid allocating extra HZB that we never use Details: - Support rendering/sampling to 2D depth texture array in Nanite and virtual shadow map pass - Remove some unnecessary HZB-related cvars - Remove unused permutations from VSM HW raster #preflight 624f4e5611261bc7b2171208 #rb jamie.hayes #ROBOMERGE-AUTHOR: andrew.lauritzen #ROBOMERGE-SOURCE: CL 19679616 via CL 19679656 via CL 19679706 #ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v938-19570697) [CL 19680680 by andrew lauritzen in ue5-main branch]
112 lines
3.6 KiB
Plaintext
112 lines
3.6 KiB
Plaintext
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
/*=============================================================================
|
|
ShadowDepthPixelShader.usf: Pixel shader for writing shadow depth.
|
|
=============================================================================*/
|
|
|
|
// needs to before Common.usf
|
|
#define SHADOW_DEPTH_SHADER 1
|
|
#define USE_STENCIL_LOD_DITHER 0
|
|
|
|
#ifndef ENABLE_NON_NANITE_VSM
|
|
#error "ENABLE_NON_NANITE_VSM should be defined to either 0 or 1!"
|
|
#endif
|
|
|
|
|
|
#if ENABLE_NON_NANITE_VSM
|
|
#define VIRTUAL_SM_ENABLED (!(ONEPASS_POINTLIGHT_SHADOW || PERSPECTIVE_CORRECT_DEPTH))
|
|
#else
|
|
#define VIRTUAL_SM_ENABLED 0
|
|
#endif
|
|
|
|
#include "Nanite/NanitePackedNaniteView.ush"
|
|
#include "Common.ush"
|
|
|
|
// Reroute SceneTexturesStruct uniform buffer references to the shadow depth pass uniform buffer
|
|
#if FEATURE_LEVEL >= FEATURE_LEVEL_SM5
|
|
#define PassStruct ShadowDepthPass
|
|
#define SceneTexturesStruct ShadowDepthPass.SceneTextures
|
|
#else
|
|
#define PassStruct MobileShadowDepthPass
|
|
#define MobileSceneTextures MobileShadowDepthPass.SceneTextures
|
|
#endif
|
|
|
|
#include "/Engine/Generated/Material.ush"
|
|
#include "/Engine/Generated/VertexFactory.ush"
|
|
#include "ShadowDepthCommon.ush"
|
|
|
|
|
|
#if VIRTUAL_SM_ENABLED
|
|
#include "Nanite/NaniteDataDecode.ush"
|
|
#include "SceneData.ush"
|
|
#include "VirtualShadowMaps/VirtualShadowMapPageAccessCommon.ush"
|
|
#endif
|
|
|
|
#define SECONDARY_OCCLUSION 1
|
|
|
|
void Main(
|
|
FShadowDepthVSToPS Inputs,
|
|
#if VIRTUAL_SM_ENABLED
|
|
nointerpolation uint PackedPageInfo : TEXCOORD8,
|
|
#endif
|
|
in float4 SvPosition : SV_Position // after all interpolators
|
|
#if PERSPECTIVE_CORRECT_DEPTH || COMPILER_METAL
|
|
,out float OutDepth : SV_DEPTH
|
|
#endif
|
|
)
|
|
{
|
|
ResolvedView = ResolveView();
|
|
|
|
#if INTERPOLATE_VF_ATTRIBUTES
|
|
|
|
FMaterialPixelParameters MaterialParameters = GetMaterialPixelParameters(Inputs.FactoryInterpolants, SvPosition);
|
|
FPixelMaterialInputs PixelMaterialInputs;
|
|
#if INTERPOLATE_POSITION
|
|
{
|
|
float4 ScreenPosition = SvPositionToResolvedScreenPosition(SvPosition);
|
|
|
|
float3 TranslatedWorld = Inputs.PixelPosition.xyz;
|
|
|
|
CalcMaterialParametersEx(MaterialParameters, PixelMaterialInputs, SvPosition, ScreenPosition, 1, TranslatedWorld, TranslatedWorld);
|
|
}
|
|
#else
|
|
CalcMaterialParameters(MaterialParameters, PixelMaterialInputs, SvPosition, 1);
|
|
#endif
|
|
|
|
// Evaluate the mask for masked materials
|
|
GetMaterialClippingShadowDepth(MaterialParameters, PixelMaterialInputs);
|
|
#else
|
|
ClipLODTransition(SvPosition.xy);
|
|
#endif
|
|
|
|
#if PERSPECTIVE_CORRECT_DEPTH
|
|
const float InvMaxSubjectDepth = PassStruct.ShadowParams.w;
|
|
Inputs.ShadowDepth = 1 - Inputs.ShadowDepth * InvMaxSubjectDepth;
|
|
Inputs.ShadowDepth += Inputs.DepthBias;
|
|
|
|
OutDepth = saturate(Inputs.ShadowDepth);
|
|
#elif COMPILER_METAL
|
|
// Metal fragment shader must not be empty,
|
|
// so output depth value explicitly if this shader permuation was not discarded
|
|
OutDepth = SvPosition.z;
|
|
#endif
|
|
|
|
#if ENABLE_NON_NANITE_VSM && VIRTUAL_TEXTURE_TARGET
|
|
uint2 vAddress = (uint2)SvPosition.xy;
|
|
float DeviceZ = SvPosition.z;
|
|
|
|
FPageInfo PageInfo = UnpackPageInfo( PackedPageInfo );
|
|
FNaniteView NaniteView = UnpackNaniteView( PassStruct.PackedNaniteViews[ PageInfo.ViewId ] );
|
|
|
|
FShadowPhysicalPage Page = ShadowDecodePageTable( PassStruct.VirtualSmPageTable[ CalcPageOffset( NaniteView.TargetLayerIndex, NaniteView.TargetMipLevel, vAddress >> VSM_LOG2_PAGE_SIZE ) ] );
|
|
|
|
if( Page.bThisLODValid )
|
|
{
|
|
uint2 pAddress = Page.PhysicalAddress * VSM_PAGE_SIZE + (vAddress & VSM_PAGE_SIZE_MASK);
|
|
// If requested, render to the static page
|
|
const int ArrayIndex = PageInfo.bStaticPage ? GetVirtualShadowMapStaticArrayIndex() : 0;
|
|
InterlockedMax( PassStruct.OutDepthBufferArray[ uint3( pAddress, ArrayIndex ) ], asuint( DeviceZ ) );
|
|
}
|
|
#endif
|
|
}
|