-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSine Vertex Displacement.shader
75 lines (63 loc) · 2.09 KB
/
Sine Vertex Displacement.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Shader "AdrianMiasik/Examples/Sine Vertex Displacement"
{
Properties
{
_Frequency("Frequency", float) = 20
_Speed("Speed", float) = 0.5
_Amplitude("Amplitude", float) = 0.1
_Axis("Axis", Vector) = (0.1, 1, 0.1)
_Color("Axis", Color) = (0.23, 0.95, 0.33, 1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
float _Frequency;
float _Speed;
float _Amplitude;
float3 _Axis;
float4 _Color;
// Source: https://docs.unity3d.com/Packages/[email protected]/manual/Combine-Node.html
float4 Unity_Combine_float(float R, float G, float B, float A)
{
return float4(R, G, B, A);
}
v2f vert (appdata v)
{
float time = _Speed * _Time * 200; // 200 = Magic number that aligns our speed with the shadergraph variant of this shader. :(
// Wave
float4 sineWave = sin(time + v.vertex * _Frequency) * _Amplitude;
// Wave enabled per axis
float3 waveX = sineWave * _Axis.r;
float3 waveY = sineWave * _Axis.g;
float3 waveZ = sineWave * _Axis.b;
// Composition
float4 modifiedVerts = Unity_Combine_float(v.vertex.x + waveX, v.vertex.y + waveY, v.vertex.z + waveZ, 1);
v2f o;
o.vertex = UnityObjectToClipPos(modifiedVerts);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
return _Color;
}
ENDCG
}
}
}