Last active
May 31, 2022 07:30
-
-
Save nilpunch/0ec12222de89b856c59fcb772841a262 to your computer and use it in GitHub Desktop.
Billboard sprite shader.
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/Sprite Billboard" | |
{ | |
Properties | |
{ | |
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} | |
_Color ("Tint", Color) = (1,1,1,1) | |
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0 | |
[Header(Aligning)] | |
_ScaleX ("Scale X", Float) = 1.0 | |
_ScaleY ("Scale Y", Float) = 1.0 | |
[Header(Rendering)] | |
_Offset("Offset", float) = 0 | |
[Enum(UnityEngine.Rendering.CullMode)] _Culling ("Cull Mode", Int) = 2 | |
[Enum(Off,0,On,1)] _ZWrite("ZWrite", Int) = 1 | |
[Enum(UnityEngine.Rendering.CompareFunction)] _ZTest ("ZTest", Int) = 4 | |
[Enum(None,0,Alpha,1,Red,8,Green,4,Blue,2,RGB,14,RGBA,15)] _ColorMask("Color Mask", Int) = 15 | |
} | |
SubShader | |
{ | |
Tags | |
{ | |
"Queue"="Transparent" | |
"IgnoreProjector"="True" | |
"RenderType"="Transparent" | |
"PreviewType"="Plane" | |
"CanUseSpriteAtlas"="True" | |
} | |
LOD 100 | |
Cull [_Culling] | |
Offset [_Offset], [_Offset] | |
ZWrite [_ZWrite] | |
ZTest [_ZTest] | |
ColorMask [_ColorMask] | |
Lighting Off | |
Blend One OneMinusSrcAlpha | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma multi_compile _ PIXELSNAP_ON | |
#include "UnityCG.cginc" | |
struct appdata_t | |
{ | |
float4 vertex : POSITION; | |
float4 color : COLOR; | |
float2 texcoord : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
fixed4 color : COLOR; | |
float2 texcoord : TEXCOORD0; | |
}; | |
fixed4 _Color; | |
float _ScaleX; | |
float _ScaleY; | |
sampler2D _MainTex; | |
v2f vert(appdata_t IN) | |
{ | |
v2f OUT; | |
OUT.vertex = mul(UNITY_MATRIX_P, | |
mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1.0)) | |
+ float4(IN.vertex.x, IN.vertex.y, 0.0, 0.0) | |
* float4(_ScaleX, _ScaleY, 1.0, 1.0)); | |
OUT.texcoord = IN.texcoord; | |
OUT.color = IN.color * _Color; | |
#ifdef PIXELSNAP_ON | |
OUT.vertex = UnityPixelSnap (OUT.vertex); | |
#endif | |
return OUT; | |
} | |
fixed4 frag(v2f IN) : SV_Target | |
{ | |
fixed4 c = tex2D(_MainTex, in.texcoord) * IN.color; | |
return c; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment