Fixes for SSAO and SSR

This commit is contained in:
Wojtek Figat
2026-01-20 18:19:34 +01:00
parent 0c5cb59875
commit cc5e4c19e1
9 changed files with 43 additions and 38 deletions

View File

@@ -81,6 +81,9 @@ int2 PerPassFullResCoordOffset;
int PassIndex;
float EffectMaxDistance;
float3 Padding0;
uint InputDepthScale;
float2 Viewport2xPixelSize;
float2 Viewport2xPixelSize_x_025; // Viewport2xPixelSize * 0.25 (for fusing add+mul into mad)
@@ -213,7 +216,7 @@ void PS_PrepareDepths(in float4 inPos : SV_POSITION, out float out0 : SV_Target0
float b = depths.z;
float a = depths.w;
#else
int3 baseCoord = int3(int2(inPos.xy) * 2, 0);
int3 baseCoord = int3(int2(inPos.xy) * InputDepthScale, 0);
float c = g_DepthSource.Load(baseCoord, int2(0, 1)).x;
float d = g_DepthSource.Load(baseCoord, int2(1, 1)).x;
float b = g_DepthSource.Load(baseCoord, int2(1, 0)).x;
@@ -230,7 +233,7 @@ void PS_PrepareDepths(in float4 inPos : SV_POSITION, out float out0 : SV_Target0
META_PS(true, FEATURE_LEVEL_ES2)
void PS_PrepareDepthsHalf(in float4 inPos : SV_POSITION, out float out0 : SV_Target0, out float out1 : SV_Target1)
{
int3 baseCoord = int3(int2(inPos.xy) * 2, 0);
int3 baseCoord = int3(int2(inPos.xy) * InputDepthScale, 0);
float a = g_DepthSource.Load(baseCoord, int2(0, 0)).x;
float d = g_DepthSource.Load(baseCoord, int2(1, 1)).x;

View File

@@ -58,9 +58,11 @@ float3 ScreenSpaceReflectionDirection(float2 uv, GBufferSample gBuffer, float3 v
// Returns: xy: hitUV, z: hitMask, where hitUV is the result UV of hit pixel, hitMask is the normalized sample weight (0 if no hit).
float3 TraceScreenSpaceReflection(float2 uv, GBufferSample gBuffer, Texture2D depthBuffer, float3 viewPos, float4x4 viewMatrix, float4x4 viewProjectionMatrix, float stepSize, float maxSamples = 20, bool temporal = false, float temporalTime = 0.0f, float worldAntiSelfOcclusionBias = 0.1f, float brdfBias = 0.82f, float drawDistance = 5000.0f, float roughnessThreshold = 0.4f, float edgeFade = 0.1f)
{
#ifndef SSR_SKIP_INVALID_CHECK
// Reject invalid pixels
if (gBuffer.ShadingModel == SHADING_MODEL_UNLIT || gBuffer.Roughness > roughnessThreshold || gBuffer.ViewPos.z > drawDistance)
return 0;
#endif
// Calculate view space normal vector
float3 normalVS = mul(gBuffer.Normal, (float3x3)viewMatrix);

View File

@@ -1,5 +1,7 @@
// Copyright (c) Wojciech Figat. All rights reserved.
#define SSR_SKIP_INVALID_CHECK 1
#include "./Flax/Common.hlsl"
#include "./Flax/LightingCommon.hlsl"
#include "./Flax/ReflectionsCommon.hlsl"
@@ -13,7 +15,7 @@
#define SSR_REDUCE_HIGHLIGHTS 1
// Enable/disable blurring SSR during sampling results and mixing with reflections buffer
#define SSR_MIX_BLUR 1
#define SSR_MIX_BLUR (!defined(PLATFORM_ANDROID) && !defined(PLATFORM_IOS) && !defined(PLATFORM_SWITCH))
META_CB_BEGIN(0, Data)
GBufferData GBuffer;
@@ -273,13 +275,11 @@ float4 PS_MixPass(Quad_VS2PS input) : SV_Target0
float4 ssr = Texture0.SampleLevel(SamplerLinearClamp, input.TexCoord, 0);
#if SSR_MIX_BLUR
ssr += Texture0.SampleLevel(SamplerLinearClamp, input.TexCoord + float2(0, SSRtexelSize.y), 0);
ssr += Texture0.SampleLevel(SamplerLinearClamp, input.TexCoord - float2(0, SSRtexelSize.y), 0);
ssr += Texture0.SampleLevel(SamplerLinearClamp, input.TexCoord + float2(SSRtexelSize.x, 0), 0);
ssr += Texture0.SampleLevel(SamplerLinearClamp, input.TexCoord - float2(SSRtexelSize.x, 0), 0);
ssr *= (1.0f / 5.0f);
#endif
ssr.a = saturate(ssr.a);