Fix for shadow atlas not being cleared correctly
This commit is contained in:
@@ -1413,7 +1413,11 @@ void ShadowsPass::RenderShadowMaps(RenderContextBatch& renderContextBatch)
|
|||||||
if (!shadows.ClearStaticShadowMapAtlas)
|
if (!shadows.ClearStaticShadowMapAtlas)
|
||||||
{
|
{
|
||||||
// Color.r is used by PS_DepthClear in Quad shader to clear depth
|
// Color.r is used by PS_DepthClear in Quad shader to clear depth
|
||||||
|
#if FLAX_REVERSE_Z
|
||||||
|
quadShaderData.Color = Float4::Zero;
|
||||||
|
#else
|
||||||
quadShaderData.Color = Float4::One;
|
quadShaderData.Color = Float4::One;
|
||||||
|
#endif
|
||||||
context->UpdateCB(quadShaderCB, &quadShaderData);
|
context->UpdateCB(quadShaderCB, &quadShaderData);
|
||||||
context->BindCB(0, quadShaderCB);
|
context->BindCB(0, quadShaderCB);
|
||||||
|
|
||||||
@@ -1480,7 +1484,11 @@ void ShadowsPass::RenderShadowMaps(RenderContextBatch& renderContextBatch)
|
|||||||
else if (!shadows.ClearShadowMapAtlas)
|
else if (!shadows.ClearShadowMapAtlas)
|
||||||
{
|
{
|
||||||
// Color.r is used by PS_DepthClear in Quad shader to clear depth
|
// Color.r is used by PS_DepthClear in Quad shader to clear depth
|
||||||
|
#if FLAX_REVERSE_Z
|
||||||
|
quadShaderData.Color = Float4::Zero;
|
||||||
|
#else
|
||||||
quadShaderData.Color = Float4::One;
|
quadShaderData.Color = Float4::One;
|
||||||
|
#endif
|
||||||
context->UpdateCB(quadShaderCB, &quadShaderData);
|
context->UpdateCB(quadShaderCB, &quadShaderData);
|
||||||
context->BindCB(0, quadShaderCB);
|
context->BindCB(0, quadShaderCB);
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ float3 GetShadowPositionOffset(float offsetScale, float NoL, float3 normal)
|
|||||||
|
|
||||||
float CalculateSubsurfaceOcclusion(float opacity, float sceneDepth, float shadowMapDepth)
|
float CalculateSubsurfaceOcclusion(float opacity, float sceneDepth, float shadowMapDepth)
|
||||||
{
|
{
|
||||||
|
// `sceneDepth` and `shadowMapDepth`are raw depths, so we have to flip them when reverse-z is enabled
|
||||||
#if FLAX_REVERSE_Z
|
#if FLAX_REVERSE_Z
|
||||||
float thickness = max(shadowMapDepth - sceneDepth, 0);
|
float thickness = max(shadowMapDepth - sceneDepth, 0);
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -11,13 +11,27 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if FEATURE_LEVEL >= FEATURE_LEVEL_SM5
|
#if FEATURE_LEVEL >= FEATURE_LEVEL_SM5
|
||||||
|
|
||||||
|
#if FLAX_REVERSE_Z
|
||||||
|
#define SAMPLE_SHADOW_MAP(shadowMap, shadowUV, sceneDepth) (1 - shadowMap.SampleCmpLevelZero(ShadowSamplerLinear, shadowUV, sceneDepth))
|
||||||
|
#define SAMPLE_SHADOW_MAP_OFFSET(shadowMap, shadowUV, texelOffset, sceneDepth) (1 - shadowMap.SampleCmpLevelZero(ShadowSamplerLinear, shadowUV, sceneDepth, texelOffset))
|
||||||
|
#else
|
||||||
#define SAMPLE_SHADOW_MAP(shadowMap, shadowUV, sceneDepth) shadowMap.SampleCmpLevelZero(ShadowSamplerLinear, shadowUV, sceneDepth)
|
#define SAMPLE_SHADOW_MAP(shadowMap, shadowUV, sceneDepth) shadowMap.SampleCmpLevelZero(ShadowSamplerLinear, shadowUV, sceneDepth)
|
||||||
#define SAMPLE_SHADOW_MAP_OFFSET(shadowMap, shadowUV, texelOffset, sceneDepth) shadowMap.SampleCmpLevelZero(ShadowSamplerLinear, shadowUV, sceneDepth, texelOffset)
|
#define SAMPLE_SHADOW_MAP_OFFSET(shadowMap, shadowUV, texelOffset, sceneDepth) shadowMap.SampleCmpLevelZero(ShadowSamplerLinear, shadowUV, sceneDepth, texelOffset)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#if FLAX_REVERSE_Z
|
||||||
|
#define SAMPLE_SHADOW_MAP(shadowMap, shadowUV, sceneDepth) (sceneDepth > shadowMap.SampleLevel(SamplerLinearClamp, shadowUV, 0).r)
|
||||||
|
#define SAMPLE_SHADOW_MAP_OFFSET(shadowMap, shadowUV, texelOffset, sceneDepth) (sceneDepth > shadowMap.SampleLevel(SamplerLinearClamp, shadowUV, 0, texelOffset).r)
|
||||||
#else
|
#else
|
||||||
#define SAMPLE_SHADOW_MAP(shadowMap, shadowUV, sceneDepth) (sceneDepth < shadowMap.SampleLevel(SamplerLinearClamp, shadowUV, 0).r)
|
#define SAMPLE_SHADOW_MAP(shadowMap, shadowUV, sceneDepth) (sceneDepth < shadowMap.SampleLevel(SamplerLinearClamp, shadowUV, 0).r)
|
||||||
#define SAMPLE_SHADOW_MAP_OFFSET(shadowMap, shadowUV, texelOffset, sceneDepth) (sceneDepth < shadowMap.SampleLevel(SamplerLinearClamp, shadowUV, 0, texelOffset).r)
|
#define SAMPLE_SHADOW_MAP_OFFSET(shadowMap, shadowUV, texelOffset, sceneDepth) (sceneDepth < shadowMap.SampleLevel(SamplerLinearClamp, shadowUV, 0, texelOffset).r)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
float4 GetShadowMask(ShadowSample shadow)
|
float4 GetShadowMask(ShadowSample shadow)
|
||||||
{
|
{
|
||||||
return float4(shadow.SurfaceShadow, shadow.TransmissionShadow, 1, 1);
|
return float4(shadow.SurfaceShadow, shadow.TransmissionShadow, 1, 1);
|
||||||
@@ -43,7 +57,11 @@ float2 GetLightShadowAtlasUV(ShadowData shadow, ShadowTileData shadowTile, float
|
|||||||
{
|
{
|
||||||
// Project into shadow space (WorldToShadow is pre-multiplied to convert Clip Space to UV Space)
|
// Project into shadow space (WorldToShadow is pre-multiplied to convert Clip Space to UV Space)
|
||||||
shadowPosition = mul(float4(samplePosition, 1.0f), shadowTile.WorldToShadow);
|
shadowPosition = mul(float4(samplePosition, 1.0f), shadowTile.WorldToShadow);
|
||||||
|
#if FLAX_REVERSE_Z
|
||||||
|
shadowPosition.z += shadow.Bias;
|
||||||
|
#else
|
||||||
shadowPosition.z -= shadow.Bias;
|
shadowPosition.z -= shadow.Bias;
|
||||||
|
#endif
|
||||||
shadowPosition.xyz /= shadowPosition.w;
|
shadowPosition.xyz /= shadowPosition.w;
|
||||||
|
|
||||||
// UV Space -> Atlas Tile UV Space
|
// UV Space -> Atlas Tile UV Space
|
||||||
|
|||||||
Reference in New Issue
Block a user