summaryrefslogtreecommitdiffstats
path: root/Water.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Water.gd')
-rw-r--r--Water.gd81
1 files changed, 81 insertions, 0 deletions
diff --git a/Water.gd b/Water.gd
new file mode 100644
index 0000000..f9463e4
--- /dev/null
+++ b/Water.gd
@@ -0,0 +1,81 @@
+extends MeshInstance
+tool
+
+export var wave1_steepness = 0.5 setget _set_wave1_steepness
+export var wave1_wavelength = 10.0 setget _set_wave1_wavelength
+export var wave1_direction = Vector2(1.0,0.0) setget _set_wave1_direction
+
+export var wave2_steepness = 0.5 setget _set_wave2_steepness
+export var wave2_wavelength = 10.0 setget _set_wave2_wavelength
+export var wave2_direction = Vector2(1.0,0.0) setget _set_wave2_direction
+
+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
+
+func _set_wave_prop(idx, prop, val):
+ if val == null: return
+ if idx >= waves.size(): return
+ waves[idx].set(prop,val)
+ _update_wave(0)
+
+func _set_wave1_steepness(val):
+ wave1_steepness = val
+ _set_wave_prop(0,"steepness",val)
+
+func _set_wave1_wavelength(val):
+ wave1_wavelength = val
+ _set_wave_prop(0,"wavelength",val)
+
+func _set_wave1_direction(val):
+ wave1_direction = val
+ _set_wave_prop(0,"direction",val)
+
+func _set_wave2_steepness(val):
+ wave2_steepness = val
+ _set_wave_prop(1,"steepness",val)
+
+func _set_wave2_wavelength(val):
+ wave2_wavelength = val
+ _set_wave_prop(1,"wavelength",val)
+
+func _set_wave2_direction(val):
+ wave2_direction = val
+ _set_wave_prop(1,"direction",val)
+
+func _set_wave3_steepness(val):
+ wave3_steepness = val
+ _set_wave_prop(2,"steepness",val)
+
+func _set_wave3_wavelength(val):
+ wave3_wavelength = val
+ _set_wave_prop(2,"wavelength",val)
+
+func _set_wave3_direction(val):
+ wave3_direction = val
+ _set_wave_prop(2,"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))
+
+func _wave_to_quad(wave):
+ return Quat(wave.steepness,wave._k,wave._a,wave._t)
+
+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) + "_dir", waves[idx].direction)
+
+func _set_time(val):
+ _time = val
+ for idx in waves.size():
+ waves[idx]._time = _time
+ _update_wave(idx)
+
+func _physics_process(delta):
+ self._time += delta
+