Created
December 25, 2023 21:06
-
-
Save kiosion/55b5925e789bf7677b3a484d248512a9 to your computer and use it in GitHub Desktop.
Simple 2-sided cutout surface shader for Unity with bumpmap support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Kio/DoubleSidedCutoutSurfaceShader" | |
{ | |
Properties | |
{ | |
_Color ("Color", Color) = (1,1,1,1) | |
_MainTex ("Albedo (RGB)", 2D) = "white" {} | |
_BumpMap ("Normal Map", 2D) = "bump" {} | |
_Glossiness ("Smoothness", Range(0,1)) = 0.5 | |
_Metallic ("Metallic", Range(0,1)) = 0.0 | |
_Cutoff ("Alpha Cutoff", Range(0,1)) = 0.5 | |
} | |
SubShader | |
{ | |
Tags { "RenderType"="TransparentCutout" "Queue"="AlphaTest" } | |
LOD 200 | |
Cull Back | |
ZWrite On | |
ZTest LEqual | |
CGPROGRAM | |
#pragma surface surf Standard fullforwardshadows alpha:fade | |
#pragma target 3.0 | |
sampler2D _MainTex; | |
sampler2D _BumpMap; | |
float _Cutoff; | |
struct Input | |
{ | |
float2 uv_MainTex; | |
float2 uv_BumpMap; | |
}; | |
half _Glossiness; | |
half _Metallic; | |
fixed4 _Color; | |
UNITY_INSTANCING_BUFFER_START(Props) | |
UNITY_INSTANCING_BUFFER_END(Props) | |
void surf (Input IN, inout SurfaceOutputStandard o) | |
{ | |
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; | |
clip(c.a - _Cutoff); | |
o.Albedo = c.rgb; | |
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); | |
o.Metallic = _Metallic; | |
o.Smoothness = _Glossiness; | |
o.Alpha = c.a; | |
} | |
ENDCG | |
Tags { "RenderType" = "TransparentCutout" "Queue"="AlphaTest" } | |
Cull Front | |
ZWrite On | |
ZTest LEqual | |
CGPROGRAM | |
#pragma surface surf Standard fullforwardshadows alpha:fade | |
#pragma vertex vert | |
#pragma target 3.0 | |
sampler2D _MainTex; | |
sampler2D _BumpMap; | |
float _Cutoff; | |
struct Input | |
{ | |
float2 uv_MainTex; | |
float2 uv_BumpMap; | |
}; | |
half _Glossiness; | |
half _Metallic; | |
fixed4 _Color; | |
UNITY_INSTANCING_BUFFER_START(Props) | |
UNITY_INSTANCING_BUFFER_END(Props) | |
void vert(inout appdata_full v, out Input o) | |
{ | |
UNITY_INITIALIZE_OUTPUT(Input, o); | |
v.normal = -v.normal; // Flip normal for back face | |
} | |
void surf(Input IN, inout SurfaceOutputStandard o) | |
{ | |
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; | |
clip(c.a - _Cutoff); | |
o.Albedo = c.rgb; | |
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); | |
o.Metallic = _Metallic; | |
o.Smoothness = _Glossiness; | |
o.Alpha = c.a; | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment