diff options
| author | yum <yum.food.vr@gmail.com> | 2025-06-04 13:26:27 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-06-04 13:35:28 -0700 |
| commit | a13a00f2a28a2ea024dcc93eadd87ecf707f3ab4 (patch) | |
| tree | 4a997310fbf07d54ceeb900beba97445d9648cd5 /cnlohr.cginc | |
| parent | b76cd52014e7f5a1b6c19a8be66d39cd28199bdc (diff) | |
fix ssao
Diffstat (limited to 'cnlohr.cginc')
| -rw-r--r-- | cnlohr.cginc | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/cnlohr.cginc b/cnlohr.cginc index b01bbce..cd98f08 100644 --- a/cnlohr.cginc +++ b/cnlohr.cginc @@ -82,24 +82,21 @@ void GetScreenUVAndPerspectiveFactor(float3 worldPos, float4 clipPos, out float2 }
#if defined(_SSAO)
-float GetDepthOfWorldPos(float3 worldPos)
+float GetDepthOfWorldPos(float3 worldPos, out float2 debug)
{
float3 full_vec_eye_to_geometry = worldPos - _WorldSpaceCameraPos;
- float4 objPos = mul(unity_WorldToObject, float4(worldPos, 1));
+ float3 objPos = mul(unity_WorldToObject, float4(worldPos, 1));
float4 clipPos = UnityObjectToClipPos(objPos);
+ float4 screenPos = ComputeScreenPos(clipPos);
- float2 suv = clipPos * float2(0.5, 0.5 * _ProjectionParams.x);
- float2 screenPos = TransformStereoScreenSpaceTex(suv + 0.5 * clipPos.w, clipPos.w);
+ const float2 screen_uv = screenPos.xy / screenPos.w;
+ float zDepthFromMap = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, screen_uv);
+ float linearZ =
+ GetLinearZFromZDepth_WorksWithMirrors(zDepthFromMap, screen_uv);
+ linearZ = min(1E3, linearZ);
- float perspective_divide = 1.0f / clipPos.w;
- float perspective_factor = length(full_vec_eye_to_geometry * perspective_divide);
- float2 screen_uv = screenPos.xy * perspective_divide;
-
- float eye_depth_world =
- GetLinearZFromZDepth_WorksWithMirrors(
- SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, screen_uv),
- screen_uv) * perspective_factor;
- return eye_depth_world;
+ debug = screen_uv;
+ return linearZ;
}
#endif
|
