1.5 KiB
1.5 KiB
title, date, excerpt, tags, rating
title | date | excerpt | tags | rating |
---|---|---|---|---|
深度相关 | 2024-09-09 16:49:08 | ⭐ |
相关代码
位于common.ush
#define NearDepthValue (HAS_INVERTED_Z_BUFFER ? 1.0f : 0.0f)
#define FarDepthValue (HAS_INVERTED_Z_BUFFER ? 0.0f : 1.0f)
可以通过DeviceZ == FarDepthValue来判断是否处于最远端。
float DeviceZ = DepthReadDisabled ? FarDepthValue : LookupDeviceZ(UvBuffer);
#endif
if (DeviceZ == FarDepthValue)
{
// Get the light disk luminance to draw
LuminanceScale = SkyAtmosphere.SkyLuminanceFactor;
#if SOURCE_DISK_ENABLED
if (SourceDiskEnabled > 0)
{
PreExposedL += GetLightDiskLuminance(WorldPos, WorldDir, 0);
#if SECOND_ATMOSPHERE_LIGHT_ENABLED
PreExposedL += GetLightDiskLuminance(WorldPos, WorldDir, 1);
#endif
}
#endif
#if RENDERSKY_ENABLED==0
// We should not render the sky and the current pixels are at far depth, so simply early exit.
// We enable depth bound when supported to not have to even process those pixels.
OutLuminance = PrepareOutput(float3(0.0f, 0.0f, 0.0f), float3(1.0f, 1.0f, 1.0f));
//Now the sky pass can ignore the pixel with depth == far but it will need to alpha clip because not all RHI backend support depthbound tests.
// And the depthtest is already setup to avoid writing all the pixel closer than to the camera than the start distance (very good optimisation).
// Since this shader does not write to depth or stencil it should still benefit from EArlyZ even with the clip (See AMD depth-in-depth documentation)
clip(-1.0f);
return;
#endif