- Home /
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?
http://docs.unity3d.com/Documentation/ScriptReference/Color.html
Answer by robertbu · Nov 01, 2013 at 06:32 AM
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.
Your answer
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
Changing two different objects renderer colour 1 Answer
If statement checking material tint color 0 Answers
Change a material color 1 Answer
new Color() not working properly? 1 Answer