This seems like a theoretically simple shader but I can't find it anywhere! Like a cutout diffuse accept with totally flat shading. Where can I find it/how can I make it?
I think this is what you're looking for: Code (csharp): Shader "Unlit/Transparent Cutout (Shadow)" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 } SubShader { Tags { "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" } LOD 100 Lighting Off CGPROGRAM #pragma surface surf Lambert alphatest:_Cutoff sampler2D _MainTex; fixed4 _Color; struct Input { float2 uv_MainTex; }; void surf (Input IN, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; o.Emission = c.rgb; o.Alpha = c.a; } ENDCG } Fallback "Transparent/Cutout/VertexLit" }
That's exactly what I'm looking for! I can't tell you how much time a spent searching for this. Thank you so much Peter77, you've really helped me out. You're assets in the store look very useful, and in a modest attempt to repay you I've purchased your Texture Overview plugin. You've helped me in two big ways today because that texture overview is friggin useful! That's so awesome how you can see all the textures in your scene and where your memory is going. I'll certainly drop a good review.
I did have one more question for you Peter or anyone who may know: How would I go about making this shader receive shadows as well as cast them?
My first thought was it's not going to happen to cast shadow on an unlit object, but then I found this thread over at polycount where an unlit cast/receive shadow shader can be found. I only added the alpha cut-out part and changed the tags. I'm not really certain what it does in detail to be honest, but it seems to work. Code (csharp): Shader "Unlit/Transparent Cutout (Shadow)" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB)", 2D) = "white" {} _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 } SubShader { Tags {"Queue" = "AlphaTest" "RenderType" = "TransparentCutout"} Pass { Tags {"LightMode" = "ForwardBase"} CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile_fwdbase #pragma fragmentoption ARB_fog_exp2 #pragma fragmentoption ARB_precision_hint_fastest #pragma alphatest:_Cutoff #include "UnityCG.cginc" #include "AutoLight.cginc" struct v2f { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; LIGHTING_COORDS(1,2) }; v2f vert (appdata_tan v) { v2f o; o.pos = mul( UNITY_MATRIX_MVP, v.vertex); o.uv = v.texcoord.xy; TRANSFER_VERTEX_TO_FRAGMENT(o); return o; } sampler2D _MainTex; float _Cutoff; fixed4 _Color; fixed4 frag(v2f i) : COLOR { fixed4 color = tex2D(_MainTex, i.uv); clip(color.a - _Cutoff); fixed atten = LIGHT_ATTENUATION(i); // Light attenuation + shadows. //fixed atten = SHADOW_ATTENUATION(i); // Shadows ONLY. return color * atten * _Color; } ENDCG } Pass { Tags {"LightMode" = "ForwardAdd"} Blend One One CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile_fwdadd_fullshadows #pragma fragmentoption ARB_fog_exp2 #pragma fragmentoption ARB_precision_hint_fastest #include "UnityCG.cginc" #include "AutoLight.cginc" struct v2f { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; LIGHTING_COORDS(1,2) }; v2f vert (appdata_tan v) { v2f o; o.pos = mul( UNITY_MATRIX_MVP, v.vertex); o.uv = v.texcoord.xy; TRANSFER_VERTEX_TO_FRAGMENT(o); return o; } sampler2D _MainTex; float _Cutoff; fixed4 _Color; fixed4 frag(v2f i) : COLOR { fixed4 color = tex2D(_MainTex, i.uv); clip(color.a - _Cutoff); fixed atten = LIGHT_ATTENUATION(i); // Light attenuation + shadows. //fixed atten = SHADOW_ATTENUATION(i); // Shadows ONLY. return tex2D(_MainTex, i.uv) * atten * _Color; } ENDCG } } Fallback "Transparent/Cutout/VertexLit" }
Man I was scouring polycount too but didn't find this. Ah, well I can see how this is going to end up being more complicated than I'd initially thought, since receiving shadows gives away the flat nature of a far lod. I think I'm going to have to go with a two material solution, where the trunks get full shading and shadows and the leaves only cast shadows. I really appreciate your help.
Hi, this shader is so close to what I need, except the cutout edge isn't antialiased Would you know how I could achieve the antialiased edge that the legacy shader 'transparent/cutout/soft edge unlit' has? thanks
This shader is very close to what I need. I am using this shader on a quad with a tiled cloud texture. The alpha cutoff and shadows are great! Problem is, the resulting clouds are solid white with very hard edges. How could I edit this shader to keep the texture instead of the solid white, and with a soft edge on the alpha cutoff? I've attached an image of the ideal shader I wish to achieve. Thanks!