114 lines
4.0 KiB
Plaintext
114 lines
4.0 KiB
Plaintext
Shader "Unlit/WaveGraph"
|
|
{
|
|
Properties
|
|
{
|
|
P1ColorIn("Color1 In", Color) = (1.0, 0.5, 0.0, 1.0)
|
|
P1ColorOut("Color1 Out", Color) = (1.0, 0.0, 0.0, 1.0)
|
|
P2ColorIn("Color2 In", Color) = (0.0, 1.0, 0.5, 1.0)
|
|
P2ColorOut("Color2 Out", Color) = (1.0, 1.0, 0.0, 1.0)
|
|
P3ColorIn("Color3 In", Color) = (0.0, 0.5, 1.0, 1.0)
|
|
P3ColorOut("Color3 Out", Color) = (0.0, 0.0, 1.0, 1.0)
|
|
P4ColorIn("Color4 In", Color) = (0.5, 0.0, 5.0, 1.0)
|
|
P4ColorOut("Color4 Out", Color) = (.5, 0.0, 0.0, 1.0)
|
|
Amplitudes("Amplitudes", Vector) = (0.1, 0.2, 0.3, 0.4)
|
|
Frequencies("Frequencies", Vector) = (40, 30, 20, 10)
|
|
[Toggle(ENABLE_MULTIWAVE)] _MULTIWAVE ("Enable multiwave feature", Float) = 0
|
|
|
|
}
|
|
SubShader
|
|
{
|
|
Tags { "RenderType"="Opaque" }
|
|
LOD 100
|
|
|
|
Pass
|
|
{
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
// make fog work
|
|
#pragma multi_compile_fog
|
|
#pragma multi_compile __ ENABLE_MULTIWAVE
|
|
|
|
#include "UnityCG.cginc"
|
|
|
|
struct appdata
|
|
{
|
|
float4 vertex : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct v2f
|
|
{
|
|
float2 uv : TEXCOORD0;
|
|
UNITY_FOG_COORDS(1)
|
|
float4 vertex : SV_POSITION;
|
|
};
|
|
|
|
half4 P1ColorIn;
|
|
half4 P1ColorOut;
|
|
half4 P2ColorIn;
|
|
half4 P2ColorOut;
|
|
half4 P3ColorIn;
|
|
half4 P3ColorOut;
|
|
half4 P4ColorIn;
|
|
half4 P4ColorOut;
|
|
half4 Amplitudes;
|
|
half4 Frequencies;
|
|
|
|
v2f vert (appdata v)
|
|
{
|
|
v2f o;
|
|
o.vertex = UnityObjectToClipPos(v.vertex);
|
|
o.uv = v.uv;
|
|
UNITY_TRANSFER_FOG(o,o.vertex);
|
|
return o;
|
|
}
|
|
|
|
|
|
half3 CalcCurve(half2 uv, float amp, float freq, half3 c1, half3 c2)
|
|
{
|
|
float curve = amp * sin((freq * uv.x) + (2.0 * _Time.z));
|
|
float lineAShape = smoothstep(1.0 - clamp(distance(curve + uv.y, 0.5), 0.0, 1.0), 1.0, 0.99);
|
|
return (1.0 - lineAShape) * lerp(c1, c2, lineAShape);
|
|
}
|
|
|
|
half3 CalcComplexCurve(half2 uv, half4 amp, half4 freq, half3 c1, half3 c2)
|
|
{
|
|
float curve = amp.x * sin((freq.x * uv.x) + (2.0 * _Time.z));
|
|
curve += amp.y * sin((freq.y * uv.x) + (2.0 * _Time.z));
|
|
curve += amp.z * sin((freq.z * uv.x) + (2.0 * _Time.z));
|
|
curve += amp.w * sin((freq.w * uv.x) + (2.0 * _Time.z));
|
|
float lineAShape = smoothstep(1.0 - clamp(distance(curve + uv.y, 0.5), 0.0, 1.0), 1.0, 0.99);
|
|
return (1.0 - lineAShape) * lerp(c1, c2, lineAShape);
|
|
}
|
|
|
|
|
|
half4 frag (v2f i) : SV_Target
|
|
{
|
|
// sample the texture
|
|
half4 col = half4(0,0,0,1);// = tex2D(_MainTex, i.uv);
|
|
/*
|
|
float curve = 0.5 * sin((40 * i.uv.x) + (2.0 * _Time.z));
|
|
|
|
float lineAShape = smoothstep(1.0 - clamp(distance(curve + i.uv.y, 0.5), 0.0, 1.0), 1.0, 0.99);
|
|
half3 lineACol = (1.0 - lineAShape) * lerp(P1ColorIn, P1ColorOut, lineAShape);
|
|
*/
|
|
#if ENABLE_MULTIWAVE
|
|
col.rgb = CalcCurve(i.uv, Amplitudes.x, Frequencies.x, P1ColorIn, P1ColorOut);
|
|
col.rgb += CalcCurve(i.uv, Amplitudes.y, Frequencies.y, P2ColorIn, P2ColorOut);
|
|
col.rgb += CalcCurve(i.uv, Amplitudes.z, Frequencies.z, P3ColorIn, P3ColorOut);
|
|
col.rgb += CalcCurve(i.uv, Amplitudes.w, Frequencies.w, P4ColorIn, P4ColorOut);
|
|
#else
|
|
col.rgb = CalcComplexCurve(i.uv, Amplitudes, Frequencies, P1ColorIn, P1ColorOut);
|
|
#endif
|
|
return col;
|
|
}
|
|
|
|
|
|
|
|
|
|
ENDCG
|
|
}
|
|
}
|
|
}
|