feat(ambience): underwater shaders + audio manager + main menu + CC0 assets
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
124
scripts/ambience/AudioManager.gd
Normal file
124
scripts/ambience/AudioManager.gd
Normal file
@@ -0,0 +1,124 @@
|
||||
extends Node
|
||||
|
||||
var music_player: AudioStreamPlayer
|
||||
var ambient_loop: AudioStreamPlayer
|
||||
var whale_player: AudioStreamPlayer
|
||||
|
||||
var _whale_timer: Timer
|
||||
var _music_tween: Tween
|
||||
|
||||
const MUSIC_PATH := "res://audio/music/"
|
||||
const SFX_PATH := "res://audio/sfx/"
|
||||
|
||||
func _ready() -> void:
|
||||
music_player = AudioStreamPlayer.new()
|
||||
music_player.bus = "Music"
|
||||
music_player.volume_db = -10.0
|
||||
add_child(music_player)
|
||||
|
||||
ambient_loop = AudioStreamPlayer.new()
|
||||
ambient_loop.bus = "SFX"
|
||||
ambient_loop.volume_db = -12.0
|
||||
add_child(ambient_loop)
|
||||
|
||||
whale_player = AudioStreamPlayer.new()
|
||||
whale_player.bus = "SFX"
|
||||
whale_player.volume_db = -15.0
|
||||
add_child(whale_player)
|
||||
|
||||
_whale_timer = Timer.new()
|
||||
_whale_timer.one_shot = true
|
||||
_whale_timer.timeout.connect(_on_whale_timer)
|
||||
add_child(_whale_timer)
|
||||
_schedule_next_whale()
|
||||
|
||||
|
||||
func play_music(track_name: String) -> void:
|
||||
var path := MUSIC_PATH + track_name
|
||||
if not ResourceLoader.exists(path):
|
||||
return
|
||||
|
||||
var stream: AudioStream = load(path)
|
||||
if stream == null:
|
||||
return
|
||||
|
||||
music_player.stream = stream
|
||||
music_player.stream.loop = true
|
||||
music_player.volume_db = -40.0
|
||||
music_player.play()
|
||||
|
||||
if _music_tween:
|
||||
_music_tween.kill()
|
||||
_music_tween = create_tween()
|
||||
_music_tween.tween_property(music_player, "volume_db", -10.0, 3.0).set_trans(Tween.TRANS_SINE)
|
||||
|
||||
|
||||
func play_ambient_loop(loop_name: String) -> void:
|
||||
var path := SFX_PATH + loop_name
|
||||
if not ResourceLoader.exists(path):
|
||||
return
|
||||
|
||||
var stream: AudioStream = load(path)
|
||||
if stream == null:
|
||||
return
|
||||
|
||||
ambient_loop.stream = stream
|
||||
ambient_loop.stream.loop = true
|
||||
ambient_loop.play()
|
||||
|
||||
|
||||
func play_whale_call_random() -> void:
|
||||
var path := SFX_PATH + "whale_call.ogg"
|
||||
if not ResourceLoader.exists(path):
|
||||
return
|
||||
if whale_player.playing:
|
||||
return
|
||||
|
||||
var stream: AudioStream = load(path)
|
||||
if stream == null:
|
||||
return
|
||||
|
||||
whale_player.stream = stream
|
||||
whale_player.play()
|
||||
|
||||
|
||||
func play_bubble_sfx(position: Vector3) -> void:
|
||||
var path := SFX_PATH + "bubbles.ogg"
|
||||
if not ResourceLoader.exists(path):
|
||||
return
|
||||
|
||||
var player := AudioStreamPlayer3D.new()
|
||||
player.bus = "SFX"
|
||||
player.volume_db = -8.0
|
||||
player.max_distance = 20.0
|
||||
player.attenuation_model = AudioStreamPlayer3D.ATTENUATION_INVERSE_SQUARE_DISTANCE
|
||||
add_child(player)
|
||||
player.global_position = position
|
||||
|
||||
var stream: AudioStream = load(path)
|
||||
if stream == null:
|
||||
player.queue_free()
|
||||
return
|
||||
|
||||
player.stream = stream
|
||||
player.play()
|
||||
player.finished.connect(player.queue_free)
|
||||
|
||||
|
||||
func set_music_volume(db: float) -> void:
|
||||
music_player.volume_db = db
|
||||
|
||||
|
||||
func set_sfx_volume(db: float) -> void:
|
||||
ambient_loop.volume_db = db
|
||||
whale_player.volume_db = db - 3.0
|
||||
|
||||
|
||||
func _on_whale_timer() -> void:
|
||||
play_whale_call_random()
|
||||
_schedule_next_whale()
|
||||
|
||||
|
||||
func _schedule_next_whale() -> void:
|
||||
_whale_timer.wait_time = randf_range(30.0, 90.0)
|
||||
_whale_timer.start()
|
||||
29
scripts/ambience/MainMenu.gd
Normal file
29
scripts/ambience/MainMenu.gd
Normal file
@@ -0,0 +1,29 @@
|
||||
extends Control
|
||||
|
||||
@onready var _options_popup: Window = $OptionsPopup
|
||||
@onready var _music_slider: HSlider = $OptionsPopup/VBox/MusicSlider
|
||||
@onready var _sfx_slider: HSlider = $OptionsPopup/VBox/SFXSlider
|
||||
|
||||
func _ready() -> void:
|
||||
AudioManager.play_music("underwater_theme.mp3")
|
||||
AudioManager.play_ambient_loop("underwater_ambient.ogg")
|
||||
|
||||
|
||||
func _on_dive_pressed() -> void:
|
||||
get_tree().change_scene_to_file("res://scenes/Main.tscn")
|
||||
|
||||
|
||||
func _on_options_pressed() -> void:
|
||||
_options_popup.popup_centered()
|
||||
|
||||
|
||||
func _on_quit_pressed() -> void:
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
func _on_music_slider_value_changed(value: float) -> void:
|
||||
AudioManager.set_music_volume(linear_to_db(value))
|
||||
|
||||
|
||||
func _on_sfx_slider_value_changed(value: float) -> void:
|
||||
AudioManager.set_sfx_volume(linear_to_db(value))
|
||||
57
scripts/ambience/PlanktonParticles.gd
Normal file
57
scripts/ambience/PlanktonParticles.gd
Normal file
@@ -0,0 +1,57 @@
|
||||
extends GPUParticles3D
|
||||
|
||||
func _ready() -> void:
|
||||
amount = 500
|
||||
lifetime = 10.0
|
||||
one_shot = false
|
||||
explosiveness = 0.0
|
||||
randomness = 1.0
|
||||
visibility_aabb = AABB(Vector3(-50, -30, -50), Vector3(100, 60, 100))
|
||||
|
||||
var process_mat := ParticleProcessMaterial.new()
|
||||
process_mat.emission_shape = ParticleProcessMaterial.EMISSION_SHAPE_BOX
|
||||
process_mat.emission_box_extents = Vector3(50.0, 30.0, 50.0)
|
||||
|
||||
process_mat.direction = Vector3(0.0, 0.0, 0.0)
|
||||
process_mat.spread = 180.0
|
||||
process_mat.initial_velocity_min = 0.0
|
||||
process_mat.initial_velocity_max = 0.1
|
||||
|
||||
process_mat.linear_accel_min = -0.05
|
||||
process_mat.linear_accel_max = 0.05
|
||||
process_mat.radial_accel_min = -0.02
|
||||
process_mat.radial_accel_max = 0.02
|
||||
|
||||
process_mat.damping_min = 0.5
|
||||
process_mat.damping_max = 1.0
|
||||
|
||||
process_mat.scale_min = 0.02
|
||||
process_mat.scale_max = 0.08
|
||||
|
||||
process_mat.color = Color(0.85, 0.92, 1.0, 0.8)
|
||||
|
||||
var grad := Gradient.new()
|
||||
grad.set_color(0, Color(0.85, 0.92, 1.0, 0.0))
|
||||
grad.set_color(1, Color(0.85, 0.92, 1.0, 0.0))
|
||||
grad.add_point(0.1, Color(0.85, 0.92, 1.0, 0.8))
|
||||
grad.add_point(0.9, Color(0.85, 0.92, 1.0, 0.8))
|
||||
var grad_tex := GradientTexture1D.new()
|
||||
grad_tex.gradient = grad
|
||||
process_mat.color_ramp = grad_tex
|
||||
|
||||
process_material = process_mat
|
||||
|
||||
var quad := QuadMesh.new()
|
||||
quad.size = Vector2(0.05, 0.05)
|
||||
|
||||
var mat := StandardMaterial3D.new()
|
||||
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||
mat.billboard_mode = BaseMaterial3D.BILLBOARD_ENABLED
|
||||
mat.emission_enabled = true
|
||||
mat.emission = Color(0.8, 0.9, 1.0)
|
||||
mat.emission_energy_multiplier = 1.5
|
||||
mat.albedo_color = Color(0.85, 0.92, 1.0, 0.8)
|
||||
|
||||
quad.surface_set_material(0, mat)
|
||||
draw_pass_1 = quad
|
||||
44
scripts/ambience/UnderwaterEnvironment.gd
Normal file
44
scripts/ambience/UnderwaterEnvironment.gd
Normal file
@@ -0,0 +1,44 @@
|
||||
extends WorldEnvironment
|
||||
|
||||
func _ready() -> void:
|
||||
var env := Environment.new()
|
||||
|
||||
env.background_mode = Environment.BG_COLOR
|
||||
env.background_color = Color(0.03, 0.12, 0.22)
|
||||
|
||||
env.ambient_light_source = Environment.AMBIENT_SOURCE_COLOR
|
||||
env.ambient_light_color = Color(0.2, 0.4, 0.6)
|
||||
env.ambient_light_energy = 0.4
|
||||
|
||||
env.fog_enabled = true
|
||||
env.fog_light_color = Color(0.1, 0.3, 0.5)
|
||||
env.fog_density = 0.02
|
||||
env.fog_aerial_perspective = 0.3
|
||||
|
||||
env.volumetric_fog_enabled = true
|
||||
env.volumetric_fog_density = 0.04
|
||||
env.volumetric_fog_albedo = Color(0.2, 0.5, 0.7)
|
||||
env.volumetric_fog_emission = Color(0.02, 0.06, 0.1)
|
||||
env.volumetric_fog_emission_energy = 0.1
|
||||
env.volumetric_fog_length = 64.0
|
||||
env.volumetric_fog_detail_spread = 2.0
|
||||
|
||||
env.glow_enabled = true
|
||||
env.glow_intensity = 0.5
|
||||
env.glow_bloom = 0.1
|
||||
env.glow_blend_mode = Environment.GLOW_BLEND_MODE_SOFTLIGHT
|
||||
|
||||
env.ssao_enabled = true
|
||||
env.ssao_radius = 1.0
|
||||
env.ssao_intensity = 1.0
|
||||
env.ssao_power = 1.5
|
||||
env.ssao_detail = 0.5
|
||||
|
||||
env.tone_mapper = Environment.TONE_MAPPER_FILMIC
|
||||
env.exposure = 1.0
|
||||
|
||||
env.adjustment_enabled = true
|
||||
env.adjustment_saturation = 1.1
|
||||
env.adjustment_color_correction = null
|
||||
|
||||
environment = env
|
||||
Reference in New Issue
Block a user