Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

_worldSpaceLightPos0 is always 0

Discussion in 'Shaders' started by jatobu, Sep 29, 2012.

  1. jatobu

    jatobu

    Joined:
    Nov 12, 2009
    Posts:
    21
    Hi,

    I'm trying to read a directional light direction from a fragment shader, but its always 0's... I have the Directional light in the hierarchy, and I'm including the "LightMode" = "ForwardBase" tag to the pass to ensure it gets updated by the Mesh Renderer...

    I've simplified my code to this:

    Code (csharp):
    1.  
    2. Shader "NV Shaders/ComicStyleNoSurfaceFromGroundUp" {
    3.     SubShader {
    4.         Pass{
    5.             Tags { "LightMode" = "ForwardBase" }
    6.        
    7.             CGPROGRAM
    8.             #pragma vertex vert
    9.             #pragma fragment frag
    10.             #include "UnityCG.cginc"
    11.                
    12.             struct vertexInput {
    13.                 float4 vertex : POSITION;
    14.             };
    15.        
    16.             struct vertexOutput {
    17.                 float4 pos : SV_POSITION;
    18.             };
    19.  
    20.             vertexOutput vert( vertexInput v )
    21.             {
    22.                 vertexOutput o;
    23.                
    24.                 o.pos  = mul( UNITY_MATRIX_MVP, v.vertex );
    25.                
    26.                 return o;
    27.             }
    28.  
    29.             half4 frag( vertexOutput i ) : COLOR
    30.             {
    31.                 float3 lightDir = normalize( float3(_WorldSpaceLightPos0 ) );
    32.  
    33.                 return half4( lightDir, 1 );
    34.             }
    35.             ENDCG
    36.         }
    37.     }
    38. }
    39.  
    but the mesh is always drawn in black color...

    do you have any idea what could be wrong or what could I be missing?

    Thanks!
     
  2. Martin-Kraus

    Martin-Kraus

    Joined:
    Feb 18, 2011
    Posts:
    617
    Do you have a directional light source without cookie in your scene?

    EDIT: And are you using forward rendering?
     
    Last edited: Sep 30, 2012
  3. jatobu

    jatobu

    Joined:
    Nov 12, 2009
    Posts:
    21
    Thanks Mark,

    that did it! =)

    +1