From a13a00f2a28a2ea024dcc93eadd87ecf707f3ab4 Mon Sep 17 00:00:00 2001 From: yum Date: Wed, 4 Jun 2025 13:26:27 -0700 Subject: fix ssao --- yum_pbr.cginc | 58 +--------------------------------------------------------- 1 file changed, 1 insertion(+), 57 deletions(-) (limited to 'yum_pbr.cginc') diff --git a/yum_pbr.cginc b/yum_pbr.cginc index 6fa12bb..c3f5c4a 100644 --- a/yum_pbr.cginc +++ b/yum_pbr.cginc @@ -1,7 +1,6 @@ #ifndef __YUM_PBR #define __YUM_PBR -#include "audiolink.cginc" #include "cnlohr.cginc" #include "decals.cginc" #include "features.cginc" @@ -29,7 +28,7 @@ void propagateRoughness(in float smoothness, out float roughness_perceptual, out roughness = roughness_perceptual * roughness_perceptual; } -YumPbr GetYumPbr(v2f i) { +YumPbr GetYumPbr(v2f i, float3x3 tangentToWorld) { YumPbr result; float2 raw_uv = i.uv01.xy; @@ -135,63 +134,8 @@ YumPbr GetYumPbr(v2f i) { applyDecals(i, result.albedo, normal_tangent, result.metallic, result.smoothness); propagateRoughness(result.smoothness, result.roughness_perceptual, result.roughness); - const float3x3 tangentToWorld = float3x3(i.tangent, i.binormal, i.normal); result.normal = normalize(mul(normal_tangent, tangentToWorld)); -#if defined(_SSAO) - { - const float fragment_depth = GetDepthOfWorldPos(i.worldPos); - - float2 screen_uv; - float perspective_factor; - GetScreenUVAndPerspectiveFactor(i.worldPos, i.pos, screen_uv, perspective_factor); - - const float2 screen_px = screen_uv * _ScreenParams.xy; - const float ssao_theta = _SSAO_Noise.SampleLevel(point_repeat_s, screen_px * _SSAO_Noise_TexelSize.xy, 0) * TAU; - const float2x2 ssao_rot = float2x2( - cos(ssao_theta), -sin(ssao_theta), - sin(ssao_theta), cos(ssao_theta)); - - const float frame = ((float) AudioLinkData(ALPASS_GENERALVU + int2(1, 0)).x); - - float ssao_occlusion = 0; - const float ssao_eps = 1E-5; - [loop] - for (uint ii = 0; ii < _SSAO_Samples; ii++) { - // Compute random vector in tangent space. - // Get the index of the current pixels, on the range [0, screen_width] x - // [0, screen_height]. - // Map that onto the noise texture's pixels. Add an offset for each - // index. - float2 noise_uv = (float2(ii % _ScreenParams.x, ii * (_ScreenParams.z - 1.0f))) * _SSAO_Noise_TexelSize.xy; - float3 sample_point = _SSAO_Noise.SampleLevel(point_repeat_s, noise_uv, 0).rgb; - // Use a low discrepancy sequence to transform each sample over time. - //sample_point = frac(sample_point + PHI * frame); - sample_point.xy = 2.0 * sample_point.xy - 1.0; - sample_point.xy = mul(ssao_rot, sample_point.xy); - - // Remap to world space. - sample_point = mul(sample_point, tangentToWorld); - float scale = (ii * 1.0f) / _SSAO_Samples; - sample_point *= lerp(0.1f, 1.0f, scale * scale) * _SSAO_Radius; - - sample_point += i.worldPos; - - float sample_depth = GetDepthOfWorldPos(sample_point); - - // Depth values we're working with indicate how far you have to go along - // the view vector before you hit the object in question. Therefore, we - // care when the sample is *closer* to us than the object. - float occlusion_amount = saturate((fragment_depth - sample_depth) - _SSAO_Bias); - - ssao_occlusion += occlusion_amount; - } - - //result.albedo.xyz *= saturate(1.0 - _SSAO_Strength * ssao_occlusion / _SSAO_Samples); - result.albedo.xyz = saturate(1.0 - _SSAO_Strength * ssao_occlusion / _SSAO_Samples); - } -#endif - #if (defined(FORWARD_BASE_PASS) || defined(FORWARD_ADD_PASS)) && defined(_GLITTER) GlitterParams glitter_p; glitter_p.color = _Glitter_Color; -- cgit v1.2.3