Created
May 11, 2023 07:48
-
-
Save xavierarpa/02316785542a40914ea7d0a9b9b58225 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/GradientWave2" { | |
Properties { | |
_MainTex ("Texture", 2D) = "white" {} | |
_ColorStart ("Start Color", Color) = (1, 1, 1, 1) | |
_ColorEnd ("End Color", Color) = (0, 0, 0, 1) | |
_Speed ("Speed", Range(0, 10)) = 1 | |
_WaveSpeedH ("Wave Speed Horizontal", Range(-10, 10)) = 0.5 | |
_WaveSpeedV ("Wave Speed Vertical", Range(-10, 10)) = 0.5 | |
_WaveAmountH ("Wave Amount Horizontal", Range(0, 1)) = 0.1 | |
_WaveAmountV ("Wave Amount Vertical", Range(0, 1)) = 0.1 | |
} | |
SubShader { | |
Tags {"Queue"="Transparent" "RenderType"="Transparent"} | |
Blend SrcAlpha OneMinusSrcAlpha | |
Pass { | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata { | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f { | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
}; | |
sampler2D _MainTex; | |
float4 _MainTex_ST; | |
float4 _ColorStart; | |
float4 _ColorEnd; | |
float _Speed; | |
float _WaveSpeedH; | |
float _WaveSpeedV; | |
float _WaveAmountH; | |
float _WaveAmountV; | |
v2f vert (appdata v) { | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.uv = TRANSFORM_TEX(v.uv, _MainTex); | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target { | |
float2 uv = i.uv; | |
// Add wave effect to the UV coordinates | |
uv.x += sin(uv.y * 10 + _Time.y * _WaveSpeedH) * _WaveAmountH; | |
uv.y += sin(uv.x * 10 + _Time.y * _WaveSpeedV) * _WaveAmountV; | |
// Calculate the current color based on time and gradient | |
float t = (_Time.y * _Speed) % 2; // Cycle between 0 and 2 | |
float4 color; | |
if (t < 1) { | |
color = lerp(_ColorStart, _ColorEnd, t); | |
} else { | |
color = lerp(_ColorEnd, _ColorStart, t - 1); | |
} | |
// Sample the texture and apply the color | |
fixed4 tex = tex2D(_MainTex, uv); | |
return tex * color; | |
} | |
ENDCG | |
} | |
} | |
FallBack "UI/Default" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment