Search Unity

Surface Shader Unlit Lightmap

Discussion in 'Shaders' started by Bravo_cr, Mar 26, 2015.

  1. Bravo_cr

    Bravo_cr

    Joined:
    Jul 19, 2012
    Posts:
    148
    Hi,

    We have been using an unlit light map shader for ages. Now with the new Unity 5 global illumination only Surface shaders are use correctly for calculating light bounces. Because of that we have made an Unlit light map shader write in Surface Shaders:

    Code (CSharp):
    1. Shader "Reborn/Unlit/Unlit Surface Shaders (Lightmap)" {
    2. Properties {
    3.  
    4.     _MainTex ("Base (RGB) Skin Mask (A)", 2D) = "white" {}
    5.  
    6.    
    7. }
    8.  
    9. SubShader {
    10.     Tags { "RenderType"="Opaque" "Queue" = "Geometry"}
    11.    
    12. CGPROGRAM
    13.  
    14.  
    15. #pragma surface surf NoLighting fullforwardshadows
    16.  
    17.  
    18.  
    19.     sampler2D _MainTex;
    20.  
    21.  
    22.  
    23.     struct Input {
    24.         half2 uv_MainTex;
    25.    
    26.     };
    27.          
    28.      fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten)
    29.      {
    30.          fixed4 c;
    31.          c.rgb = s.Albedo;
    32.          c.a = s.Alpha;
    33.          return c;
    34.      }
    35.  
    36.  
    37.     void surf (Input IN, inout SurfaceOutput o)
    38.     {  
    39.         o.Albedo = tex2D(_MainTex, IN.uv_MainTex);
    40.        
    41.     }
    42. ENDCG
    43. }
    44.  
    45. Fallback "Mobile/VertexLit"
    46. }

    This work great when there is no lightmap in the scene. As soon as you have the lightmap working, this shader IS affected by lights marked as Realtime. It seems related to the bounce intensity. So if an object is marked as static and the lightmap is processed, realtime lights with bounce value higher than 0 DO affect the object. If the object is not marked as static the shader is 100% unlit.

    Is there a way to make a true Unlity surface shader?