Search Unity

How to set EmissionMap's color of HDRP/Decal during runtime

Discussion in 'High Definition Render Pipeline' started by libra34567, Apr 21, 2021.

  1. libra34567

    libra34567

    Joined:
    Apr 5, 2014
    Posts:
    62
    So, I'm trying to set HDRP/Decal EmissionMap's color to emission color during runtime.
    I tried:
    decalProjector.material.SetColor("_EMISSIVEMAP", targetColor);

    P.s.:
    1. I have to use EmissionMap instead of BaseColor since I have a PNG to show emission, and it only works if I put it under emissionMap.
    2. This property keyword is the one I found under debug mode inspector. But it's not taken effect, really curious to what went wrong here. upload_2021-4-22_0-55-58.png
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi,
    I think the keyword should be _EmissiveColor.
    Instead of looking to those Shader Keywords, open the HDRP shader sources and check there.
    i.e. in this case it should be Decal.shader file.

    There you can see this:
    Code (HLSL):
    1. [ToggleUI] _Emissive("_Emissive", Range(0.0, 1.0)) = 0.0
    2. [HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
    Then just change it like you did.
    Code (HLSL):
    1. material.SetColor("_EmissiveColor", targetColor);
    Just make sure your exposure or something else in the HDRP won't make the effect invisible.
     
  3. libra34567

    libra34567

    Joined:
    Apr 5, 2014
    Posts:
    62
    Thx man, worked like a charm!
     
  4. MathewHI

    MathewHI

    Joined:
    Mar 29, 2016
    Posts:
    501
    What is a "targetColor"? This is not working:

    material.SetColor("_Color", Color.red);
     
  5. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    Last edited: Feb 25, 2022
    FlightFight likes this.
  6. adrien-de-tocqueville

    adrien-de-tocqueville

    Unity Technologies

    Joined:
    Mar 16, 2020
    Posts:
    270
    _Color property doesn't exist on HDRP/Decal shader
    You should use the _BaseColor property
     
    MathewHI likes this.