Fix applying AO twice for lighting in Forward shading and use correct specular occlusion on reflections

#3717
This commit is contained in:
Wojtek Figat
2026-02-10 22:50:32 +01:00
parent 9c8023d64f
commit e851efa0a8
3 changed files with 12 additions and 5 deletions

View File

@@ -142,11 +142,11 @@ void PS_Forward(
#endif
#endif
light.rgb += reflections * GetReflectionSpecularLighting(ViewPos, gBuffer) * light.a;
light.rgb += reflections * GetReflectionSpecularLighting(ViewPos, gBuffer) * light.a;
#endif
// Add lighting (apply ambient occlusion)
output.rgb += light.rgb * gBuffer.AO;
// Add lighting
output.rgb += light.rgb;
#endif

View File

@@ -79,7 +79,7 @@ float4 PS_CombinePass(Quad_VS2PS input) : SV_Target0
// Calculate specular color
float3 specularColor = GetSpecularColor(gBuffer);
// Calculate reflecion color
// Calculate reflection color
float3 V = normalize(gBufferData.ViewPos - gBuffer.WorldPos);
float NoV = saturate(dot(gBuffer.Normal, V));
reflections *= EnvBRDF(PreIntegratedGF, specularColor, gBuffer.Roughness, NoV);

View File

@@ -48,10 +48,17 @@ float4 SampleReflectionProbe(float3 viewPos, TextureCube probe, ProbeData data,
// Calculates the reflective environment lighting to multiply the raw reflection color for the specular light (eg. from Env Probe or SSR).
float3 GetReflectionSpecularLighting(float3 viewPos, GBufferSample gBuffer)
{
// Calculate reflection color
float3 specularColor = GetSpecularColor(gBuffer);
float3 V = normalize(viewPos - gBuffer.WorldPos);
float NoV = saturate(dot(gBuffer.Normal, V));
return EnvBRDFApprox(specularColor, gBuffer.Roughness, NoV);
float3 reflections = EnvBRDFApprox(specularColor, gBuffer.Roughness, NoV);
// Apply specular occlusion
float roughnessSq = gBuffer.Roughness * gBuffer.Roughness;
reflections *= GetSpecularOcclusion(NoV, roughnessSq, gBuffer.AO);
return reflections;
}
#endif