Kastell/Assets/Shaders/Level Sine Background.shader
Gerard Gascón f5c1616018 init
2025-02-02 23:45:04 +01:00

98 lines
No EOL
2.7 KiB
Text

Shader "Geri/Level Sine Background"
{
Properties
{
[PerRendererData] _Color1 ("Color 1", Color) = (1,1,1,1)
[PerRendererData] _Color2 ("Color 2", Color) = (0,0,0,1)
[PerRendererData] _Opacity ("Opacity", Float) = 1
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Cull Off
Lighting Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
Name "Default"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc"
#pragma multi_compile_local _ UNITY_UI_CLIP_RECT
#pragma multi_compile_local _ UNITY_UI_ALPHACLIP
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
fixed4 _Color1;
fixed4 _Color2;
float _Opacity;
v2f vert(appdata_t v)
{
v2f OUT;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.vertex = v.vertex;
OUT.texcoord = v.texcoord;
return OUT;
}
float2 rotate_uv(float2 uv, float rotation)
{
rotation = radians(rotation);
float s = sin(rotation);
float c = cos(rotation);
float2x2 rotation_matrix = float2x2(c, -s, s, c);
rotation_matrix *= 0.5;
rotation_matrix += 0.5;
rotation_matrix = rotation_matrix * 2 - 1;
uv.xy = mul(uv.xy, rotation_matrix);
return uv;
}
fixed4 frag(v2f IN) : SV_Target
{
IN.texcoord = rotate_uv(IN.texcoord, -45);
bool is_color_1 = int(floor(cos(IN.texcoord.x) + 2 * IN.texcoord.y)) % 2 == 0;
half4 color = _Color1 * is_color_1 + _Color2 * (1 - is_color_1);
color.a = _Opacity;
#ifdef UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
#endif
return color;
}
ENDCG
}
}
}