#normals world space to view space conversion issue.

1 messages · Page 1 of 1 (latest)

proven sparrow
#

Hello, i am experiencing an issue trying to convert normals from world space to view space in a full screen renderer feature.
The issue only seems to happen when the checkbox for accurate normals is turned off.

I have attached an image, one is with the correct output so you see normal colors. the other shows everything very white.

Shader "CustomEffects/SSR"
{   
    HLSLINCLUDE

    #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
    #include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"

    #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
    #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"

    float4 Frag (Varyings input) : SV_Target
    {
        #if UNITY_REVERSED_Z
            float depth = SampleSceneDepth(input.texcoord);
        #else
            float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1.0, SampleSceneDepth(input.texcoord));
        #endif

        // reconstruct position in view space
        float4 pos_ndc = float4(input.texcoord.xy * 2 - 1, depth, 1.0);
        #if UNITY_UV_STARTS_AT_TOP
            pos_ndc.y = 1 - pos_ndc.y;
        #endif
        float4 pos_cs = mul(UNITY_MATRIX_I_P, pos_ndc);
        float3 pos_vs = pos_cs.xyz / pos_cs.w;

        float3 normal_vs = normalize(mul(UNITY_MATRIX_V, float4(SampleSceneNormals(input.texcoord), 0.0)).xyz);

        return float4(normal_vs.x, normal_vs.y, normal_vs.z, 1.0);
    }

    ENDHLSL

    SubShader
    {
        Tags 
        { 
            "RenderPipeline" = "UniversalPipeline"
            "RenderType" = "Opaque" 
        }

        LOD 100

        ZWrite Off
        Cull Off

        Pass
        {
            Name "RaymarchPass"

            HLSLPROGRAM

            #pragma vertex Vert
            #pragma fragment Frag

            #pragma multi_compile _ _GBUFFER_NORMALS_OCT

            ENDHLSL
        }
    }
}
#

I am unsure what the issue is, this formula still seems to work when accurate normals is turned on but not always when it is off. i do not remember having an issue like this in older versions like 6.0, i am on 6.3 now