summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordusoleil <howcansocksbereal@gmail.com>2022-09-23 10:40:20 -0400
committerdusoleil <howcansocksbereal@gmail.com>2022-09-23 10:40:20 -0400
commitf74c06885b77ab8aa2cbf7d007253792bd1636e8 (patch)
treefc96b938ab960e6550f9b5f5585036144787234d
parenta20afe2e211305af26c6a10f307ebf24da44d115 (diff)
downloadgodot_wildjam_49-f74c06885b77ab8aa2cbf7d007253792bd1636e8.tar.gz
godot_wildjam_49-f74c06885b77ab8aa2cbf7d007253792bd1636e8.zip
Add 3 more waves for less predictable water
-rw-r--r--Main.tscn19
-rw-r--r--water/Water.gd72
-rw-r--r--water/Water.tscn34
-rw-r--r--water/Wave.gdshader21
4 files changed, 123 insertions, 23 deletions
diff --git a/Main.tscn b/Main.tscn
index fec9cd0..42f64d4 100644
--- a/Main.tscn
+++ b/Main.tscn
@@ -45,6 +45,25 @@ material/0 = SubResource( 21 )
[node name="Water" parent="." instance=ExtResource( 3 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
+wave1_steepness = 0.08
+wave1_wavelength = 76.72
+wave1_direction = Vector2( 0.07, 0.98 )
+wave2_steepness = 0.2
+wave2_wavelength = 277.23
+wave2_direction = Vector2( -0.86, 0.06 )
+wave3_steepness = 0.16
+wave3_wavelength = 306.79
+wave3_direction = Vector2( 0.66, 0.08 )
+wave4_steepness = 0.03
+wave4_wavelength = 177.72
+wave4_direction = Vector2( 0.37, 0.08 )
+wave5_steepness = 0.16
+wave5_wavelength = 457.05
+wave5_direction = Vector2( -0.09, -0.09 )
+wave6_steepness = 0.13
+wave6_wavelength = 224.56
+wave6_direction = Vector2( -0.27, 0.33 )
+wave_size = 0.75
[node name="World" parent="." instance=ExtResource( 6 )]
traveler = NodePath("../ShipRigidBody")
diff --git a/water/Water.gd b/water/Water.gd
index 9937725..5a4bfe2 100644
--- a/water/Water.gd
+++ b/water/Water.gd
@@ -13,8 +13,20 @@ export var wave3_steepness = 0.5 setget _set_wave3_steepness
export var wave3_wavelength = 10.0 setget _set_wave3_wavelength
export var wave3_direction = Vector2(1.0,0.0) setget _set_wave3_direction
+export var wave4_steepness = 0.5 setget _set_wave4_steepness
+export var wave4_wavelength = 10.0 setget _set_wave4_wavelength
+export var wave4_direction = Vector2(1.0,0.0) setget _set_wave4_direction
+
+export var wave5_steepness = 0.5 setget _set_wave5_steepness
+export var wave5_wavelength = 10.0 setget _set_wave5_wavelength
+export var wave5_direction = Vector2(1.0,0.0) setget _set_wave5_direction
+
+export var wave6_steepness = 0.5 setget _set_wave6_steepness
+export var wave6_wavelength = 10.0 setget _set_wave6_wavelength
+export var wave6_direction = Vector2(1.0,0.0) setget _set_wave6_direction
+
export var wave_speed = 2.0 setget _set_wave_speed
-export var wave_size = 1.5 setget _set_wave_size
+export var wave_size = 1.0 setget _set_wave_size
onready var water_plane = $"MeshInstance"
@@ -60,12 +72,55 @@ func _set_wave3_direction(val):
wave3_direction = val
_set_wave_prop(2,"direction",val)
+func _set_wave4_steepness(val):
+ wave4_steepness = val
+ _set_wave_prop(3,"steepness",val)
+
+func _set_wave4_wavelength(val):
+ wave4_wavelength = val
+ _set_wave_prop(3,"wavelength",val)
+
+func _set_wave4_direction(val):
+ wave4_direction = val
+ _set_wave_prop(3,"direction",val)
+
+func _set_wave5_steepness(val):
+ wave5_steepness = val
+ _set_wave_prop(4,"steepness",val)
+
+func _set_wave5_wavelength(val):
+ wave5_wavelength = val
+ _set_wave_prop(4,"wavelength",val)
+
+func _set_wave5_direction(val):
+ wave5_direction = val
+ _set_wave_prop(4,"direction",val)
+
+func _set_wave6_steepness(val):
+ wave6_steepness = val
+ _set_wave_prop(5,"steepness",val)
+
+func _set_wave6_wavelength(val):
+ wave6_wavelength = val
+ _set_wave_prop(5,"wavelength",val)
+
+func _set_wave6_direction(val):
+ wave6_direction = val
+ _set_wave_prop(5,"direction",val)
+
var _time = 0.0 setget _set_time
var waves = []
func _ready():
waves.push_back(Wave.new(wave1_steepness,wave1_wavelength,wave1_direction,_time))
waves.push_back(Wave.new(wave2_steepness,wave2_wavelength,wave2_direction,_time))
waves.push_back(Wave.new(wave3_steepness,wave3_wavelength,wave3_direction,_time))
+ waves.push_back(Wave.new(wave4_steepness,wave4_wavelength,wave4_direction,_time))
+ waves.push_back(Wave.new(wave5_steepness,wave5_wavelength,wave5_direction,_time))
+ waves.push_back(Wave.new(wave6_steepness,wave6_wavelength,wave6_direction,_time))
+ for i in waves.size():
+ _update_wave(i)
+ _update_multipliers()
+ self._time = 0.0
func _wave_to_v3(wave):
return Vector3(wave.steepness,wave._k,wave._a)
@@ -75,18 +130,25 @@ func _update_wave(idx):
material.set_shader_param("wave" + str(idx+1), _wave_to_v3(waves[idx]))
material.set_shader_param("wave" + str(idx+1) + "_dir", waves[idx].direction)
+func _update_multipliers():
+ if water_plane != null:
+ var material = self.water_plane.get_surface_material(0)
+ material.set_shader_param("wave_speed", wave_speed)
+ material.set_shader_param("wave_size", wave_size)
+
func _set_wave_speed(val):
- var material = self.water_plane.get_surface_material(0)
wave_speed = val
- material.set_shader_param("wave_speed", wave_speed)
+ if val == null: return
+ _update_multipliers()
func _set_wave_size(val):
- var material = self.water_plane.get_surface_material(0)
wave_size = val
- material.set_shader_param("wave_size", wave_size)
+ if val == null: return
+ _update_multipliers()
func _set_time(val):
_time = val
+ if val == null: return
var material = self.water_plane.get_surface_material(0)
for idx in waves.size():
waves[idx]._time = _time
diff --git a/water/Water.tscn b/water/Water.tscn
index 87909ac..6d2571a 100644
--- a/water/Water.tscn
+++ b/water/Water.tscn
@@ -18,20 +18,29 @@ noise = SubResource( 17 )
[sub_resource type="ShaderMaterial" id=11]
shader = ExtResource( 1 )
-shader_param/wave1 = Vector3( 0.1, 0.0314159, 3.1831 )
-shader_param/wave1_dir = Vector2( 1, 1 )
+shader_param/wave1 = Vector3( 0.08, 0.0818976, 0.976829 )
+shader_param/wave1_dir = Vector2( 0.07, 0.98 )
shader_param/wave1_t = 0.0
-shader_param/wave2 = Vector3( 0.1, 0.0479632, 2.08493 )
-shader_param/wave2_dir = Vector2( 1, 0.6 )
+shader_param/wave2 = Vector3( 0.2, 0.0226642, 8.8245 )
+shader_param/wave2_dir = Vector2( -0.86, 0.06 )
shader_param/wave2_t = 0.0
-shader_param/wave3 = Vector3( 0.2, 0.0634665, 3.15127 )
-shader_param/wave3_dir = Vector2( 1, 1.3 )
+shader_param/wave3 = Vector3( 0.16, 0.0204804, 7.81234 )
+shader_param/wave3_dir = Vector2( 0.66, 0.08 )
shader_param/wave3_t = 0.0
-shader_param/wave_size = 1.5
+shader_param/wave4 = Vector3( 0.03, 0.0353544, 0.84855 )
+shader_param/wave4_dir = Vector2( 0.37, 0.08 )
+shader_param/wave4_t = 0.0
+shader_param/wave5 = Vector3( 0.16, 0.0137473, 11.6387 )
+shader_param/wave5_dir = Vector2( -0.09, -0.09 )
+shader_param/wave5_t = 0.0
+shader_param/wave6 = Vector3( 0.13, 0.02798, 4.64618 )
+shader_param/wave6_dir = Vector2( -0.27, 0.33 )
+shader_param/wave6_t = 0.0
+shader_param/wave_size = 1.0
shader_param/water_color = Color( 0.25098, 0.623529, 0.788235, 0.54902 )
shader_param/foam_color = Color( 0.694118, 0.945098, 0.941176, 0.368627 )
shader_param/foam_amount_edge = 2.0
-shader_param/foam_amount_crest = 4.0
+shader_param/foam_amount_crest = 10.0
shader_param/murkiness = 4.0
shader_param/refraction_amount = 0.01
shader_param/foam_map = ExtResource( 3 )
@@ -39,15 +48,6 @@ shader_param/noise = SubResource( 21 )
[node name="Water" type="Spatial"]
script = ExtResource( 2 )
-wave1_steepness = 0.1
-wave1_wavelength = 200.0
-wave1_direction = Vector2( 1, 1 )
-wave2_steepness = 0.1
-wave2_wavelength = 131.0
-wave2_direction = Vector2( 1, 0.6 )
-wave3_steepness = 0.2
-wave3_wavelength = 99.0
-wave3_direction = Vector2( 1, 1.3 )
[node name="MeshInstance" type="MeshInstance" parent="."]
layers = 2
diff --git a/water/Wave.gdshader b/water/Wave.gdshader
index bf9a744..65743af 100644
--- a/water/Wave.gdshader
+++ b/water/Wave.gdshader
@@ -13,6 +13,18 @@ uniform vec3 wave3 = vec3(0.5,0.5,0.5);
uniform vec2 wave3_dir = vec2(1.0,0.0);
uniform float wave3_t = 0.0;
+uniform vec3 wave4 = vec3(0.5,0.5,0.5);
+uniform vec2 wave4_dir = vec2(1.0,0.0);
+uniform float wave4_t = 0.0;
+
+uniform vec3 wave5 = vec3(0.5,0.5,0.5);
+uniform vec2 wave5_dir = vec2(1.0,0.0);
+uniform float wave5_t = 0.0;
+
+uniform vec3 wave6 = vec3(0.5,0.5,0.5);
+uniform vec2 wave6_dir = vec2(1.0,0.0);
+uniform float wave6_t = 0.0;
+
uniform float wave_size = 1.5;
uniform vec4 water_color : hint_color;
@@ -73,6 +85,9 @@ void vertex()
displacement += gerstner_wave(wave1,wave1_dir,wave1_t,global_vertex,TANGENT,BINORMAL);
displacement += gerstner_wave(wave2,wave2_dir,wave2_t,global_vertex,TANGENT,BINORMAL);
displacement += gerstner_wave(wave3,wave3_dir,wave3_t,global_vertex,TANGENT,BINORMAL);
+ displacement += gerstner_wave(wave4,wave4_dir,wave4_t,global_vertex,TANGENT,BINORMAL);
+ displacement += gerstner_wave(wave5,wave5_dir,wave5_t,global_vertex,TANGENT,BINORMAL);
+ displacement += gerstner_wave(wave6,wave6_dir,wave6_t,global_vertex,TANGENT,BINORMAL);
displacement.y *= wave_size;
VERTEX += displacement;
NORMAL = normalize(cross(BINORMAL,TANGENT));
@@ -113,9 +128,13 @@ void fragment()
float depth = get_depth(SCREEN_UV, DEPTH_TEXTURE, INV_PROJECTION_MATRIX);
float water_depth = -VERTEX.z;
float submersion = depth - water_depth;
- float wave_pos = wave_position(wave1.y,wave1_dir,wave1_t);
+ float wave_pos = 0.0;
+ wave_pos += wave_position(wave1.y,wave1_dir,wave1_t);
wave_pos *= wave_position(wave2.y,wave2_dir,wave2_t);
wave_pos *= wave_position(wave3.y,wave3_dir,wave3_t);
+ wave_pos *= wave_position(wave4.y,wave4_dir,wave4_t);
+ wave_pos *= wave_position(wave5.y,wave5_dir,wave5_t);
+ wave_pos *= wave_position(wave6.y,wave6_dir,wave6_t);
wave_pos = 1.0 - (pow(1.0 - wave_pos, foam_amount_crest));
vec4 foam = texture(foam_map, UV + (-displacement.xz * 0.005));
vec4 mapped_foam_color = mix(water_color,foam_color,foam.b);