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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
[gd_scene load_steps=10 format=2]
[sub_resource type="Shader" id=1]
code = "shader_type spatial;
render_mode unshaded;
uniform vec4 deep_color : hint_color;
uniform vec4 shallow_color : hint_color = vec4(1);
uniform float refraction_speed = 0.25;
uniform float refraction_strength = 1.0;
uniform float foam_amount = 1.0;
uniform float foam_cutoff = 1.0;
uniform vec4 foam_color : hint_color = vec4(1);
uniform float displacement_strength = 0.25;
uniform float depth_distance = 1.0;
uniform vec2 movement_direction = vec2(1,0);
uniform sampler2D refraction_noise : hint_normal;
uniform sampler2D foam_noise : hint_black_albedo;
uniform sampler2D displacement_noise : hint_black;
void vertex() {
float displacement = textureLod(
displacement_noise,
UV + (TIME * movement_direction) * refraction_speed,
0.0).r * 2.0 - 1.0;
VERTEX.y += displacement * displacement_strength;
}
void fragment() {
vec2 uv = SCREEN_UV + refraction_strength
* (texture(refraction_noise, UV + (TIME * movement_direction) * refraction_speed).rg
* 2.0 - 1.0);
float real_depth = texture(DEPTH_TEXTURE, SCREEN_UV).r * 2.0 - 1.0;
real_depth = PROJECTION_MATRIX[3][2] / (real_depth + PROJECTION_MATRIX[2][2]) + VERTEX.z;
// Get the raw linear depth from the depth texture into a [-1, 1] range
float depth = texture(DEPTH_TEXTURE, uv).r * 2.0 - 1.0;
// Recreate linear depth of the intersecting geometry using projection matrix, and subtract the vertex of the sphere
depth = PROJECTION_MATRIX[3][2] / (depth + PROJECTION_MATRIX[2][2]) + VERTEX.z;
depth = max(depth, real_depth);
float intersection = clamp(depth / foam_amount, 0, 1) * foam_cutoff;
vec4 out_color = mix(shallow_color, deep_color, clamp((depth / depth_distance), 0, 1));
vec4 scene_color = texture(SCREEN_TEXTURE, uv);
out_color = mix(scene_color, out_color, out_color.a);
vec3 foam = step(intersection,
texture(foam_noise, UV + (TIME * movement_direction) * refraction_speed).rgb)
* foam_color.rgb;
ALBEDO = out_color.rgb + foam;
}"
[sub_resource type="OpenSimplexNoise" id=4]
[sub_resource type="NoiseTexture" id=5]
flags = 3
width = 1024
height = 1024
noise = SubResource( 4 )
[sub_resource type="OpenSimplexNoise" id=6]
[sub_resource type="NoiseTexture" id=7]
width = 1024
height = 1024
noise = SubResource( 6 )
[sub_resource type="OpenSimplexNoise" id=8]
[sub_resource type="NoiseTexture" id=9]
width = 1024
height = 1024
noise = SubResource( 8 )
[sub_resource type="ShaderMaterial" id=2]
shader = SubResource( 1 )
shader_param/deep_color = Color( 0.00784314, 0, 0.196078, 1 )
shader_param/shallow_color = Color( 0.65098, 1, 1, 1 )
shader_param/refraction_speed = 0.25
shader_param/refraction_strength = 1.0
shader_param/foam_amount = 1.0
shader_param/foam_cutoff = 1.0
shader_param/foam_color = Color( 1, 1, 1, 1 )
shader_param/displacement_strength = 0.25
shader_param/depth_distance = 5.0
shader_param/movement_direction = Vector2( 1, 0 )
shader_param/refraction_noise = SubResource( 9 )
shader_param/foam_noise = SubResource( 7 )
shader_param/displacement_noise = SubResource( 5 )
[sub_resource type="PlaneMesh" id=3]
material = SubResource( 2 )
subdivide_width = 512
subdivide_depth = 512
[node name="Spatial" type="Spatial"]
[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.182733, -0.0156302 )
mesh = SubResource( 3 )
[node name="OmniLight" type="OmniLight" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.336934, 0 )
omni_range = 0.949787
|