Search Unity

Trying to read a normal map in a custom URP shader

Discussion in 'Shaders' started by MadSwag, Aug 5, 2020.

  1. MadSwag

    MadSwag

    Joined:
    Oct 20, 2018
    Posts:
    4
    Hello, recently I have started working with the new URP pipeline and I'm having some issues trying to read normal maps. I learned from Catlike coding bump mapping tutorial for SRP but it seems that the output in URP is different and following is method yields me a different value.

    For testing I wrote the same shader in Shader graph. Below I add how I'm currently sampling normals in my PS from a texture, note that I'm rendering them on a flat plane aligned with the x,z axis so I'm not translating them from TS:

    Below I show the code snippet of my PS:

    half4 PSPass(PSData input) : SV_Target
    {
    // Calculate normal textures.
    float2 NormalCalmUvs = TRANSFORM_TEX(input.uv, _NormalCalmTexture) * 1/2;
    float3 CalmWaterNormal = UnpackNormal(tex2D(_NormalCalmTexture, NormalCalmUvs));
    return float4(normalWS, 1.0f);
    }

    Can somebody help me and tell what I'm doing wrong? I seem to be unable to fetch the correct values for the normal.

    Both shaders are using the same texture so it doesn't seem a texture issue.

    Sorry if this is quite a basic question but I have not found any shaders that are sampling a normal texture without converting it from TS, and, as far as I know, this should work flawlessly in my case.
     
    dccoo likes this.