Adjusting hue/tint for material color?

Hello, as documentation shows, you can render a specific material a specific color. However, I would like to only change the tint or hue of the material a bit, not the entire material flushed to a specific color. Is there a reasonable way to program this, or am I better off just creating different materials? If it is possible, is it a performance saver? I think Unitys Terrain system does this with trees?

I think you are talking about Material.color. How this is handled depends entirely on the shader you are using. Some shaders use it to tint, some shaders use it for the entire color, and some shaders don’t use it at all. If you have the right shader, it is as simple as:

renderer.material.color = someColor;

Performance is an interesting question. If you are doing this to only few game object, then it is likely a bit less expensive than swapping out the whole material. If you are doing this to a bunch of game object, then this can be significantly expensive. Alternate, less expensive but more complicated solutions include:

  • Using a shader that supports vertex colors and rewriting the vertex colors directly in the mesh.
  • Using UV coordinates in the mesh to change the texture used in the mesh.

I’d only go to the trouble of these two solutions if you have a lot of game object you are trying to tint, and/or if you are targeting mobile.

Note many shaders ‘overbrighten’ colors. For these shaders you have to set the alpha of the color to 0.5 to get the tint/color you expect.