Search Unity

Isn't light pass the final pass in Unity shader ?

Discussion in 'Shaders' started by mungtion, Nov 26, 2015.

  1. mungtion

    mungtion

    Joined:
    Apr 18, 2015
    Posts:
    13
    Hi there,

    I've been testing some shader code.

    I'll show you the code

    -----------------------------------------------------------------------------------------------------------------------------
    Code (CSharp):
    1. Shader "Custom/TestLightShader" {
    2.     Properties {
    3.         _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    4.     }
    5.     SubShader {
    6.         Tags { "RenderType"="Opaque" }
    7.         LOD 250
    8.     CGPROGRAM
    9.     #pragma surface surf TestBlinnPhong exclude_path:prepass nolightmap noforwardadd halfasview interpolateview
    10.  
    11.     inline fixed4 LightingTestBlinnPhong(SurfaceOutput s, fixed3 lightDir, fixed3 halfDir, fixed atten)
    12.     {
    13.         fixed4 c;
    14.         c.rgb = 0;
    15.         return c;
    16.     }
    17.  
    18.     sampler2D _MainTex;
    19.  
    20.     struct Input {
    21.         float2 uv_MainTex;
    22.     };
    23.  
    24.     void surf (Input IN, inout SurfaceOutput o) {
    25.         fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    26.         o.Albedo = tex.rgb;
    27.         o.Gloss = tex.a;
    28.         o.Alpha = tex.a;
    29.     }
    30.     ENDCG
    31.     }
    32.  
    33.     FallBack "Mobile/VertexLit"
    34. }
    -----------------------------------------------------------------------------------------------------------------------------

    I added LightingTestBlinnPhong Func.
    It just make zero rgb value as test.

    I thought final color is black.

    but I got a little darkness with basetexture ( 'SurfaceOutput s' just have basetexture )

    like this.

    lighting.jpg


    Lighting pass is final pass from i know.
    i dont know, what is wrong.

    I think, final color is calculated in lighting function when I use forward render pass.
    So, If I set color in lightingfunc, it must shows.

    How should i do ?

    Anyone help me, any answer, Advice and comment.

    Thank you.
     
  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    The ambient lighting passes in the surface shader will be using your texture, though.
     
  3. mungtion

    mungtion

    Joined:
    Apr 18, 2015
    Posts:
    13
    Thank you for your answer.

    Is The ambient lighting passes processed after light pass ?

    And Can i make custom ambient lighting func ?

    thank you. have a nice day ^^
     
  4. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    The ambient lighting happens as part of the forward base pass, you can turn the various functions off by adding the terms here to your #pragma surface line and writing your own into the forward base pass;
    (Code generation options segment)
    http://docs.unity3d.com/Manual/SL-SurfaceShaders.html
     
  5. mungtion

    mungtion

    Joined:
    Apr 18, 2015
    Posts:
    13