mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 07:45:33 +00:00
39 lines
1.5 KiB
GDScript
39 lines
1.5 KiB
GDScript
@tool
|
|
class_name AcidArea
|
|
extends Area3D
|
|
|
|
const _ACID_SHADER := preload("res://Shaders/Acid.gdshader")
|
|
# Replace this path with your actual noise texture resource once you have one saved on disk.
|
|
# A NoiseTexture2D saved as a .tres file works well here.
|
|
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):
|
|
# Grab the texture func_godot baked into the surface before we replace the material
|
|
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)
|