A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate
in the Unity community.
Introducing the new Universal Render Pipeline and High Definition Render Pipeline subforums!
Unity 2019.3 Beta is out now.
Discussion in 'Unity 5 Pre-order Beta' started by nickw4rd, Nov 14, 2014.
How can I change the Emission value of a standard shader using c#?
Alright starting over. I have a model that came from studio max with a multi-sub object material. The model has 6 materials all together. How can I go in and change the Emission Color of one of those materials?
I can do it with a model with a single material on it with:
GetComponent<Renderer>().material.SetColor ("_EmissionColor", Color.black);
Any help would be great. Thanks!
So where's the difficulty then?
looks like no one can halp, so problem is actual for me too
// First you want to use the API with multiple materials
// where 3 should be the index you want to use...
var materials = GetComponent<Renderer>().materials;
materials.SetColor ("_EmissionColor", Color.blue);
// Another thing to note is that Unity 5 uses the concept of shader keywords extensively.
// So if your material is initially configured to be without emission, then in order to enable emission, you need to enable // the keyword.
Oh and if you actually want to set it to black, then of course EnableKeyword is not necessary. In fact DisableKeyword in that case will make your shader run faster, because it will define out the math that deals with emissive surfaces, but of course the difference may or may not be huge depending on what you do, it may very well not be worth it to do that kind of optimization with switching enable / disable keywords.
i tried, but unfortunately nothing changed, looks like emission color do not work for unity's standard shader
You might have to call DynamicGI.UpdateMaterials as well.
You are giving up too easily. They work, I use them all over the place.
This is only necessary if you actually want to animate emissive lighting. Do you want to animate emissive lighting?
As a starting point. I would suggest first trying it out in the material editor. So you can quickly see the results of changing the colors / textures assigned etc. This way you can prove to yourself or others that the rendering feature does indeed work.
Once you know that the rendering actually works and the content looks as you expect it, then it makes sense to script it. As explained above.
The correct answer is
Color finalValue=Color.White*someValue; // someValue adjust the scale of emission
DynamicGI.SetEmissive(GetComponent<Renderer>(), finalValue); // Pass your objet's renderer which emissive material attached
if you want to change emissive value at run time and affect GI. I have tested it and it works.