-
Notifications
You must be signed in to change notification settings - Fork 4
/
waterfall.gdshader
49 lines (43 loc) · 1.65 KB
/
waterfall.gdshader
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
shader_type spatial;
render_mode specular_toon, cull_disabled;
varying vec3 world_position;
varying vec3 v_vertex;
// global uniform float water_time;
uniform sampler2D noise;
const vec3 foam_color = vec3(1.0);
const vec3 water_blue = vec3(0.1, 0.35, 0.92);
global uniform vec3 hole_punch;
void fragment() {
if (distance(world_position, hole_punch) < 13.0) {
discard;
}
if (distance(world_position, hole_punch) < 13.4) {
ALBEDO = vec3(1.0);
}
else {
float water_time = TIME;
float n = texture(noise, vec2(UV.x + TIME / 7.0, UV.y - TIME)).r;
float n2 = texture(noise, vec2(UV.x + TIME / 17.0, UV.y / 10.0 - TIME / 10.5)).r;
float n3 = texture(noise, vec2(UV.x - TIME / 60.0, UV.y / 10.0)).r;
float n4 = texture(noise, vec2(UV.x / 1.5, UV.y / 2.0 - TIME / 3.2)).r;
float n5 = texture(noise, vec2(UV.x / 1.5 + TIME / 20.0, UV.y / 2.0 - TIME / 3.5)).r;
float edge = round(abs(UV.x - 0.5) * (1.05 + n / 5.0));
float stripes = clamp((1.0 - round((n2 + n3) / 1.2)), 0.0, 1.0) * 0.2;
float stripes2 = round((n4 + n5) / 2.0) * 0.1;
ALBEDO = mix(water_blue, foam_color, clamp(edge + stripes + stripes2, 0.0, 1.0));
}
}
void vertex() {
float water_time = TIME;
world_position = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
VERTEX.x += (texture(noise, VERTEX.xz + vec2(TIME / 19.0)).r - 0.5) * 0.018;
VERTEX.z += (texture(noise, VERTEX.xz + vec2(TIME / 22.0)).r - 0.5) * 0.015;
v_vertex = VERTEX;
}
void light() {
float n = texture(noise, v_vertex.xz * 20.0).r;
DIFFUSE_LIGHT += clamp(
round(clamp(v_vertex.y / 1.5, 0.0, 1.0) * 2.0) / 1.0
+ clamp(round(dot(NORMAL, LIGHT) * (1.2 + n / 2.35)) / 2.0 + 0.35, 0.0, 1.0),
0.0, 1.0) * ATTENUATION * ALBEDO;
}