Search Unity

make shader unlit

Discussion in 'Shaders' started by will_brett, Aug 20, 2014.

  1. will_brett

    will_brett

    Joined:
    Feb 16, 2013
    Posts:
    208
    Hi there,

    Firstly Im really not familiar with shaders. Up until now I have only been using existing shaders so what I want to ask may be impossible.

    I want to change a shader I found online to be unlit. I had a go by add lighting off but this made no difference. Can anyone help?

    Thank you

    Code (CSharp):
    1.   Shader "mShaders/Holes1" {
    2.     Properties {
    3.       _MainTex ("Texture (RGB)", 2D) = "white" {}
    4.       _SliceGuide ("Slice Guide (RGB)", 2D) = "white" {}
    5.       _SliceAmount ("Slice Amount", Range(0.0, 1.0)) = 0.9
    6.     }
    7.     SubShader {
    8.       Tags { "RenderType" = "Opaque" }
    9.       Cull Off
    10.       CGPROGRAM
    11.       //if you're not planning on using shadows, remove "addshadow" for better performance
    12.       #pragma surface surf Lambert
    13.       struct Input {
    14.                    
    15.           float2 uv_MainTex;
    16.           float2 uv_SliceGuide;
    17.           float _SliceAmount;
    18.       };
    19.       sampler2D _MainTex;
    20.       sampler2D _SliceGuide;
    21.       float _SliceAmount;
    22.       void surf (Input IN, inout SurfaceOutput o) {
    23.           clip(tex2D (_SliceGuide, IN.uv_SliceGuide).rgb - _SliceAmount);
    24.           o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    25.       }
    26.       ENDCG
    27.     }
    28.     Fallback "Diffuse"
    29.   }
    SOURCE: http://unitycoder.com/blog/2011/08/09/painting-holes-with-shader-v1-0/
     
  2. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Code (CSharp):
    1.   Shader "mShaders/HolesUnlit" {
    2.     Properties {
    3.       _MainTex ("Texture (RGB)", 2D) = "white" {}
    4.       _SliceGuide ("Slice Guide (RGB)", 2D) = "white" {}
    5.       _SliceAmount ("Slice Amount", Range(0.0, 1.0)) = 0.9
    6.     }
    7.     SubShader {
    8.       Tags { "RenderType" = "Opaque" }
    9.       Cull Off
    10.       CGPROGRAM
    11.       //if you're not planning on using shadows, remove "addshadow" for better performance
    12.       #pragma surface surf Lambert
    13.       struct Input {
    14.                  
    15.           float2 uv_MainTex;
    16.           float2 uv_SliceGuide;
    17.           float _SliceAmount;
    18.       };
    19.       sampler2D _MainTex;
    20.       sampler2D _SliceGuide;
    21.       float _SliceAmount;
    22.       void surf (Input IN, inout SurfaceOutput o) {
    23.           clip(tex2D (_SliceGuide, IN.uv_SliceGuide).rgb - _SliceAmount);
    24.           o.Emission = tex2D (_MainTex, IN.uv_MainTex).rgb;
    25.       }
    26.       ENDCG
    27.     }
    28.     Fallback "Diffuse"
    29.   }
     
  3. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    If you don't need lighting, you're probably much better off avoiding surface shaders. Their primary purpose is to make it easy to support Unity's increasingly-complex lighting pipeline.

    For unlit shaders, a vertex/fragment shader will be more efficient and flexible. This template is a good start: http://wiki.unity3d.com/index.php/Vertex/Fragment_Template
     
  4. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Daniel is right - I supposed you might need shadows for some reason, if not, the template he pointed is a very good start for making Cg shaders.
     
  5. will_brett

    will_brett

    Joined:
    Feb 16, 2013
    Posts:
    208
    thanks everyone
     
  6. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Right: shadow casting support can be added with Fallback "VertexLit" at the end of the Shader block.