Search Unity

Sampling LightProbes from Cg shader

Discussion in 'Shaders' started by Heisenbug, Jul 7, 2014.

  1. Heisenbug

    Heisenbug

    Joined:
    Aug 31, 2012
    Posts:
    40
    Hi,

    I'm trying to sample light probes baked values from a Cg shader. This is the code:

    Code (CSharp):
    1. Shader "SHDiffuse" {
    2.     Properties {
    3.        _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    4.    }
    5.     SubShader {
    6.    
    7.         Tags { "RenderType"="Opaque" "Queue"="Geometry"}
    8.  
    9.         CGINCLUDE
    10.         #include "UnityCG.cginc"
    11.          #pragma multi_compile_fwdbase
    12.         uniform sampler2D _MainTex;
    13. uniform half4 _MainTex_ST;
    14.  
    15. struct vertIN_D
    16. {
    17.     float4 vertex : POSITION;
    18.     half3 normal : NORMAL;
    19.        half2 texcoord: TEXCOORD0;
    20. };
    21.  
    22. struct vertexOUT_D_SH
    23. {
    24.     float4 pos : SV_POSITION;
    25.     half2 uv : TEXCOORD0;
    26.     fixed3 ambient_SH : COLOR;
    27. };
    28. vertexOUT_D_SH vert_SH(vertIN_D v)
    29. {
    30.     vertexOUT_D_SH output;
    31.  
    32.     output.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    33.  
    34.     output.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    35.  
    36.     float3 normal_WS =mul((float3x3)_Object2World, SCALED_NORMAL);
    37.      output.ambient_SH =  ShadeSH9 (float4(normal_WS,1.0));
    38.     return output;
    39. }
    40. fixed4 frag_SH(vertexOUT_D_SH input) : COLOR
    41. {
    42.     return fixed4(input.ambient_SH ,1);
    43. //    return  unity_SHAg;//black
    44. //    return unity_SHAb;//black....
    45.     return col;
    46. }
    47.        
    48.         ENDCG
    49.  
    50.         Pass {
    51.             CGPROGRAM
    52.             #pragma vertex vert_SH
    53.             #pragma fragment frag_SH
    54.             ENDCG
    55.         }
    56.  
    57.     }
    58. }
    Shaders display always black color.
    I checked out that light probes are correctly baked (using unity default shaders). It seems that Spherical Harmonics coefficient are not set (maybe some pragma directive somewhere?)

    What am I missing?
     
  2. Heisenbug

    Heisenbug

    Joined:
    Aug 31, 2012
    Posts:
    40
    Never mind..I just figured it out..

    Shader is fine it was just missing the LightMode tag:

    Code (CSharp):
    1. Tags { "RenderType"="Opaque" "Queue"="Geometry" "LightMode"="ForwardBase"}