#How can I use the same 3D material, but change the object's color without affecting the rest?
1 messages · Page 1 of 1 (latest)
based on my knowlage of 2D
u have to duplicate in order making it unique material
such as:
var new_material my_obj.material.duplicate()
new_material.set("color..",Color.RED)
my_obj.material = new_material
this method works for me on 2D, im sure u can figure out how to use it on ur project as well?
u can do this manipulations on _ready() script whenever ur object ready
Thank you, I found this same solution on Internet, but the draw calls increases per object and I don't know how to decrease it.
I think that one thing I can do is use the same materials for all objects that don't change color, and duplicate the ones that do
thats pretty much the solution
Isn't there another way to do this without increasing draw calls?
Imagine that I'm coding Just Shapes & Beats obstacles, but with 3D objects
Every object of that game has flashes per object, and that can't be possible by having the same material in each object
Let me explain, I'm doing an experiment by combining Just Shapes & Beats level design and Super Hexagon's gameplay. Everything is made with 3D objects and each object needs to have their own colors
Where is it and what it does?
if you set it to true, Godot will interact with it as a separate material
another option is via mateirial overlay in the Meshinstance
Make a material for each color:
- make it have transparency enabled
- Change blend mode to taste
- Make sure to set render priority to 1 higher than the base material
Interchange those color matarials with a script that changes the material overlay at runtime
What I did here is a code that duplicates the material override and changes the color, but it increases the draw calls (I need each radial part to have independent colors)
for (int i = 0; i < radialParts.Length; i++) {
MeshInstance3D mesh = radialParts[i];
StandardMaterial3D material = (StandardMaterial3D)mesh.MaterialOverride.Duplicate();
material.AlbedoColor = Color.FromHsv(0, 0, i % 2 == 0 ? 0.5f : 0.75f);
mesh.MaterialOverride = material;
}
I enabled it, but it changes the color for every object that has this material too
how do you change the color?
I duplicate the material and change the albedo color
Oohh
for two objects ?
For 8 objects for now with this code
oh wait let me see
I was thinking on doing something similar
I'll explain what I thought to do with this pseudocode:
if (color is different) {
Duplicate the material and change the color
} else {
Assign the same material as every other object
}
And that with each obstacle, but I don't know if this is a good practice or if there are better ways to do this
It sounds like you want per-instance uniforms: https://docs.godotengine.org/en/stable/tutorials/shaders/shader_reference/shading_language.html#per-instance-uniforms