summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordusoleil <howcansocksbereal@gmail.com>2022-09-22 07:18:03 -0400
committerdusoleil <howcansocksbereal@gmail.com>2022-09-22 07:18:03 -0400
commitdf3557dc3b04b1fa2f399ea319d8810f37931035 (patch)
treeb9db26cbeff5ef5ea0079b87fff6f24c2dc4a463
parent12943209f25236a06f0a1c3ddcb62c83f7172827 (diff)
downloadgodot_wildjam_49-df3557dc3b04b1fa2f399ea319d8810f37931035.tar.gz
godot_wildjam_49-df3557dc3b04b1fa2f399ea319d8810f37931035.zip
Only update the time uniform for the shader each frame
-rw-r--r--water/Water.gd9
-rw-r--r--water/Water.tscn13
-rw-r--r--water/Wave.gdshader18
3 files changed, 23 insertions, 17 deletions
diff --git a/water/Water.gd b/water/Water.gd
index 02bf966..99efa74 100644
--- a/water/Water.gd
+++ b/water/Water.gd
@@ -62,19 +62,20 @@ func _ready():
waves.push_back(Wave.new(wave2_steepness,wave2_wavelength,wave2_direction,_time))
waves.push_back(Wave.new(wave3_steepness,wave3_wavelength,wave3_direction,_time))
-func _wave_to_quad(wave):
- return Quat(wave.steepness,wave._k,wave._a,wave._t)
+func _wave_to_v3(wave):
+ return Vector3(wave.steepness,wave._k,wave._a)
func _update_wave(idx):
var material = self.get_surface_material(0)
- material.set_shader_param("wave" + str(idx+1), _wave_to_quad(waves[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_time(val):
_time = val
+ var material = self.get_surface_material(0)
for idx in waves.size():
waves[idx]._time = _time
- _update_wave(idx)
+ material.set_shader_param("wave" + str(idx+1) + "_t", waves[idx]._t)
func _physics_process(delta):
self._time += delta
diff --git a/water/Water.tscn b/water/Water.tscn
index cdd22a7..0110acd 100644
--- a/water/Water.tscn
+++ b/water/Water.tscn
@@ -10,25 +10,28 @@ subdivide_depth = 500
[sub_resource type="OpenSimplexNoise" id=17]
-[sub_resource type="NoiseTexture" id=18]
+[sub_resource type="NoiseTexture" id=21]
seamless = true
as_normalmap = true
noise = SubResource( 17 )
[sub_resource type="ShaderMaterial" id=11]
shader = ExtResource( 1 )
-shader_param/wave1 = Quat( 0.25, 0.10472, 2.38732, 203.957 )
+shader_param/wave1 = Vector3( 0.25, 0.10472, 2.38732 )
shader_param/wave1_dir = Vector2( 1, 1 )
-shader_param/wave2 = Quat( 0.25, 0.202683, 1.23345, 146.603 )
+shader_param/wave1_t = 0.0
+shader_param/wave2 = Vector3( 0.25, 0.202683, 1.23345 )
shader_param/wave2_dir = Vector2( 1, 0.6 )
-shader_param/wave3 = Quat( 0.25, 0.349066, 0.716197, 111.712 )
+shader_param/wave2_t = 0.0
+shader_param/wave3 = Vector3( 0.25, 0.349066, 0.716197 )
shader_param/wave3_dir = Vector2( 1, 1.3 )
+shader_param/wave3_t = 0.0
shader_param/water_colour = Color( 0.694118, 0.945098, 0.941176, 0.368627 )
shader_param/deep_water_colour = Color( 0.25098, 0.623529, 0.788235, 0.54902 )
shader_param/foam_amount = 0.6
shader_param/murkiness = 4.0
shader_param/refraction_amount = 0.01
-shader_param/noise = SubResource( 18 )
+shader_param/noise = SubResource( 21 )
[node name="Water" type="Spatial"]
diff --git a/water/Wave.gdshader b/water/Wave.gdshader
index ee06fe0..95d064e 100644
--- a/water/Wave.gdshader
+++ b/water/Wave.gdshader
@@ -1,14 +1,17 @@
shader_type spatial;
render_mode cull_disabled, depth_draw_always;
-uniform vec4 wave1 = vec4(0.5,0.5,0.5,1.0);
+uniform vec3 wave1 = vec3(0.5,0.5,0.5);
uniform vec2 wave1_dir = vec2(1.0,0.0);
+uniform float wave1_t = 0.0;
-uniform vec4 wave2 = vec4(0.5,0.5,0.5,1.0);
+uniform vec3 wave2 = vec3(0.5,0.5,0.5);
uniform vec2 wave2_dir = vec2(1.0,0.0);
+uniform float wave2_t = 0.0;
-uniform vec4 wave3 = vec4(0.5,0.5,0.5,1.0);
+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 vec4 water_colour: hint_color;
uniform vec4 deep_water_colour : hint_color;
@@ -20,12 +23,11 @@ uniform float refraction_amount = 0.01;
varying float vertex_y;
-vec3 gerstner_wave(vec4 wave, vec2 wave_dir, vec3 pos, inout vec3 tangent, inout vec3 binormal)
+vec3 gerstner_wave(vec3 wave, vec2 wave_dir, float t, vec3 pos, inout vec3 tangent, inout vec3 binormal)
{
float steepness = wave.x;
float k = wave.y;
float a = wave.z;
- float t = wave.w;
vec2 d = normalize(wave_dir);
float f = k * (dot(d,pos.xz) - t);
@@ -60,9 +62,9 @@ void vertex()
vec3 global_vertex = (WORLD_MATRIX * vec4(VERTEX,1.0)).xyz;
TANGENT = vec3(1.0,0.0,0.0);
BINORMAL = vec3(0.0,0.0,1.0);
- VERTEX += gerstner_wave(wave1,wave1_dir,global_vertex,TANGENT,BINORMAL);
- VERTEX += gerstner_wave(wave2,wave2_dir,global_vertex,TANGENT,BINORMAL);
- VERTEX += gerstner_wave(wave3,wave3_dir,global_vertex,TANGENT,BINORMAL);
+ VERTEX += gerstner_wave(wave1,wave1_dir,wave1_t,global_vertex,TANGENT,BINORMAL);
+ VERTEX += gerstner_wave(wave2,wave2_dir,wave2_t,global_vertex,TANGENT,BINORMAL);
+ VERTEX += gerstner_wave(wave3,wave3_dir,wave3_t,global_vertex,TANGENT,BINORMAL);
vertex_y = VERTEX.y;
NORMAL = normalize(cross(BINORMAL,TANGENT));
}