evershade/Assets/Shaders/GradientShaderWithAngle.shader

64 lines
1.7 KiB
Plaintext

Shader "Custom/GradientShaderWithAngle"
{
Properties
{
_Color1 ("Start Color", Color) = (1,0,0,1)
_Color2 ("End Color", Color) = (0,0,1,1)
_Angle ("Angle", Range(0, 360)) = 0
}
SubShader
{
Tags
{
"RenderType"="Transparent" "Queue"="Overlay"
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float2 texcoord : TEXCOORD0;
float4 vertex : SV_POSITION;
};
float4 _Color1;
float4 _Color2;
float _Angle;
v2f vert(appdata_t v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = v.texcoord;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
// Convert angle to radians
float angleRad = radians(_Angle);
// Compute rotated UVs
float2 rotatedUV = float2(
cos(angleRad) * i.texcoord.x - sin(angleRad) * i.texcoord.y,
sin(angleRad) * i.texcoord.x + cos(angleRad) * i.texcoord.y
);
// Compute gradient
float gradient = rotatedUV.y; // Adjust to .x for horizontal, .y for vertical
fixed4 color = lerp(_Color1, _Color2, gradient);
return color;
}
ENDCG
}
}
FallBack "Diffuse"
}