Created
August 17, 2020 11:13
-
-
Save elringus/b4b12705633feb4164cf3dfeb819d360 to your computer and use it in GitHub Desktop.
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/UnlitAlphaRotation" | |
{ | |
Properties | |
{ | |
_MainTex("Base (RGB) Trans (A)", 2D) = "white" {} | |
_RotationY("Rotation over Y-axis", Range(0, 360)) = 45 | |
} | |
SubShader | |
{ | |
Tags | |
{ | |
"Queue" = "Transparent" | |
"IgnoreProjector" = "True" | |
"RenderType" = "Transparent" | |
} | |
LOD 100 | |
ZWrite Off | |
Blend SrcAlpha OneMinusSrcAlpha | |
Pass | |
{ | |
CGPROGRAM | |
#include "UnityCG.cginc" | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma target 2.0 | |
#pragma multi_compile_fog | |
sampler2D _MainTex; | |
float4 _MainTex_ST; | |
float _RotationY; | |
struct appdata_t | |
{ | |
float4 vertex : POSITION; | |
float2 texcoord : TEXCOORD0; | |
UNITY_VERTEX_INPUT_INSTANCE_ID | |
}; | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
float2 texcoord : TEXCOORD0; | |
UNITY_FOG_COORDS(1) | |
UNITY_VERTEX_OUTPUT_STEREO | |
}; | |
float4 RotateAroundYInDegrees(float4 vertex, float degrees) | |
{ | |
float alpha = degrees * UNITY_PI / 180.0; | |
float sina, cosa; | |
sincos(alpha, sina, cosa); | |
float2x2 m = float2x2(cosa, -sina, sina, cosa); | |
return float4(mul(m, vertex.xz), vertex.yw).xzyw; | |
} | |
v2f vert(appdata_t v) | |
{ | |
v2f o; | |
UNITY_SETUP_INSTANCE_ID(v); | |
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.vertex = RotateAroundYInDegrees(o.vertex, _RotationY); | |
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); | |
UNITY_TRANSFER_FOG(o,o.vertex); | |
return o; | |
} | |
fixed4 frag(v2f i) : SV_Target | |
{ | |
fixed4 col = tex2D(_MainTex, i.texcoord); | |
UNITY_APPLY_FOG(i.fogCoord, col); | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment