Files
UnrealEngineUWP/Engine/Shaders/Private/VirtualShadowMaps/VirtualShadowMapPageCacheCommon.ush
jamie hayes 257ae60ff4 New material option: "Always Evaluate World Position Offset". This new option is used to force World Position Offset to always be evaluated for a material so that it cannot be disabled by the likes of "Evaluate World Position Offset" or "World Position Offset Disable Distance" on the component. This is useful for meshes that use WPO for behavior like billboarding (i.e. imposters) where WPO shouldn't be disabled for performance.
This option has the following knock-on effects of other rendering systems to prevent potential bugs or artifacts:
* For non-Nanite meshes, enabling this option will force instances of draw commands with this material applied to always invalidate VSM page cache when instance culling for VSM shadows.
* For Nanite meshes, enabling this option will force all clusters of all instances to pad cluster culling bounds and invalidate cached VSM pages, even if clusters don't have this material applied to it, as it would be prohibitively expensive to determine if no materials on the cluster would force invalidation.

#rb ola.olsson, massimo.tristano

[CL 26448477 by jamie hayes in 5.3 branch]
2023-07-18 17:20:38 -04:00

33 lines
1.5 KiB
Plaintext

// Copyright Epic Games, Inc. All Rights Reserved.
/*=============================================================================
VirtualShadowMapPageCacheCommon.ush:
=============================================================================*/
#pragma once
// Flags buffer (one bit per PersistentPrimitiveIndex) to track statically cached primitives that are invalidating
// Currently we use GPU messaging to send these primitives back for the CPU to handle as desired
// in future frames, but this flags buffer ensures we only send one message per prim.
RWStructuredBuffer<uint> OutStaticInvalidatingPrimitives;
void RecordStaticPrimitiveInvalidation(uint PersistentPrimitiveIndex)
{
uint PrimitiveIdWordOffset = PersistentPrimitiveIndex / 32U;
uint PrimitiveIdWordMask = 1U << (PersistentPrimitiveIndex % 32U);
InterlockedOr(OutStaticInvalidatingPrimitives[PrimitiveIdWordOffset], PrimitiveIdWordMask);
}
bool ShouldMaterialInvalidateShadowCache(FPrimitiveSceneData PrimitiveData, bool bEnableWPO)
{
// Determine if this instance will cause page invalidations.
bool bInvalidate = bEnableWPO;
// Ignore WPO disable distance for this if any of the materials have bAlwaysEvaluateWorldPositionOffset = true.
bInvalidate |= ((PrimitiveData.Flags & PRIMITIVE_SCENE_DATA_FLAG_HAS_ALWAYS_EVALUATE_WPO_MATERIALS) != 0u);
// Unless, of course, the primitive opts to disable shadow cache invalidations.
bInvalidate &= ((PrimitiveData.Flags & PRIMITIVE_SCENE_DATA_FLAG_DISABLE_MATERIAL_INVALIDATIONS) == 0u);
return bInvalidate;
}