some shake

This commit is contained in:
2026-01-20 15:27:59 +01:00
parent 8d1e7ebb4f
commit c1ca0bf27b
143 changed files with 5704 additions and 6 deletions

View File

@@ -0,0 +1,46 @@
@icon("res://addons/shaker/assets/ShakerType.svg")
@tool
class_name ShakerTypeBase1D
extends ShakerTypeBase
enum GraphAxis {
X,
}
@export var amplitude:float = 1.0:
set = set_amplitude,
get = get_amplitude
@export var offset:float = 0.0:
set = set_offset,
get = get_offset
func set_amplitude(value: float) -> void:
amplitude = value
_on_property_changed("amplitude")
func get_amplitude() -> float:
return amplitude
func set_offset(value: float) -> void:
offset = value
_on_property_changed("offset")
func get_offset() -> float:
return offset
# Get the shake value at a given time
func get_value(t: float) -> float:
var result:float = 0.0;
return _calc_value(fmod(t, 1.0), result)
# Calculate the shake value
func _calc_value(t: float, result: float) -> float:
if duration > 0:
t /= duration
if (start_percent != 0 && start_percent > t) || (end_percent != 1 && end_percent < t):
result = 0.0;
else:
result = result * amplitude + offset
result *= (ease(t, fade_in) if fade_in > 0.0001 else 1.0) * (ease(1.0 - t, fade_out) if fade_out > 0.0001 else 1.0)
return result;

View File

@@ -0,0 +1 @@
uid://bhqlklbhcxfgf

View File

@@ -0,0 +1,43 @@
@tool
class_name ShakerTypeAudioBus1D
extends ShakerTypeBase1D
@export var bus_name:String = "Master":
set = set_bus_name,
get = get_bus_name
@export_range(20, 20000) var min_frequence:float = 20
@export_range(20, 20000) var max_frequence:float = 20000
var bus_index:int = 0
var effect:AudioEffectSpectrumAnalyzerInstance
## Calculates the value of the square wave at time t.
func get_value(t: float) -> float:
var result:float = 0.0
if effect:
var mag:Vector2 = effect.get_magnitude_for_frequency_range(min_frequence, max_frequence, AudioEffectSpectrumAnalyzerInstance.MAGNITUDE_MAX)
result = mag.length()
return _calc_value(t, result)
func set_bus_name(value: String) -> void:
bus_name = value
_update_bus_index()
_on_property_changed("bus_name")
func get_bus_name() -> String:
return bus_name
func _update_bus_index() -> void:
bus_index = AudioServer.get_bus_index(bus_name)
if bus_index > -1:
for e in AudioServer.get_bus_effect_count(bus_index):
var _effect:AudioEffect = AudioServer.get_bus_effect(bus_index, e)
if _effect is AudioEffectSpectrumAnalyzer:
effect = AudioServer.get_bus_effect_instance(bus_index, e, 0)
break;
if effect == null:
AudioServer.add_bus_effect(bus_index, AudioEffectSpectrumAnalyzer.new(), 0)
effect = AudioServer.get_bus_effect_instance(bus_index, 0)
else:
push_error("Error: Bus '" + bus_name + "' not found!")
effect = null

View File

@@ -0,0 +1 @@
uid://dshti5xd41w07

View File

@@ -0,0 +1,42 @@
@tool
class_name ShakerTypeBrownianShake1D
extends ShakerTypeBase1D
@export var roughness:float = 1.0:
set = set_roughness,
get = get_roughness
@export var persistence:float = 0.5:
set = set_persistence,
get = get_persistence
var _generator: RandomNumberGenerator = RandomNumberGenerator.new()
var _last_pos:float = 0.0
func _init() -> void:
property_changed.connect(_property_changed)
func get_value(t: float) -> float:
var result:float = 0.0
result = (_last_pos + _generator.randf_range(-roughness, roughness))
result = _calc_value(t, result)
_last_pos = lerpf(_last_pos, result, 1.0 - persistence)
return _last_pos
func _property_changed(name: StringName) -> void:
_last_pos = 0.0
func set_roughness(value: float) -> void:
roughness = value
_on_property_changed("roughness")
func get_roughness() -> float:
return roughness
func set_persistence(value: float) -> void:
persistence = clamp(persistence,0, 1)
_on_property_changed("persistence")
func get_persistence() -> float:
return persistence

View File

@@ -0,0 +1 @@
uid://62yumjskyeow

View File

@@ -0,0 +1,41 @@
@tool
class_name ShakerTypeCurve1D
extends ShakerTypeBase1D
@export var curve: Curve:
set = set_curve,
get = get_curve
@export var loop: bool = true:
set = set_loop,
get = get_loop
func _curve_changed() -> void:
_on_property_changed("curve")
func get_value(t: float) -> float:
var result: float = 0.0
if loop && t > 1.0:
t = fmod(t, 1.0)
if curve:
result = curve.sample(t)
return _calc_value(t, result)
func set_curve(value: Curve) -> void:
if curve:
curve.changed.disconnect(_curve_changed)
curve = value
if curve:
curve.changed.connect(_curve_changed)
else:
_curve_changed()
func get_curve() -> Curve:
return curve
func set_loop(value: bool) -> void:
loop = value
_on_property_changed("loop")
func get_loop() -> bool:
return loop

View File

@@ -0,0 +1 @@
uid://dadkdm3tvmuqq

View File

@@ -0,0 +1,32 @@
@tool
class_name ShakerTypeNoiseShake1D
extends ShakerTypeBase1D
@export var noise_texture: NoiseTexture2D = NoiseTexture2D.new():
set = set_noise_texture,
get = get_noise_texture
func _init() -> void:
noise_texture.changed.connect(_on_noise_changed)
func get_value(t: float) -> float:
var result:float = 0.0
if noise_texture && noise_texture.noise:
var noise_size:Vector2 = Vector2(noise_texture.width, noise_texture.height)
var noise_offset:float = t * noise_size.x
result = noise_texture.noise.get_noise_1d(noise_offset)
result *= 2.0
return _calc_value(t, result)
func _on_noise_changed() -> void:
_on_property_changed("noise_texture")
func set_noise_texture(value: NoiseTexture2D) -> void:
if noise_texture:
noise_texture.changed.disconnect(_on_noise_changed)
noise_texture = value
if noise_texture:
noise_texture.changed.connect(_on_noise_changed)
func get_noise_texture() -> NoiseTexture2D:
return noise_texture

View File

@@ -0,0 +1 @@
uid://bdrk4rkut1y3l

View File

@@ -0,0 +1,30 @@
@tool
class_name ShakerTypeRandom1D
extends ShakerTypeBase1D
## The seed for the random number generator.
@export var seed: int = 0:
set = set_seed
## The random number generator instance.
var _generator: RandomNumberGenerator = RandomNumberGenerator.new()
## Initializes the shake type with the given seed.
func _init() -> void:
set_seed(seed)
## Calculates a random value for each axis at time t.
func get_value(t: float) -> float:
var result:float = 0.0
result = _generator.randf_range(-1.0, 1.0)
return _calc_value(t, result)
## Sets the seed for the random number generator.
func set_seed(value: int) -> void:
seed = value
_generator.seed = seed
_on_property_changed("seed")
## Gets the current seed of the random number generator.
func get_seed() -> int:
return seed

View File

@@ -0,0 +1 @@
uid://buor2ix0dmwk2

View File

@@ -0,0 +1,41 @@
@tool
class_name ShakerTypeSawtoothWave1D
extends ShakerTypeBase1D
## The frequency of the sawtooth wave for each axis.
@export var frequency:float = 5.0:
set = set_frequency
## The asymmetry of the sawtooth wave for each axis (0 to 1).
@export var asymmetry:float = 0.5:
set = set_asymmetry
## Sets the frequency of the sawtooth wave.
func set_frequency(value: float) -> void:
frequency = value
_on_property_changed("frequency")
## Gets the frequency of the sawtooth wave.
func get_frequency() -> float:
return frequency
## Sets the asymmetry of the sawtooth wave.
func set_asymmetry(value: float) -> void:
asymmetry = clamp(value, 0.0, 0.0)
_on_property_changed("asymmetry")
## Gets the asymmetry of the sawtooth wave.
func get_asymmetry() -> float:
return asymmetry
## Calculates the value of the sawtooth wave at time t.
func get_value(t: float) -> float:
var result:float = 0.0
var _real_time:float = fmod(t, 1.0) if t > 1.0 else t
var wave:float = fmod(_real_time * frequency, 1.0)
wave = wave / asymmetry if wave < asymmetry else (1.0 - wave) / (1.0 - asymmetry)
result = wave
result = _calc_value(t, result)
result = (result - amplitude * 0.5) * 2.0
return result

View File

@@ -0,0 +1 @@
uid://tftoajmajyfg

View File

@@ -0,0 +1,32 @@
@tool
class_name ShakerTypeSineWave1D
extends ShakerTypeBase1D
@export_group("Sinewave Properties")
@export var frequency:float = 1.0:
set = set_frequency,
get = get_frequency
@export var phase:float = 0.0:
set = set_phase,
get = get_phase
func get_value(t: float) -> float:
var result:float = 0.0
var _real_time: float = fmod(t, 1.0) if t > 1.0 else t
result = sin(t * frequency * TAU + phase)
return _calc_value(_real_time, result)
func set_frequency(value: float) -> void:
frequency = value
_on_property_changed("frequency")
func get_frequency() -> float:
return frequency
func set_phase(value: float) -> void:
phase = value
_on_property_changed("phase")
func get_phase() -> float:
return phase

View File

@@ -0,0 +1 @@
uid://vvwsdrpmw7w4

View File

@@ -0,0 +1,35 @@
@tool
class_name ShakerTypeSquareWave1D
extends ShakerTypeBase1D
## The frequency of the square wave for each axis.
@export var frequency:float = 5.0:
set = set_frequency
## The duty cycle of the square wave for each axis (0 to 1).
@export var duty_cycle:float = 0.5:
set = set_duty_cycle
## Sets the frequency of the square wave.
func set_frequency(value:float) -> void:
frequency = value
_on_property_changed("frequency")
## Gets the frequency of the square wave.
func get_frequency() -> float:
return frequency
## Sets the duty cycle of the square wave.
func set_duty_cycle(value:float) -> void:
duty_cycle = clamp(value, 0.0, 0.0)
_on_property_changed("duty_cycle")
## Gets the duty cycle of the square wave.
func get_duty_cycle() -> float:
return duty_cycle
## Calculates the value of the square wave at time t.
func get_value(t: float) -> float:
var result:float = 0.0
result = 1.0 if fmod(t * frequency, 1.0) < duty_cycle else -1.0
return _calc_value(t, result)

View File

@@ -0,0 +1 @@
uid://bwuxn8yt7jiwy