Search Unity

how to make unlit shader in surface shader??

Discussion in 'Shaders' started by wisecat hun, May 31, 2013.

  1. wisecat hun

    wisecat hun

    Joined:
    Nov 22, 2012
    Posts:
    2
    hi :)

    I wanna make unlit shader in surface shader.

    this is NGUI unlit shader code

    Code (csharp):
    1.  
    2. Shader "Unlit/Transparent Colored"
    3. {
    4.     Properties
    5.     {
    6.         _MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
    7.     }
    8.    
    9.     SubShader
    10.     {
    11.         LOD 100
    12.  
    13.         Tags
    14.         {
    15.             "Queue" = "Transparent"
    16.             "IgnoreProjector" = "True"
    17.             "RenderType" = "Transparent"
    18.         }
    19.        
    20.         Pass
    21.         {
    22.             Cull Off
    23.             Lighting Off
    24.             ZWrite Off
    25.             Fog { Mode Off }
    26.             Offset -1, -1
    27.             ColorMask RGB
    28.             AlphaTest Greater .01
    29.             Blend SrcAlpha OneMinusSrcAlpha
    30.             ColorMaterial AmbientAndDiffuse
    31.            
    32.             SetTexture [_MainTex]
    33.             {
    34.                 Combine Texture * Primary
    35.             }
    36.         }
    37.     }
    38. }
    39.  
    how to convert to surface shader code above subshader code?

    or

    I wanna know how to UV scrolling in subshader code.


    Thank! :)
     
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,327
    Surface shaders are specifically for working with the lighting pipeline. Write in Cg, but don't use a surface shader.
     
  3. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    113
    use
    #pragma surface surf Unlit

    this will make unity look for a lighting function called LightingUnlit which can be implemented as follows:

    half4 LightingUnlit(SurfaceOutput s, half3 lightDir, half atten)
    {
    return half4(s.Albedo, s.Alpha);
    }


    note: you will propably only want to use this for debug purposes, if your shader is truly unlit just write a "regular" shader as Jessy mentions
     
  4. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    915
    Since OPs shader is already transparent and thus rendered in forward pass, this is probably fine. But for opaque objects, this would only render in forward too, as you can't define custom lighting functions for Deferred (unless you modify the global deferred lighting/shading file itself). In the case of deferred, one hacky workaround is to output your color to the Emission and set every other output black.
     
    Last edited: Jul 9, 2019
    Bas-Smit likes this.