From 8bc4970d3459c5b49b31ce3c1427f2cf2ca5af06 Mon Sep 17 00:00:00 2001 From: Michele Rossi Date: Thu, 28 May 2026 00:12:26 +0200 Subject: [PATCH] Add shaders pre-warming --- core/shader_warmup.gd | 74 +++++++++++++++++++++++++++++++++++++++ core/shader_warmup.gd.uid | 1 + project.godot | 1 + 3 files changed, 76 insertions(+) create mode 100644 core/shader_warmup.gd create mode 100644 core/shader_warmup.gd.uid diff --git a/core/shader_warmup.gd b/core/shader_warmup.gd new file mode 100644 index 0000000..014a31a --- /dev/null +++ b/core/shader_warmup.gd @@ -0,0 +1,74 @@ +extends Node +## Autoload — pre-warms custom shaders on startup by rendering each +## ShaderMaterial once in a hidden 64×64 viewport. +## +## StandardMaterial3D is covered by ubershaders (already enabled). +## This catches the custom .gdshader materials that ubershaders miss. + +# Paths to all ShaderMaterial .tres files with custom shaders +const MATERIAL_PATHS: Array[String] = [ + "res://core/daynight/environment_dust_material.tres", + "res://core/daynight/environment_shadows.tres", + "res://core/daynight/godrays.tres", + "res://core/daynight/weather_overlay.tres", + "res://core/daynight/weather_plain_shader.tres", + "res://core/biome_generator/wires.tres", + "res://tgcc/chunk/prop/grass/grass_chunk.tres", + "res://tgcc/chunk/prop/grass/grass_chunk_weeds.tres", + "res://tgcc/chunk/prop/grass/grass_chunk_weeds2.tres", + "res://tgcc/chunk/prop/grass/grass_bank.tres", + "res://tgcc/chunk/prop/tree/leaves_tree1.tres", + "res://tgcc/chunk/prop/tree/leaves_tree_small.tres", + "res://tgcc/chunk/prop/tree/trunk.tres", + "res://tgcc/chunk/prop/flower/flower.tres", + "res://tgcc/chunk/prop/flower/bush.tres", + "res://tgcc/chunk/prop/house/house_emissiv.tres", + "res://tgcc/chunk/prop/tenda noren/tenda.tres", + "res://tgcc/chunk/prop/Tori/Tori.tres", + "res://tgcc/chunk/prop/zen garden/zengardenCircle.tres", + "res://tgcc/chunk/prop/zen garden/zengarden.tres", +] + + +func _ready() -> void: + await get_tree().process_frame + warmup() + + +func warmup() -> void: + var valid: Array[ShaderMaterial] = [] + for path in MATERIAL_PATHS: + if not ResourceLoader.exists(path): + continue + var mat := load(path) + if mat is ShaderMaterial: + valid.append(mat) + + if valid.is_empty(): + return + + print("[ShaderWarmup] Pre-warming %d custom ShaderMaterials..." % valid.size()) + + # Tiny hidden viewport — 64×64 is cheap to render + var vp := SubViewport.new() + vp.size = Vector2i(64, 64) + vp.render_target_update_mode = SubViewport.UPDATE_ALWAYS + add_child(vp) + + var cam := Camera3D.new() + cam.current = true + cam.environment = null + vp.add_child(cam) + + var quad := MeshInstance3D.new() + quad.mesh = QuadMesh.new() + quad.mesh.size = Vector2(1, 1) + quad.position = Vector3(0, 0, -2) + cam.add_child(quad) + + for mat in valid: + quad.material_override = mat + await get_tree().process_frame # one frame renders the quad with this material + + vp.queue_free() + print("[ShaderWarmup] Done.") diff --git a/core/shader_warmup.gd.uid b/core/shader_warmup.gd.uid new file mode 100644 index 0000000..12c0bed --- /dev/null +++ b/core/shader_warmup.gd.uid @@ -0,0 +1 @@ +uid://d16jx65gmy20b diff --git a/project.godot b/project.godot index 8e85bf5..01a5eea 100644 --- a/project.godot +++ b/project.godot @@ -23,6 +23,7 @@ GameState="*uid://b17g2w2g101o6" CollectionManager="*uid://c3kq1qddpm8tf" AudioManager="*uid://dcttbbavtwtsg" SceneManager="*uid://bw8hwkw55j675" +ShaderWarmup="res://core/shader_warmup.gd" [display]