Search Unity

Confusion in visualizing normal.

Discussion in 'Shaders' started by oozwal, Dec 22, 2020.

  1. oozwal

    oozwal

    Joined:
    Sep 6, 2018
    Posts:
    2
    I am new to writing shaders in unity and I wanted to just visualize the normal in a standard surface shader but why am I always getting red color?
     

    Attached Files:

  2. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    328
    Which Unity version do you use ?
    Can you insert all shader code, maybe something else is broken.
    It seems like a bug.

    For test, I checked this simple normal visualiser, and it works OK with built-in Sphere gameobject:

    Code (CSharp):
    1. Shader "Show Normals"
    2. {
    3.     Subshader
    4.     {
    5.         Tags { "RenderType" = "Opaque" }
    6.         CGPROGRAM
    7.         #pragma surface SurfaceShader Standard vertex:VertexShaderFunction
    8.  
    9.         struct Input
    10.         {
    11.             float3 color;
    12.         };
    13.        
    14.         void VertexShaderFunction (inout appdata_full v, out Input o)
    15.         {
    16.             o.color = UnityObjectToWorldDir(v.normal);
    17.         }
    18.  
    19.         void SurfaceShader (Input IN, inout SurfaceOutputStandard o)
    20.         {
    21.             o.Albedo = IN.color;
    22.         }
    23.  
    24.         ENDCG
    25.     }
    26. }
    upload_2020-12-22_21-10-31.png