summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordusoleil <howcansocksbereal@gmail.com>2022-09-23 09:11:35 -0400
committerdusoleil <howcansocksbereal@gmail.com>2022-09-23 09:11:35 -0400
commita20afe2e211305af26c6a10f307ebf24da44d115 (patch)
tree2664ce0250af697b83d7e42644bd84b6dea380a2
parentd089c01a602964d2e3b4892e6b5e40c7bbbe725d (diff)
downloadgodot_wildjam_49-a20afe2e211305af26c6a10f307ebf24da44d115.tar.gz
godot_wildjam_49-a20afe2e211305af26c6a10f307ebf24da44d115.zip
Add wave height and speed multipliers for bigger, faster waves
-rw-r--r--Main.tscn2
-rw-r--r--water/Water.gd16
-rw-r--r--water/Water.tscn19
-rw-r--r--water/Wave.gdshader5
4 files changed, 30 insertions, 12 deletions
diff --git a/Main.tscn b/Main.tscn
index 5357b25..fec9cd0 100644
--- a/Main.tscn
+++ b/Main.tscn
@@ -32,7 +32,7 @@ shadow_enabled = true
directional_shadow_blend_splits = true
[node name="Ground" type="StaticBody" parent="."]
-transform = Transform( 20000, 0, 0, 0, 1, 0, 0, 0, 20000, 0, -10, 0 )
+transform = Transform( 20000, 0, 0, 0, 1, 0, 0, 0, 20000, 0, -50, 0 )
collision_layer = 4
collision_mask = 0
diff --git a/water/Water.gd b/water/Water.gd
index d8027f8..9937725 100644
--- a/water/Water.gd
+++ b/water/Water.gd
@@ -13,6 +13,9 @@ 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 wave_speed = 2.0 setget _set_wave_speed
+export var wave_size = 1.5 setget _set_wave_size
+
onready var water_plane = $"MeshInstance"
func _set_wave_prop(idx, prop, val):
@@ -72,6 +75,16 @@ 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 _set_wave_speed(val):
+ var material = self.water_plane.get_surface_material(0)
+ wave_speed = val
+ material.set_shader_param("wave_speed", wave_speed)
+
+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)
+
func _set_time(val):
_time = val
var material = self.water_plane.get_surface_material(0)
@@ -80,7 +93,7 @@ func _set_time(val):
material.set_shader_param("wave" + str(idx+1) + "_t", waves[idx]._t)
func _physics_process(delta):
- self._time += delta
+ self._time += delta * wave_speed
func gertsner_wave(pos, idx):
if idx >= waves.size(): return 0.0
@@ -101,6 +114,7 @@ func sample_wave(pos):
var offset = Vector3.ZERO
for idx in waves.size():
offset += gertsner_wave(pos, idx)
+ offset.y *= wave_size
return offset
func height(pos):
diff --git a/water/Water.tscn b/water/Water.tscn
index b37340b..87909ac 100644
--- a/water/Water.tscn
+++ b/water/Water.tscn
@@ -18,15 +18,16 @@ noise = SubResource( 17 )
[sub_resource type="ShaderMaterial" id=11]
shader = ExtResource( 1 )
-shader_param/wave1 = Vector3( 0.25, 0.10472, 2.38732 )
+shader_param/wave1 = Vector3( 0.1, 0.0314159, 3.1831 )
shader_param/wave1_dir = Vector2( 1, 1 )
shader_param/wave1_t = 0.0
-shader_param/wave2 = Vector3( 0.25, 0.202683, 1.23345 )
+shader_param/wave2 = Vector3( 0.1, 0.0479632, 2.08493 )
shader_param/wave2_dir = Vector2( 1, 0.6 )
shader_param/wave2_t = 0.0
-shader_param/wave3 = Vector3( 0.25, 0.349066, 0.716197 )
+shader_param/wave3 = Vector3( 0.2, 0.0634665, 3.15127 )
shader_param/wave3_dir = Vector2( 1, 1.3 )
shader_param/wave3_t = 0.0
+shader_param/wave_size = 1.5
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
@@ -38,14 +39,14 @@ shader_param/noise = SubResource( 21 )
[node name="Water" type="Spatial"]
script = ExtResource( 2 )
-wave1_steepness = 0.25
-wave1_wavelength = 60.0
+wave1_steepness = 0.1
+wave1_wavelength = 200.0
wave1_direction = Vector2( 1, 1 )
-wave2_steepness = 0.25
-wave2_wavelength = 31.0
+wave2_steepness = 0.1
+wave2_wavelength = 131.0
wave2_direction = Vector2( 1, 0.6 )
-wave3_steepness = 0.25
-wave3_wavelength = 18.0
+wave3_steepness = 0.2
+wave3_wavelength = 99.0
wave3_direction = Vector2( 1, 1.3 )
[node name="MeshInstance" type="MeshInstance" parent="."]
diff --git a/water/Wave.gdshader b/water/Wave.gdshader
index 06c5327..bf9a744 100644
--- a/water/Wave.gdshader
+++ b/water/Wave.gdshader
@@ -13,6 +13,8 @@ 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 float wave_size = 1.5;
+
uniform vec4 water_color : hint_color;
uniform vec4 foam_color: hint_color;
@@ -71,6 +73,7 @@ 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.y *= wave_size;
VERTEX += displacement;
NORMAL = normalize(cross(BINORMAL,TANGENT));
}
@@ -114,7 +117,7 @@ void fragment()
wave_pos *= wave_position(wave2.y,wave2_dir,wave2_t);
wave_pos *= wave_position(wave3.y,wave3_dir,wave3_t);
wave_pos = 1.0 - (pow(1.0 - wave_pos, foam_amount_crest));
- vec4 foam = texture(foam_map, UV + (-displacement.xz * 0.001));
+ vec4 foam = texture(foam_map, UV + (-displacement.xz * 0.005));
vec4 mapped_foam_color = mix(water_color,foam_color,foam.b);
vec4 color = mix(water_color, mapped_foam_color, wave_pos);
float object_foam = clamp((foam_amount_edge - submersion) / foam_amount_edge, 0.0, 1.0);