Files
tgcc/core/shader_warmup.gd
2026-05-30 15:25:53 +00:00

75 lines
2.3 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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.")