Created
August 8, 2017 03:01
-
-
Save kodai100/10d1ce3a76276b79ddb33eeb066d263e to your computer and use it in GitHub Desktop.
Unity Shader Bool Property Example
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 "Custom/ToggleTest" { | |
Properties{ | |
_BackgroundTex("Background Texture", 2D) = "white"{} | |
[Toggle(USE_TEXTURE)] _UseTexture("Use Texture", Float) = 0 | |
} | |
SubShader{ | |
Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" } | |
CGINCLUDE | |
#pragma target 5.0 | |
#pragma shader_feature USE_TEXTURE | |
#include "UnityCG.cginc" | |
sampler2D _BackgroundTex; | |
struct appdata { | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f { | |
float4 pos : SV_POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
v2f vert(appdata IN) { | |
v2f OUT; | |
OUT.pos = UnityObjectToClipPos(IN.vertex); | |
OUT.uv = IN.uv; | |
return OUT; | |
} | |
fixed4 frag(v2f IN) : SV_Target{ | |
float2 uv = IN.uv; | |
#ifdef USE_TEXTURE | |
return fixed4(tex2D(_BackgroundTex, uv).xyz, alpha); | |
#else | |
return fixed4(0, 1, 1, 1); | |
#endif | |
} | |
ENDCG | |
Pass { | |
Blend SrcAlpha OneMinusSrcAlpha | |
Cull Off | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment