Merge #30: forced lighting, intro sounds, scarecrow chest glow
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
f0146c8aa5
17 changed files with 562 additions and 4 deletions
|
|
@ -9,6 +9,8 @@ extends Node
|
|||
## The scarecrow carries a lantern that lights up as it gets dark, and enemies glow faintly at
|
||||
## night (night_glow in thief.gdshader and ufo.gdshader) so they stay readable. The current
|
||||
## look eases toward the target, so phase changes never pop.
|
||||
## A cutscene (the opening intro) can hold a look whatever the phase (forced: "morning" or
|
||||
## "night") and keep the lanterns dark (lanterns_dark); both are cleared to give the phase back.
|
||||
|
||||
const NIGHTFALL := 8.0
|
||||
const EASE := 2.5
|
||||
|
|
@ -33,6 +35,11 @@ var lantern: OmniLight3D
|
|||
## Co-op: player 2's lantern (add_lantern), lit the same.
|
||||
var lanterns: Array[OmniLight3D] = []
|
||||
var current := DAY.duplicate()
|
||||
## "" follows the phase; "morning" holds the MORNING phase's look and "night" the NIGHT look
|
||||
## (target() returns it; the current look eases toward it, or snap() jumps to it).
|
||||
var forced := ""
|
||||
## Every lantern stays off while set (the intro's scarecrow isn't alive yet).
|
||||
var lanterns_dark := false
|
||||
|
||||
|
||||
func setup(p_campaign: CampaignController, p_sun: DirectionalLight3D, p_env: Environment, player: Node3D,
|
||||
|
|
@ -72,6 +79,11 @@ func snap() -> void:
|
|||
|
||||
|
||||
func target() -> Dictionary:
|
||||
match forced:
|
||||
"morning":
|
||||
return morning()
|
||||
"night":
|
||||
return NIGHT
|
||||
var s := campaign.state
|
||||
var cfg := campaign.config
|
||||
var length := campaign.phase_length(s.phase)
|
||||
|
|
@ -79,7 +91,7 @@ func target() -> Dictionary:
|
|||
var p := clampf(elapsed / length, 0.0, 1.0) if is_finite(length) and length > 0.0 else 0.0
|
||||
match s.phase:
|
||||
CampaignController.Phase.MORNING:
|
||||
return _mix(SUNRISE, DAY, 0.7)
|
||||
return morning()
|
||||
CampaignController.Phase.DUSK:
|
||||
return _mix(DAY, SUNSET, p)
|
||||
CampaignController.Phase.NIGHT:
|
||||
|
|
@ -91,6 +103,11 @@ func target() -> Dictionary:
|
|||
return DAY
|
||||
|
||||
|
||||
## The MORNING phase's look: mostly day, a little sunrise.
|
||||
static func morning() -> Dictionary:
|
||||
return _mix(SUNRISE, DAY, 0.7)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if campaign == null:
|
||||
return
|
||||
|
|
@ -108,7 +125,7 @@ func _apply() -> void:
|
|||
env.adjustment_saturation = current["sat"]
|
||||
for l in lanterns:
|
||||
if is_instance_valid(l):
|
||||
l.light_energy = current["lantern"]
|
||||
l.light_energy = 0.0 if lanterns_dark else float(current["lantern"])
|
||||
for m in enemy_materials:
|
||||
if m != null:
|
||||
m.set_shader_parameter("night_glow", current["glow"])
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@ extends Node3D
|
|||
## * phases: the dusk bell, stingers at dusk, nightfall, sunrise, and morning; game over;
|
||||
## the day and night ambience (crossfading through dusk and dawn)
|
||||
## * UI: hover, click, back, open, close, error (ui(), also from the menus)
|
||||
## * the opening intro (OpeningIntro, solo only, so never sent): the farmhouse door's creak, the
|
||||
## car doors, the big UFO's hum (a loop), spin-up whine, and zoom away, the part's falling
|
||||
## whistle, and the flash that brings the scarecrow to life
|
||||
## * Music (the Music bus), by phase: "On the Farm" on the title screen (the farm's morning
|
||||
## behind it), the morning, and by day, and when the farmers are back; "Purgatory" at night;
|
||||
## none at dusk, at dawn, or after a Game Over (only the ambience). Tracks crossfade.
|
||||
|
|
@ -101,11 +104,20 @@ const CUES := {
|
|||
"truck_engine": {"files": ["synth/truck_engine.wav"], "db": -6.0},
|
||||
"day_ambience": {"files": ["synth/day_ambience.wav"], "bus": "Ambience"},
|
||||
"night_ambience": {"files": ["synth/night_ambience.wav"], "bus": "Ambience"},
|
||||
# The opening intro ("ufo_hum" loops: play it on a player of its own, with stream_of)
|
||||
"door_creak": {"files": ["kenney/rpg/creak1.ogg", "kenney/rpg/creak2.ogg"], "db": -2.0, "pitch": 0.05},
|
||||
"car_door": {"files": ["synth/car_door.wav"], "db": -3.0, "pitch": 0.06},
|
||||
"ufo_hum": {"files": ["synth/ufo_hum.wav"], "db": -6.0},
|
||||
"ufo_whine": {"files": ["synth/ufo_whine.wav"], "db": -6.0},
|
||||
"part_fall": {"files": ["synth/part_fall.wav"], "db": -6.0},
|
||||
"life_flash": {"files": ["synth/life_flash.wav"], "db": -2.0},
|
||||
"ufo_zoom": {"files": ["synth/ufo_zoom.wav"], "db": -4.0},
|
||||
}
|
||||
## Cues each machine plays for itself in co-op (never sent, never skipped).
|
||||
const LOCAL_CUES: Array[String] = ["ui_hover", "ui_click", "ui_back", "ui_open", "ui_close", "error", "step", "chop",
|
||||
"rustle", "clank", "hammer", "patching", "bell", "dusk", "night", "dawn", "morning", "game_over", "victory",
|
||||
"assessment", "horn", "truck_engine", "day_ambience", "night_ambience", "upgrade", "fear_ready"]
|
||||
"assessment", "horn", "truck_engine", "day_ambience", "night_ambience", "upgrade", "fear_ready", "door_creak",
|
||||
"car_door", "ufo_hum", "ufo_whine", "part_fall", "life_flash", "ufo_zoom"]
|
||||
const VOICES_3D := 20
|
||||
const VOICES_UI := 10
|
||||
## Seconds of channel between repeats of the gather / repair / patch sounds, and meters per
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@ extends CharacterBody3D
|
|||
## it was last sent (net_position, net_yaw) and animates by net_speed (like input strength: 1 at
|
||||
## run speed, more while sprinting) instead of reading the input. Each scarecrow sprints on the
|
||||
## machine that plays it. set_tint() and set_tag() tell the two scarecrows apart.
|
||||
## The core glow: every scarecrow has a small blue core in its chest (the alien part it absorbed
|
||||
## in the opening intro): a glowing gem on the chest bone (so it follows the animation), a soft
|
||||
## halo, and a weak blue light, pulsing slowly. It's unshaded (the toon look and the hit flash
|
||||
## leave it alone, and the tint doesn't touch it), so it reads faintly by day and clearly at
|
||||
## night. set_core_glow(false) hides it (the intro, until the flash).
|
||||
|
||||
@export var run_speed := 5.0
|
||||
@export var acceleration := 30.0
|
||||
|
|
@ -37,6 +42,41 @@ extends CharacterBody3D
|
|||
@onready var model: Node3D = $Model
|
||||
@onready var animation_player: AnimationPlayer = $Model/AnimationPlayer
|
||||
|
||||
## Where the core sits in the mannequin skeleton's space (its front is +Z): on the front of the
|
||||
## chest, a little more than half sunk in; the bone it rides; and the fallback spot in the
|
||||
## model's space (it faces -Z) for a model without that bone.
|
||||
const CORE_SPOT := Vector3(0.0, 0.93, 0.25)
|
||||
const CORE_BONE := "chest"
|
||||
const CORE_SPOT_MODEL := Vector3(0.0, 0.87, -0.25)
|
||||
const CORE_COLOR := Color(0.3, 0.62, 1.0)
|
||||
const CORE_GEM_COLOR := Color(0.5, 0.8, 1.0)
|
||||
## Seconds per pulse, and the light's and the halo's strength from the pulse's low to its high.
|
||||
const CORE_PULSE := 2.8
|
||||
const CORE_LIGHT := Vector2(0.25, 0.45)
|
||||
const CORE_HALO := Vector2(0.4, 0.75)
|
||||
## The halo: an additive, camera-facing disc, drawn pulled toward the camera so the chest it
|
||||
## sits in doesn't cut it in half (the body still hides it from behind).
|
||||
const HALO_SHADER := """
|
||||
shader_type spatial;
|
||||
render_mode unshaded, blend_add, depth_draw_never, cull_disabled, shadows_disabled, fog_disabled;
|
||||
|
||||
uniform vec4 color : source_color = vec4(0.3, 0.62, 1.0, 1.0);
|
||||
uniform float strength = 1.0;
|
||||
uniform float pull = 0.2;
|
||||
|
||||
void vertex() {
|
||||
vec3 center = (MODELVIEW_MATRIX * vec4(0.0, 0.0, 0.0, 1.0)).xyz;
|
||||
vec3 at = center + vec3(VERTEX.xy, 0.0) + normalize(-center) * pull;
|
||||
POSITION = PROJECTION_MATRIX * vec4(at, 1.0);
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
float d = length(UV - 0.5) * 2.0;
|
||||
ALBEDO = color.rgb;
|
||||
ALPHA = strength * pow(clamp(1.0 - d, 0.0, 1.0), 2.2);
|
||||
}
|
||||
"""
|
||||
|
||||
var alive := true
|
||||
## Standing still for a channel: no movement input, the channel clip loops.
|
||||
var rooted := false
|
||||
|
|
@ -62,6 +102,13 @@ var _aim := Vector2.ZERO
|
|||
var _aim_hold: float = 0.0
|
||||
var _flash_mat: ShaderMaterial
|
||||
var _tag: Label3D
|
||||
## The core glow's root (hide it to hide all of it), its light and halo, and the pulse's clock.
|
||||
var core_glow: Node3D
|
||||
var _core_light: OmniLight3D
|
||||
var _core_halo: ShaderMaterial
|
||||
var _core_time: float = 0.0
|
||||
## The halo's shader, compiled once for every scarecrow.
|
||||
static var _halo_shader: Shader
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -69,6 +116,13 @@ func _ready() -> void:
|
|||
_flash_mat.shader = load("res://prototype/resources/hit_flash.gdshader") as Shader
|
||||
for mi in model.find_children("*", "MeshInstance3D", true, false):
|
||||
(mi as MeshInstance3D).material_overlay = _flash_mat
|
||||
_build_core_glow()
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if core_glow != null and core_glow.visible:
|
||||
_core_time = fmod(_core_time + delta, CORE_PULSE)
|
||||
_pulse_core()
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
|
|
@ -157,10 +211,95 @@ func _end_sprint() -> void:
|
|||
sprint_recharge = config.sprint_cooldown if config != null else 0.0
|
||||
|
||||
|
||||
## Tints the model (co-op: player 2's scarecrow is blue).
|
||||
## Shows or hides the core glow in the chest (on from the start).
|
||||
func set_core_glow(on: bool) -> void:
|
||||
if core_glow != null:
|
||||
core_glow.visible = on
|
||||
|
||||
|
||||
## The core glow: on the chest bone (through a BoneAttachment3D) when the model has one, else on
|
||||
## the model at chest height.
|
||||
func _build_core_glow() -> void:
|
||||
var parent: Node3D = model
|
||||
var spot := CORE_SPOT_MODEL
|
||||
var front := Vector3.FORWARD
|
||||
var down := Vector3.DOWN
|
||||
var skeletons := model.find_children("*", "Skeleton3D", true, false)
|
||||
if not skeletons.is_empty():
|
||||
var skel := skeletons[0] as Skeleton3D
|
||||
var bone := skel.find_bone(CORE_BONE)
|
||||
if bone >= 0:
|
||||
var attach := BoneAttachment3D.new()
|
||||
attach.name = "CoreAttachment"
|
||||
attach.bone_name = CORE_BONE
|
||||
skel.add_child(attach)
|
||||
parent = attach
|
||||
var rest := skel.get_bone_global_rest(bone).affine_inverse() # skeleton -> the bone's space
|
||||
spot = rest * CORE_SPOT
|
||||
front = (rest.basis * Vector3.BACK).normalized()
|
||||
down = (rest.basis * Vector3.DOWN).normalized()
|
||||
core_glow = Node3D.new()
|
||||
core_glow.name = "CoreGlow"
|
||||
core_glow.position = spot
|
||||
parent.add_child(core_glow)
|
||||
|
||||
var gem := MeshInstance3D.new()
|
||||
gem.name = "Gem"
|
||||
var sphere := SphereMesh.new()
|
||||
sphere.radius = 0.06
|
||||
sphere.height = 0.12
|
||||
sphere.radial_segments = 12
|
||||
sphere.rings = 6
|
||||
var gem_mat := StandardMaterial3D.new()
|
||||
gem_mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
gem_mat.albedo_color = CORE_GEM_COLOR
|
||||
sphere.material = gem_mat
|
||||
gem.mesh = sphere
|
||||
gem.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
|
||||
core_glow.add_child(gem)
|
||||
|
||||
var halo := MeshInstance3D.new()
|
||||
halo.name = "Halo"
|
||||
var quad := QuadMesh.new()
|
||||
quad.size = Vector2(0.55, 0.55)
|
||||
if _halo_shader == null:
|
||||
_halo_shader = Shader.new()
|
||||
_halo_shader.code = HALO_SHADER
|
||||
_core_halo = ShaderMaterial.new()
|
||||
_core_halo.shader = _halo_shader
|
||||
_core_halo.set_shader_parameter("color", CORE_COLOR)
|
||||
halo.mesh = quad
|
||||
halo.material_override = _core_halo
|
||||
halo.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
|
||||
halo.extra_cull_margin = 0.5 # the shader moves it toward the camera
|
||||
core_glow.add_child(halo)
|
||||
|
||||
_core_light = OmniLight3D.new()
|
||||
_core_light.name = "CoreLight"
|
||||
_core_light.light_color = CORE_COLOR
|
||||
_core_light.omni_range = 2.2
|
||||
_core_light.omni_attenuation = 1.0
|
||||
_core_light.shadow_enabled = false
|
||||
# Just in front of the chest and a little below the core, so it lights the arms and the ground
|
||||
# more than the face.
|
||||
_core_light.position = front * 0.25 + down * 0.08
|
||||
core_glow.add_child(_core_light)
|
||||
_pulse_core()
|
||||
|
||||
|
||||
## The pulse: a slow sine between the light's and the halo's low and high.
|
||||
func _pulse_core() -> void:
|
||||
var k := 0.5 + 0.5 * sin(TAU * _core_time / CORE_PULSE)
|
||||
_core_light.light_energy = lerpf(CORE_LIGHT.x, CORE_LIGHT.y, k)
|
||||
_core_halo.set_shader_parameter("strength", lerpf(CORE_HALO.x, CORE_HALO.y, k))
|
||||
|
||||
|
||||
## Tints the model (co-op: player 2's scarecrow is blue), all but the core glow.
|
||||
func set_tint(color: Color) -> void:
|
||||
for mi in model.find_children("*", "MeshInstance3D", true, false):
|
||||
var m := mi as MeshInstance3D
|
||||
if core_glow != null and core_glow.is_ancestor_of(m):
|
||||
continue
|
||||
var base := m.get_active_material(0)
|
||||
if base is BaseMaterial3D:
|
||||
var tinted := (base as BaseMaterial3D).duplicate() as BaseMaterial3D
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ extends RefCounted
|
|||
## stop rendering in 3D (they'd be pixelated) and ScreenLabels draws them as flat text where they
|
||||
## project, at least MIN_SIZE tall, only while shown and in front of the camera, and nudged apart
|
||||
## where they'd overlap.
|
||||
## The opening intro's hooks into the look and sound: DayNight.forced holds the morning or the
|
||||
## night look whatever the phase (and lets go again), lanterns_dark keeps the lanterns off, the
|
||||
## intro's sound cues have their sounds, and every scarecrow has its blue core glow in its chest
|
||||
## (on the chest bone, toon look, tint, and hit flash leaving it alone) until set_core_glow(false).
|
||||
|
||||
const TOON := "res://game/resources/toon.gdshader"
|
||||
const TOON_DOUBLE_SIDED := "res://game/resources/toon_double_sided.gdshader"
|
||||
|
|
@ -141,11 +145,68 @@ func _farm(r: GameTestRunner) -> void:
|
|||
and outline.cast_shadow == GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
|
||||
and outline_mat.render_priority == Material.RENDER_PRIORITY_MIN,
|
||||
"the outline quad is in the world, casts no shadow, and draws under the transparent effects")
|
||||
_intro_hooks(r, sim, a)
|
||||
look.queue_free()
|
||||
farm.queue_free()
|
||||
await r.process_frame
|
||||
|
||||
|
||||
func _intro_hooks(r: GameTestRunner, sim: FarmSim, partner: Avatar) -> void:
|
||||
var dn := sim.day_night
|
||||
var c := sim.campaign
|
||||
c.begin_day()
|
||||
dn.forced = "night"
|
||||
dn.snap()
|
||||
r.check(dn.target() == DayNight.NIGHT and is_equal_approx(sim.sun.light_energy, float(DayNight.NIGHT["energy"]))
|
||||
and is_equal_approx(dn.lantern.light_energy, float(DayNight.NIGHT["lantern"])),
|
||||
"DayNight.forced = \"night\" holds the night look by day, the lantern lit")
|
||||
dn.lanterns_dark = true
|
||||
dn.snap()
|
||||
var lit := dn.lanterns.filter(func(l: OmniLight3D) -> bool: return l.light_energy != 0.0)
|
||||
r.check(dn.lanterns.size() == 2 and lit.is_empty(), "lanterns_dark keeps the lanterns off at night")
|
||||
dn.lanterns_dark = false
|
||||
dn.forced = "morning"
|
||||
dn.snap()
|
||||
r.check(dn.target() == DayNight.morning() and dn.target() != DayNight.DAY
|
||||
and is_equal_approx(sim.sun.light_energy, float(DayNight.morning()["energy"])),
|
||||
"forced = \"morning\" holds the morning look by day")
|
||||
dn.forced = ""
|
||||
dn.snap()
|
||||
r.check(dn.target() == DayNight.DAY and is_equal_approx(sim.sun.light_energy, float(DayNight.DAY["energy"]))
|
||||
and is_equal_approx(dn.lantern.light_energy, 0.0), "cleared, the phase's look comes back")
|
||||
|
||||
var audio := sim.audio
|
||||
var missing: Array[String] = []
|
||||
for cue in ["door_creak", "car_door", "ufo_hum", "ufo_whine", "part_fall", "life_flash", "ufo_zoom"]:
|
||||
if audio.stream_of(cue) == null or not FarmAudio.LOCAL_CUES.has(cue):
|
||||
missing.append(cue)
|
||||
var hum := audio.stream_of("ufo_hum") as AudioStreamWAV
|
||||
r.check(missing.is_empty() and hum != null and hum.loop_mode == AudioStreamWAV.LOOP_FORWARD,
|
||||
"the intro's sounds resolve and stay local, and the UFO's hum loops (missing: %s)" % [missing])
|
||||
|
||||
for body: PlayerCharacter in [sim.player, partner.body]:
|
||||
var who := "player 1's" if body == sim.player else "the partner's"
|
||||
var glow := body.core_glow
|
||||
var attach := glow.get_parent() as BoneAttachment3D if glow != null else null
|
||||
var gem := glow.get_node("Gem") as MeshInstance3D if glow != null else null
|
||||
var gem_mat := gem.get_active_material(0) as StandardMaterial3D if gem != null else null
|
||||
r.check(glow != null and glow.is_visible_in_tree() and attach != null and attach.bone_name == PlayerCharacter.CORE_BONE
|
||||
and gem_mat != null and gem_mat.albedo_color == PlayerCharacter.CORE_GEM_COLOR and gem.material_overlay == null,
|
||||
"%s scarecrow has its core glow on the chest bone, untinted, untouched by the toon look and the hit flash" % who)
|
||||
var rel := glow.global_position - body.global_position if glow != null else Vector3.ZERO
|
||||
var ahead := rel.dot(-body.model.global_basis.z)
|
||||
r.check(rel.y > 0.7 and rel.y < 1.2 and ahead > 0.15, "at chest height on its front (%.2f m up, %.2f m ahead)" % [rel.y, ahead])
|
||||
var mannequin := sim.player.model.find_children("Mannequin_Medium_*", "MeshInstance3D", true, false)
|
||||
r.check(mannequin.size() == 6 and mannequin.all(func(m: Node) -> bool: return (m as MeshInstance3D).material_overlay != null),
|
||||
"the hit flash still covers the scarecrow's body (%d parts)" % mannequin.size())
|
||||
var light := sim.player.core_glow.get_node("CoreLight") as OmniLight3D
|
||||
sim.player.set_core_glow(false)
|
||||
r.check(not sim.player.core_glow.visible and not light.is_visible_in_tree() and partner.body.core_glow.visible,
|
||||
"set_core_glow(false) hides it, light and all")
|
||||
sim.player.set_core_glow(true)
|
||||
r.check(light.is_visible_in_tree(), "and set_core_glow(true) shows it again")
|
||||
|
||||
|
||||
## The nodes under root still showing a lit StandardMaterial3D, by name.
|
||||
static func _lit_left(root: Node) -> Array[String]:
|
||||
var out: Array[String] = []
|
||||
|
|
|
|||
|
|
@ -12,6 +12,14 @@ extends SceneTree
|
|||
## torch tick; back-to-back plays blend into one roar)
|
||||
## alien_beam.wav a buzzing, warbling ray hum over a high whine and a fizz (an alien ray
|
||||
## tick; back-to-back plays blend into one hum)
|
||||
## and the opening intro's (OpeningIntro):
|
||||
## ufo_hum.wav 4 s loop: the big UFO's low, wobbling, beating drone and a faint warble
|
||||
## ufo_whine.wav a 2 s spin-up: a whine rising faster and faster, pulsing as it spins
|
||||
## part_fall.wav a 1.5 s falling whistle, louder as it comes down (the thud is "fall")
|
||||
## life_flash.wav the blue flash: a crack, a rising zap, a low whomp, and a shimmer of
|
||||
## sparkles dying away
|
||||
## ufo_zoom.wav the UFO leaving: a whoosh and a hum whose pitch drops away (doppler)
|
||||
## car_door.wav a car door slamming: a latch click and a dull metal thunk
|
||||
## Loops carry a WAV 'smpl' loop point, so the importer's "Detect From WAV" loops them; every
|
||||
## periodic part of a loop has a whole number of cycles in it and filtered noise is warmed up
|
||||
## on the loop's own tail, so the seam is silent. Run with the editor closed, then let the
|
||||
|
|
@ -44,6 +52,19 @@ func _initialize() -> void:
|
|||
_write("torch_roar.wav", _roar(0.42), false)
|
||||
_rng.seed = 19 # its own seed too
|
||||
_write("alien_beam.wav", _beam(0.34), false)
|
||||
# The opening intro's, each on its own seed as well.
|
||||
_rng.seed = 23
|
||||
_write("ufo_hum.wav", _hum(4.0), true)
|
||||
_rng.seed = 29
|
||||
_write("ufo_whine.wav", _whine(2.0), false)
|
||||
_rng.seed = 31
|
||||
_write("part_fall.wav", _whistle(1.5), false)
|
||||
_rng.seed = 37
|
||||
_write("life_flash.wav", _life_flash(1.4), false)
|
||||
_rng.seed = 41
|
||||
_write("ufo_zoom.wav", _zoom(2.2), false)
|
||||
_rng.seed = 43
|
||||
_write("car_door.wav", _door(0.5), false)
|
||||
quit(0)
|
||||
|
||||
|
||||
|
|
@ -162,6 +183,33 @@ func _night(seconds: float) -> PackedFloat32Array:
|
|||
return _normalize(buf, 0.45)
|
||||
|
||||
|
||||
## The big UFO hovering: two buzzy low tones a little apart (so they beat), both wobbling in
|
||||
## pitch, under a faint high warble, throbbing, over a low rumble. Every cycle and wobble is a
|
||||
## whole number of times in the loop (the wobbles' phase is integrated exactly), so it's seamless.
|
||||
func _hum(seconds: float) -> PackedFloat32Array:
|
||||
var n := int(seconds * RATE)
|
||||
var rumble := _noise_lowpass(n, 120.0)
|
||||
var buf := PackedFloat32Array()
|
||||
buf.resize(n)
|
||||
# (Hz, wobble Hz, wobble depth, level): 220, 227, and 1320 cycles in 4 s; wobbles of 6 and 20.
|
||||
var voices := [[55.0, 1.5, 0.03, 1.0], [56.75, 1.5, 0.03, 0.7], [330.0, 5.0, 0.015, 0.12]]
|
||||
for i in n:
|
||||
var t := float(i) / RATE
|
||||
var s := 0.0
|
||||
for v: Array in voices:
|
||||
var f: float = v[0]
|
||||
var rate: float = v[1]
|
||||
var phase := f * t + f * float(v[2]) * (1.0 - cos(TAU * rate * t)) / (TAU * rate)
|
||||
if f < 100.0:
|
||||
for h in range(1, 7):
|
||||
s += float(v[3]) * sin(TAU * phase * h) / pow(h, 1.2)
|
||||
else:
|
||||
s += float(v[3]) * (0.8 + 0.2 * sin(TAU * 0.5 * t)) * sin(TAU * phase)
|
||||
var throb := 0.75 + 0.25 * sin(TAU * 3.0 * t) # 12 throbs in 4 s
|
||||
buf[i] = throb * s + 0.35 * rumble[i]
|
||||
return _normalize(buf, 0.6)
|
||||
|
||||
|
||||
func _engine(seconds: float) -> PackedFloat32Array:
|
||||
var n := int(seconds * RATE)
|
||||
var rumble := _noise_lowpass(n, 180.0)
|
||||
|
|
@ -302,6 +350,143 @@ func _beam(length: float) -> PackedFloat32Array:
|
|||
return _normalize(buf, 0.7)
|
||||
|
||||
|
||||
## The UFO spinning up: a whine (and a fifth above it) sweeping up faster and faster from a low
|
||||
## hum, pulsing quicker as it spins, over a rising rush of air; it ends at its peak.
|
||||
func _whine(length: float) -> PackedFloat32Array:
|
||||
var n := int(length * RATE)
|
||||
var air := _band_sweep(n, 300.0, 3000.0, 0.15)
|
||||
var buf := PackedFloat32Array()
|
||||
buf.resize(n)
|
||||
var phase := 0.0
|
||||
var spin := 0.0
|
||||
for i in n:
|
||||
var u := float(i) / n
|
||||
var f := 140.0 * pow(1800.0 / 140.0, pow(u, 1.3))
|
||||
phase += f / RATE
|
||||
spin += lerpf(3.0, 28.0, u * u) / RATE
|
||||
var pulse := 1.0 - 0.35 * (0.5 + 0.5 * sin(TAU * spin))
|
||||
var tone := sin(TAU * phase) + 0.3 * sin(TAU * phase * 2.0) + 0.12 * sin(TAU * phase * 3.0) \
|
||||
+ 0.4 * sin(TAU * phase * 1.5)
|
||||
var env := minf(u / 0.08, 1.0) * (0.45 + 0.55 * u) * minf((1.0 - u) / 0.04, 1.0)
|
||||
buf[i] = env * (pulse * tone + 0.6 * u * air[i])
|
||||
return _normalize(buf, 0.7)
|
||||
|
||||
|
||||
## A falling whistle: a near-pure tone gliding down (with a breath of air), swelling as it
|
||||
## comes; it stops dead where the part lands.
|
||||
func _whistle(length: float) -> PackedFloat32Array:
|
||||
var n := int(length * RATE)
|
||||
var air := _noise_lowpass(n, 5000.0)
|
||||
var air_low := _noise_lowpass(n, 1500.0)
|
||||
var buf := PackedFloat32Array()
|
||||
buf.resize(n)
|
||||
var phase := 0.0
|
||||
for i in n:
|
||||
var t := float(i) / RATE
|
||||
var u := float(i) / n
|
||||
phase += 1900.0 * pow(620.0 / 1900.0, u) * (1.0 + 0.008 * sin(TAU * 6.0 * t)) / RATE
|
||||
var env := minf(u / 0.13, 1.0) * (0.4 + 0.6 * u) * minf((1.0 - u) / 0.025, 1.0)
|
||||
buf[i] = env * (sin(TAU * phase) + 0.15 * sin(TAU * phase * 2.0) + 0.25 * (air[i] - air_low[i]))
|
||||
return _normalize(buf, 0.6)
|
||||
|
||||
|
||||
## The blue flash that brings the scarecrow to life: a sharp crack, a buzzy zap sweeping up, a
|
||||
## low whomp under it, and a shimmer of high sparkles that flicker and die away.
|
||||
func _life_flash(length: float) -> PackedFloat32Array:
|
||||
var n := int(length * RATE)
|
||||
var white := _noise_lowpass(n, 9000.0)
|
||||
var white_low := _noise_lowpass(n, 2000.0)
|
||||
var buf := PackedFloat32Array()
|
||||
buf.resize(n)
|
||||
var zap := 0.0
|
||||
var whomp := 0.0
|
||||
for i in n:
|
||||
var t := float(i) / RATE
|
||||
zap += (220.0 * pow(8.0, minf(t / 0.2, 1.0))) / RATE
|
||||
whomp += lerpf(110.0, 55.0, minf(t / 0.4, 1.0)) / RATE
|
||||
var buzz := 0.0
|
||||
for h in [1, 3, 5]: # (the 7th would pass the Nyquist limit at the top of the sweep)
|
||||
buzz += sin(TAU * zap * h) / h
|
||||
var zap_env := minf(t / 0.01, 1.0) * (1.0 if t < 0.2 else exp(-(t - 0.2) * 8.0))
|
||||
buf[i] = 0.7 * minf(t / 0.001, 1.0) * (white[i] - white_low[i]) * exp(-t * 30.0) + 0.5 * zap_env * buzz \
|
||||
+ 0.5 * minf(t / 0.005, 1.0) * sin(TAU * whomp) * exp(-t * 6.0)
|
||||
for k in 14: # the sparkles
|
||||
var f := _rng.randf_range(2000.0, 6500.0)
|
||||
var trem := _rng.randf_range(8.0, 20.0)
|
||||
var at := _rng.randf_range(0.0, 0.25)
|
||||
var amp := _rng.randf_range(0.04, 0.08)
|
||||
for i in range(int(at * RATE), n):
|
||||
var t := float(i) / RATE - at
|
||||
var flicker := 0.5 + 0.5 * sin(TAU * trem * t)
|
||||
buf[i] += amp * minf(t / 0.02, 1.0) * exp(-t * 2.6) * flicker * sin(TAU * f * t)
|
||||
return _normalize(buf, 0.8)
|
||||
|
||||
|
||||
## The UFO zooming off: a rush of air and a buzzy hum, both dropping in pitch as it goes (fast
|
||||
## at first, then settling: a doppler fall) and fading away.
|
||||
func _zoom(length: float) -> PackedFloat32Array:
|
||||
var n := int(length * RATE)
|
||||
var air := _band_sweep(n, 2600.0, 350.0, 0.15)
|
||||
var buf := PackedFloat32Array()
|
||||
buf.resize(n)
|
||||
var phase := 0.0
|
||||
for i in n:
|
||||
var t := float(i) / RATE
|
||||
var u := float(i) / n
|
||||
phase += (260.0 + 690.0 * exp(-u * 4.0)) * (1.0 + 0.02 * sin(TAU * 7.0 * t)) / RATE
|
||||
var tone := 0.0
|
||||
for h in [1, 3, 5]:
|
||||
tone += sin(TAU * phase * h) / h
|
||||
var env := minf(u / 0.03, 1.0) * pow(1.0 - u, 1.6)
|
||||
buf[i] = env * (0.5 * tone + 0.8 * air[i])
|
||||
return _normalize(buf, 0.75)
|
||||
|
||||
|
||||
## A car door slamming: the latch's click (and a second as it catches), then a dull thunk: a low
|
||||
## thump, a few damped, out-of-tune panel tones, and a puff of low noise.
|
||||
func _door(length: float) -> PackedFloat32Array:
|
||||
var n := int(length * RATE)
|
||||
var click := _noise_lowpass(n, 9000.0)
|
||||
var click_low := _noise_lowpass(n, 3000.0)
|
||||
var thud := _noise_lowpass(n, 400.0)
|
||||
var buf := PackedFloat32Array()
|
||||
buf.resize(n)
|
||||
var hit := 0.006 # the thunk starts just after the first click
|
||||
var panel := [[143.0, 14.0, 0.5], [231.0, 18.0, 0.35], [389.0, 24.0, 0.22], [612.0, 30.0, 0.14], [980.0, 40.0, 0.08]]
|
||||
var phase := 0.0
|
||||
for i in n:
|
||||
var t := float(i) / RATE
|
||||
var s := 0.35 * minf(t / 0.0005, 1.0) * (click[i] - click_low[i]) * exp(-t / 0.0015)
|
||||
if t > 0.035:
|
||||
s += 0.2 * (click[i] - click_low[i]) * exp(-(t - 0.035) / 0.0012)
|
||||
if t >= hit:
|
||||
var th := t - hit
|
||||
phase += lerpf(85.0, 62.0, minf(th / 0.15, 1.0)) / RATE
|
||||
var attack := minf(th / 0.002, 1.0)
|
||||
s += attack * sin(TAU * phase) * exp(-th * 16.0)
|
||||
for p: Array in panel:
|
||||
s += attack * float(p[2]) * sin(TAU * float(p[0]) * th) * exp(-th * float(p[1]))
|
||||
s += 0.6 * attack * thud[i] * exp(-th * 25.0)
|
||||
buf[i] = s
|
||||
return _normalize(buf, 0.85)
|
||||
|
||||
|
||||
## White noise through a resonant band whose center glides from f0 to f1 (q: lower is narrower).
|
||||
func _band_sweep(n: int, f0: float, f1: float, q: float) -> PackedFloat32Array:
|
||||
var buf := PackedFloat32Array()
|
||||
buf.resize(n)
|
||||
var low := 0.0
|
||||
var band := 0.0
|
||||
for i in n:
|
||||
var u := float(i) / n
|
||||
var w := TAU * f0 * pow(f1 / f0, u) / RATE
|
||||
var high := _rng.randf_range(-1.0, 1.0) - low - q * band
|
||||
band += w * high
|
||||
low += w * band
|
||||
buf[i] = band
|
||||
return _normalize(buf, 1.0)
|
||||
|
||||
|
||||
func _horn() -> PackedFloat32Array:
|
||||
var n := int(0.9 * RATE)
|
||||
var buf := PackedFloat32Array()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue