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): Shader "mShaders/Holes1" { Properties { _MainTex ("Texture (RGB)", 2D) = "white" {} _SliceGuide ("Slice Guide (RGB)", 2D) = "white" {} _SliceAmount ("Slice Amount", Range(0.0, 1.0)) = 0.9 } SubShader { Tags { "RenderType" = "Opaque" } Cull Off CGPROGRAM //if you're not planning on using shadows, remove "addshadow" for better performance #pragma surface surf Lambert struct Input { float2 uv_MainTex; float2 uv_SliceGuide; float _SliceAmount; }; sampler2D _MainTex; sampler2D _SliceGuide; float _SliceAmount; void surf (Input IN, inout SurfaceOutput o) { clip(tex2D (_SliceGuide, IN.uv_SliceGuide).rgb - _SliceAmount); o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb; } ENDCG } Fallback "Diffuse" } SOURCE: http://unitycoder.com/blog/2011/08/09/painting-holes-with-shader-v1-0/
Code (CSharp): Shader "mShaders/HolesUnlit" { Properties { _MainTex ("Texture (RGB)", 2D) = "white" {} _SliceGuide ("Slice Guide (RGB)", 2D) = "white" {} _SliceAmount ("Slice Amount", Range(0.0, 1.0)) = 0.9 } SubShader { Tags { "RenderType" = "Opaque" } Cull Off CGPROGRAM //if you're not planning on using shadows, remove "addshadow" for better performance #pragma surface surf Lambert struct Input { float2 uv_MainTex; float2 uv_SliceGuide; float _SliceAmount; }; sampler2D _MainTex; sampler2D _SliceGuide; float _SliceAmount; void surf (Input IN, inout SurfaceOutput o) { clip(tex2D (_SliceGuide, IN.uv_SliceGuide).rgb - _SliceAmount); o.Emission = tex2D (_MainTex, IN.uv_MainTex).rgb; } ENDCG } Fallback "Diffuse" }
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
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.