We've been working on a project that uses the standard Unity materials, and we're having an issue with getting the current emissive scale (brightness). There are quite a few answers out there concerning accessing them already, but they don't seem to answer our question.
Basically, we have some point lights and light bulb models underneath them, and we want to be able to control the color and brightness of both the light (easy to do) and the model (requires editing the material's "_EmissionColor" property). We haven't had any issues setting "_EmissionColor", but we can't get the value from "_EmissionScaleUI" since it is UI only.
Other solutions said to simply multiply whatever color we're passing in by some float to scale the emissiveness, but how can we get the current emissive scale? If our lights are at a brightness of "0.5", how do we access "_EmissionScaleUI" to get that value?
Answer by G-Reusch
Mar 03 at 09:12 PM
I don't know of any way to access that specific material property, but if you haven't noticed, the brightness is just the highest value between the r, g, and b of your material's emission color.
So, for example, if your material has a Color of (0.9f, 0.6f, 0.1f), the brightness (or emissive scale as it's referred to behind the scenes) would be 0.9. You can see the brightness change in realtime in the editor if you change the emission color.
To get the current emissive scale of a standard material, just make a function similar to this and multiply the new color you're assigning to "_EmissionColor" by the result:
//Function to find the emissive scale of a material's color (the highest value out of r,g,b)
private float FindScale(Color color)
return color.r < color.g ? (color.g < color.b ? color.b : color.g) : (color.r < color.b ? color.b : color.r);
Thanks! I hadn't noticed that, so this did exactly what we wanted
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
4 People are following this question.
How to change material color to a specific object group's childs..?
Surface Shader issue: property color gets changed
Batch Objects with Different Colors and Scales
Instantiated object material colors
Brightening the colour of a material that can be any colour without shaders.