mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-14 14:43:47 +00:00
Animated acid shader
This commit is contained in:
parent
f7240e1167
commit
6777cb1447
5 changed files with 301 additions and 217 deletions
|
|
@ -2,5 +2,38 @@
|
|||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue