Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

How to use Emissive Materials with Global Illumination parameter set to Realtime?

Discussion in 'Global Illumination' started by Garrettec, May 30, 2017.

  1. Garrettec

    Garrettec

    Joined:
    Nov 26, 2012
    Posts:
    76
    Hello, could we please get reliable information from developers about how should we use realtime emission?

    Manual simply states: "Realtime - The emissive light from this material will be added to the realtime global illumination calculations for the scene, so the lighting of nearby objects, even moving objects, will be affected by the emitted light." Sounds pretty easy, right? :)

    Wrong, because simple change of material parameters from inspector do nothing. From forum topics I know that we should call some functions from code to set material properties and then some functions to recalculate environment. But it is absolutely unclear which functions exactly? In one topic people say we should use Material.SetColor and then DynamicGI.UpdateEnvironment others say we must use DynamicGI.UpdateMaterials, third person assure that DynamicGI.SetEmissive is only function we need. On the other hand Scripting API on DynamicGI.SetEmissive warn us that subsequent DynamicGI.UpdateMaterials call on any renderer within the system will clear the effects of DynamicGI.SetEmissive... Situation get even more messy considering the fact that all those methods have almost no explanation in Scripting API when should we use them.

    And what about LightProbes, should we update them manually after changing emissive material parameters?

    Would be very nice to have precise instruction and ideally include this instruction into documentation. Thanks in advance!
     
    Last edited: Jun 19, 2017
    Swarley_92 and fffMalzbier like this.
  2. Swarley_92

    Swarley_92

    Joined:
    Oct 26, 2013
    Posts:
    1
    I'm also interested in this info, would be nice to get some explanations! Thanks
     
    Garrettec likes this.
  3. MrClicker89

    MrClicker89

    Joined:
    Feb 16, 2014
    Posts:
    6
    Interesting topic. I would appreciate some professional answers from unity guys here. Thanks.
     
    Garrettec likes this.
  4. kemalakay

    kemalakay

    Unity Technologies

    Joined:
    Jul 12, 2016
    Posts:
    224
    Hi @Garrettec @Swarley_92 and @PavelShchelkun

    Who says that? :)
    material.SetColor or GetColor is useful when you try to change or retrieve color information. For instance, you can do:

    Code (CSharp):
    1.     void Start () {
    2.         emColor = GetComponent<Renderer>().material.GetColor("_EmissionColor");
    3.         rend = GetComponent<Renderer>();
    4.     }
    5.  
    6.     void Update () {
    7.         DynamicGI.SetEmissive(rend, emColor);
    8.     }
    If you search for DynamicGI in manual, you can see this page and it lists all the methods you can use under DynamicGI namespace. When we search for DynamicGI.UpdateEnvironment, we have this page. And I assume this description is not enough: Schedules an update of the environment texture.

    What it really means is that it updates all the information under Environment title in Lighting window, including ambient lighting. So if you're updating ambient light, then yes, you need to call DynamicGI.UpdateEnvironment()

    This one is tricky and it also confused me because it says it's obsolete when you check manual page. We need to fix that. That being said, what you're looking for is RendererExtensions.UpdateGIMaterials(Renderer rend);

    But don't get it wrong, RendererExtensions.UpdateGIMaterials() has nothing to do with emissives. This one is used when you change the albedo property of a renderer/shader. Then, obviously, your indirect light has to be updated as well and this API ensures that. Say you have a green plane and you can see green bounce light on the boxes that are around it. If you don't use RendererExtensions.UpdateGIMaterials(), then green bounce light will remain when you change the albedo property of plane to another color and it will look incorrect. Thus, you need to call this API to update it.

    That third person is correct. Mark your object static, assign a realtime emissive material and use this to update your emissive property with realtime GI. Done.

    You think this page is not enough? Do you suggest that there should be a separate manual page for explaining how this works?

    No need, using DynamicGI.SetEmissive() affects light probes and dynamic objects alike.

    I hope this helps and clarifies the questions in your mind.

    Bonus:
    Multiply emColor in DynamicGI.SetEmissive() code I shared above with Utility.Sine01() to render animated intensity values for your emissive material.

    Thanks,
    Graphics QA Team
     
    Last edited: Jul 28, 2017
    NicolasDuboc and Garrettec like this.
  5. Garrettec

    Garrettec

    Joined:
    Nov 26, 2012
    Posts:
    76
    Thank you, @kemalakay for awesome answer, it really explains everything I wanted to know and even more, DynamicGI.UpdateEnvironment and DynamicGI.UpdateMaterials seems much more useful now, I was completely unaware that we are able to change albedo in realtime and recalculate indirect lighting for it.

    This page make sense only for people who already know what to look for, but person who is studying lighting by reading this manual or watching tutorials will only see little notice that:
    Realtime - The emissive light from this material will be added to the realtime global illumination calculations for the scene, so the lighting of nearby objects, even moving objects, will be affected by the emitted light.
    and no clues that he should use DynamicGI class.

    I believe that there is no need for one more page of manual, several more sentences to the existing one will be more than enough. Something like: "To update emissive color in realtime use DynamicGI.SetEmissive function".
    And little more clarifications to DynamicGI.SetEmissive page, that say that it updates LightProbes and need no more additional actions to work.
     
  6. kemalakay

    kemalakay

    Unity Technologies

    Joined:
    Jul 12, 2016
    Posts:
    224
    We are already planning to update this page because UI for emission property in standard shader has been refactored. And yes, I agree that we should add a paragraph to explain how you can "make it work" with API and refer to right direction. We'll address this as soon as possible. Thanks a lot for the input and feedback. Glad to hear that this helps.
     
    Garrettec likes this.
  7. Garrettec

    Garrettec

    Joined:
    Nov 26, 2012
    Posts:
    76
    @kemalakay I've tested everything you suggested and found one thing you possibly could consider a bug:
    I change Emissive Texture next way
    Code (CSharp):
    1. rend.material.SetTexture("_EmissionMap", Textures[pointer]);
    2. RendererExtensions.UpdateGIMaterials(rend);
    Everything work fine until I call DynamicGI.SetEmissive. After calling SetEmissive at least one time RendererExtensions.UpdateGIMaterials stop doing anything for this particular renderer.

    Not a big deal, I doubt anyone will dynamically switch emissive textures and change color simultaneously, but my conscience is clear, I told you what I found :)
     
    kemalakay likes this.
  8. kemalakay

    kemalakay

    Unity Technologies

    Joined:
    Jul 12, 2016
    Posts:
    224
    Thanks for the heads up @Garrettec I'll report this bug to our grabbag indeed. I hope it's not a showstopper for you :)