Search Unity

Adjusting Emission Intensity of a material with the HDRP Lit shader at runtime not working

Discussion in 'High Definition Render Pipeline' started by Tashkeel, Sep 20, 2019.

  1. Tashkeel

    Tashkeel

    Joined:
    Mar 13, 2019
    Posts:
    8
    Hello!

    I've been working with HDRP for the past week and have been loving it so far, but I've run into an oddity I was hoping could be cleared up here.

    I'm attempting to change some material parameters (using the HDRP/Lit shader) through code at runtime, but any change I make to the emission intensity (using the "_EmissiveIntensity" flag) seems to have no effect on screen. Heres the line of code I use:

    mesh.material.SetFloat("_EmissiveIntensity", 10f);

    I know I'm setting the right parameter because I see the value in the created instanced material in the inspector changing as I toggle it, but it does not change the appearance of the material. However, when I adjust the same value manually by inputting in the inspector, the material reacts as expected; so is this just a bug in the version of Unity Im running (2019.2.0f1)? Or should I approach things in HDRP differently than I normally would?

    Thanks for any response,
    Tash
     
  2. Tashkeel

    Tashkeel

    Joined:
    Mar 13, 2019
    Posts:
    8
    Update:
    I did just now find a workaround, which was to just make my own simple shader in shadergraph.

    It turns out you can't seem to pipe in any vector value to the emission output for a shader though, so I had to use the 'Emission Node' and feed my exposed float parameter throught the intensity input of that node...In case any of you were running into this!


    I 'AM' still curious as to why it wont work with the standard HDRP/Lit or /Unlit shaders, so if anyone can illuminate me on that, Id still be grateful.
     
  3. Daryoon

    Daryoon

    Joined:
    Sep 6, 2013
    Posts:
    1
    same problem here. values change in the inspector but not reflecting the change to the game.
    if i change the value manually in the inspector at runtime it does reflect the change :(
    2019.01.14f
     
  4. MikeChr

    MikeChr

    Joined:
    Feb 2, 2018
    Posts:
    43
    I am having the same problem. Setting _EmissiveIntensity through inspector works. Setting in C# has no effect.
     
  5. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    I think your answer is the same as this one : https://forum.unity.com/threads/hdr...d-lead-to-black-material.732350/#post-4888181
     
  6. Thromshall

    Thromshall

    Joined:
    Oct 9, 2012
    Posts:
    12
    I'm having the exact same issue where runtime adjustment of the emission does nothing unless I change it in the inspector. I have a non black emissive color and have enabled the toggle to use the emission intensity. Here's my emissive setup:

    upload_2019-12-12_17-56-12.png

    Here's the code I'm using to change the intensity:

    Renderer.material.SetFloat("_EmissiveIntensity", 0);

    I can indeed go see it update in the inspector, to 0, but unless I start to adjust the intensity inside of the inspector, the emission does not change.
     
    GodlikeAurora likes this.
  7. BernieRoehl

    BernieRoehl

    Joined:
    Jun 24, 2010
    Posts:
    81
    You should have the following line somewhere in your code, e.g. in Start() or Awake()...

    yourMaterial.EnableKeyword("_EmissiveIntensity");

    Without it, setting the _EmissiveIntensity value will have no effect.
     
  8. GodlikeAurora

    GodlikeAurora

    Joined:
    Dec 7, 2016
    Posts:
    14
    This thing does nothing in HDRP. In default shaders it does. But maybe I'm doing something wrong..
     
    angelonit likes this.
  9. sigil_tech

    sigil_tech

    Joined:
    Sep 18, 2019
    Posts:
    17
    Access debug mode on your prefab and look at the keywords.
     
    Gryflir likes this.
  10. Laex410

    Laex410

    Joined:
    Mar 18, 2015
    Posts:
    51
    This is definitely a bug. I tried setting the emission intensity float via script and while it updated the value in the material's inspector it didn't actually update the visuals in game. When I change the same value by hand (by the same amount) during runtime it updates as intended.

    As a workaround I used Tashkeels solution and created a simple shader graph with exposed emission intensity var and updated that one. This works the way it is supposed to.
     
  11. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    934
    Hi,

    The GUI code in HDRP setup various thing like Keyword and render state, and can perform some calculation for the correct intensity to setup also.
    We don't have expose API currently to be able to do similar thing at Runtime, so the current workaround is to replicated what the GUI code is doing.

    >yourMaterial.EnableKeyword("_EmissiveIntensity");
    This don't do anything in HDRP.

    hope that help.
     
  12. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    I'm sorry, but how does this help? Why is this broken exactly? I don't understand why things like this still persist in Unity (I remember having issues with this years ago)
     
  13. irenya

    irenya

    Joined:
    Nov 22, 2017
    Posts:
    10
    For anybody else having the same problem, what can be done is changing the actual emission colour of the material. The property is "_EmissiveColor", and you have to untick Use Emission Intensity. In that way, instead of entering a value, you enter an HDR colour. To get an HDR colour, you only have to multiplicate a regular colour by some factor (so multiply each component).
    It's a bit more annoying that simply a value, but it works.
     
  14. jackvob1

    jackvob1

    Joined:
    Mar 2, 2018
    Posts:
    38
    how about the emmision exposure weight anyone know ?
     
  15. fromPaxtaobod

    fromPaxtaobod

    Joined:
    Dec 2, 2014
    Posts:
    5
    Hi.
    It works for my
    mat.SetFloat("_EmissiveExposureWeight", myValue);
     
    MathewHI, mrfvanzwol and oAzuehT like this.
  16. azevedco

    azevedco

    Joined:
    Mar 2, 2014
    Posts:
    34
    This...this works but modifying "_EmissiveIntensity" does not? Unity, please...
     
  17. ChrisLend

    ChrisLend

    Joined:
    Apr 28, 2016
    Posts:
    2
    So this might be a bit off topic, but I was writing an AssetPostprocessor for OnPreprocessMaterialDescription and I was having the issue that the textures didn't show up until I've selected them in the project view.

    using
    Code (CSharp):
    1. material.EnableKeyword("_EMISSIVE_COLOR_MAP");
    worked for me even though SebLagarde's post from before says that it won't. Maybe what that post was meant to say that the old Keywords are not going to work any more. Digging through the HDRP/Lit shader I found some keywords starting with line 235.
    I am using Unity 2020.1 and HDRP 8.1.0
     
  18. Kinnith7

    Kinnith7

    Joined:
    Jul 4, 2017
    Posts:
    84
    Hello, I see it's been a while since this post, but I just did it in Shader Graph. Color Node (Default) & Vector 4 Node, both to Multiply Node and out to Emission slot in PBR Master. Make Color and Vector 4 properties and you can change the emission value with x in vector 4. Just hoping this helps if anyone else stumbles upon this looking for a solution.
     
    zacharyaghaizu likes this.
  19. DavidDreamer

    DavidDreamer

    Joined:
    Oct 14, 2017
    Posts:
    13
  20. HyruleDefender

    HyruleDefender

    Joined:
    Apr 4, 2017
    Posts:
    17
  21. analogupstudios

    analogupstudios

    Joined:
    Jul 3, 2019
    Posts:
    14
    I finally figured this out in HDRP. Hopefully it helps! If you have any questions just let me know. Happy engineering. disolve_shader_HDRP.JPG
    dissolve_gameView.JPG
     
    memosagame likes this.
  22. Mattpc

    Mattpc

    Joined:
    Dec 8, 2019
    Posts:
    1
    You are a true hero man i love you
     
    rmele09 likes this.