mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 08:55:35 +00:00
35 lines
1.3 KiB
GDScript
35 lines
1.3 KiB
GDScript
@tool
|
|
class_name AcidArea
|
|
extends Area3D
|
|
|
|
const _ACID_SHADER := preload("res://Shaders/Acid.gdshader")
|
|
const _NOISE_TEX_PATH := "res://Shaders/acid_noise.tres"
|
|
|
|
func _init() -> void:
|
|
add_to_group("Acid", true)
|
|
|
|
func _ready() -> void:
|
|
if Engine.is_editor_hint():
|
|
return
|
|
var noise_tex: NoiseTexture2D = null
|
|
if ResourceLoader.exists(_NOISE_TEX_PATH):
|
|
noise_tex = load(_NOISE_TEX_PATH)
|
|
for child in find_children("*", "MeshInstance3D", true, false):
|
|
_apply_shader_to_mesh(child as MeshInstance3D, noise_tex)
|
|
|
|
func _apply_shader_to_mesh(mesh_instance: MeshInstance3D, noise_tex: NoiseTexture2D) -> void:
|
|
var surface_count := mesh_instance.get_surface_override_material_count()
|
|
if surface_count == 0 and mesh_instance.mesh != null:
|
|
surface_count = mesh_instance.mesh.get_surface_count()
|
|
for i in range(surface_count):
|
|
var existing_tex: Texture2D = null
|
|
var existing_mat := mesh_instance.mesh.surface_get_material(i) as BaseMaterial3D
|
|
if existing_mat != null:
|
|
existing_tex = existing_mat.albedo_texture
|
|
var mat := ShaderMaterial.new()
|
|
mat.shader = _ACID_SHADER
|
|
if existing_tex != null:
|
|
mat.set_shader_parameter("albedo_tex", existing_tex)
|
|
if noise_tex != null:
|
|
mat.set_shader_parameter("noise_tex", noise_tex)
|
|
mesh_instance.set_surface_override_material(i, mat)
|