#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)

granite galleon
#

I'm very beginner with 3D materials, even in Blender and Unity, and I don't really know how to keep the same material but make the color independent of the material.

For now, my game uses a different material for each object to change their colors, but this increases the draw calls and I want to reduce them.

placid meteor
granite galleon
granite galleon
#

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

desert heron
#

do you want it through code ?

#

I use this:

granite galleon
#

Where is it and what it does?

desert heron
boreal briar
#

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
granite galleon
# granite galleon Let me explain, I'm doing an experiment by combining Just Shapes & Beats level d...

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;
}
granite galleon
granite galleon
granite galleon
desert heron
granite galleon
desert heron
desert heron
granite galleon
#

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

drifting ivy