Last active
July 14, 2021 14:08
-
-
Save xtiandiaz/3c344be0eafd518ee698e103d7d99abf to your computer and use it in GitHub Desktop.
Unity shader for a double-sided card
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 "Card" | |
{ | |
Properties | |
{ | |
_Color ("Color", Color) = (0, 0, 0, 1) | |
_FrontTex ("Front Texture", 2D) = "white" {} | |
_BackTex ("Back Texture", 2D) = "white" {} | |
} | |
SubShader | |
{ | |
Tags | |
{ | |
"Queue" = "Transparent" | |
"RenderType" = "Transparent" | |
} | |
Cull Off | |
Blend SrcAlpha OneMinusSrcAlpha | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma target 3.0 | |
#include "UnityCG.cginc" | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
float2 texcoord : TEXCOORD0; | |
}; | |
float4 _Color; | |
sampler2D _FrontTex; | |
sampler2D _BackTex; | |
float4 _FrontTex_ST; | |
float4 _BackTex_ST; | |
v2f vert(appdata_base v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.texcoord = v.texcoord; | |
return o; | |
} | |
fixed4 frag(v2f i, fixed facing : VFACE) : SV_TARGET | |
{ | |
if (facing > 0) | |
return tex2D(_FrontTex, i.texcoord) * _Color; | |
else | |
return tex2D(_BackTex, i.texcoord) * _Color; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: Apply to e.g., a quad via custom material. To avoid having separate materials per card, use Material Property Blocks.