Add shaders pre-warming
This commit is contained in:
74
core/shader_warmup.gd
Normal file
74
core/shader_warmup.gd
Normal file
@@ -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.")
|
||||
1
core/shader_warmup.gd.uid
Normal file
1
core/shader_warmup.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d16jx65gmy20b
|
||||
Reference in New Issue
Block a user