I want to change the transparency of a MeshInstance3D at runtime.
Sublimation If you only want to alter transparency, you don't really have to use custom shaders. In fact you don't even need to deal with materials. Mesh instances have the transparency
property that works on top of any assigned shader/material. Simply do:
$MeshInstance.transparency = .5
Hi, i think a meshinstance3d contains no transparency. but you can give a material to the meshinstance3d and to the material an albedotexture for example png with transparency and you can change it from script...
Brachio I have assigned a material to the mesh in the MeshInstance and I want to edit that.
Sublimation you have to use a custom shader.
1 - create you material normaly, either a standard material or ORM.
2 - in material click on the popup menu and "convert to shader". Once you do this you will not be able to tweak the material like you used to, so make sure it has everything you need.
3 - edit the shader on the shader editor. In front of uniform vec4 albedo
, add "instance": instance uniform vec4 albedo
.
4 - now you can change the color of each object that shares the material from gdscript by changing the instance "albedo" using set_instance_shader_parameter("albedo", Vector4(1.0, 1.0, 1.0, 0.5)
You also get access to a new panel in geometry to change the instance in the editor.
Sublimation If you only want to alter transparency, you don't really have to use custom shaders. In fact you don't even need to deal with materials. Mesh instances have the transparency
property that works on top of any assigned shader/material. Simply do:
$MeshInstance.transparency = .5
© 2022 - 2024 — McMap. All rights reserved.