summaryrefslogtreecommitdiff
path: root/godot/watershadertest.tscn
diff options
context:
space:
mode:
authorAnson Bridges <bridges.anson@gmail.com>2022-09-30 11:20:16 -0400
committerAnson Bridges <bridges.anson@gmail.com>2022-09-30 11:20:16 -0400
commit4a17fde692b900393d796675bcf7011aa7399dad (patch)
tree5305dba808a7094192821736a379168cdb549843 /godot/watershadertest.tscn
parent7a1d857de96174dfa5a0fa40f8c14acbd2f651c2 (diff)
syncing off main
Diffstat (limited to 'godot/watershadertest.tscn')
-rw-r--r--godot/watershadertest.tscn115
1 files changed, 115 insertions, 0 deletions
diff --git a/godot/watershadertest.tscn b/godot/watershadertest.tscn
new file mode 100644
index 0000000..2c370d9
--- /dev/null
+++ b/godot/watershadertest.tscn
@@ -0,0 +1,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