Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

HDRP shader change in build lead to BLACK material

Discussion in 'Graphics Experimental Previews' started by Danua, Aug 22, 2019.

  1. Danua

    Danua

    Joined:
    Feb 20, 2015
    Posts:
    195
    Case: HDRP shader change via script in build lead to black material on model.

    upload_2019-8-22_17-2-46.png
    upload_2019-8-22_17-3-22.png
     
  2. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    350
    Without further informations, it will be hard to help you. What/how do you change it through script ? HDRP and Unity version ?
     
  3. Danua

    Danua

    Joined:
    Feb 20, 2015
    Posts:
    195
    ok, HDRP, ShaderGraph 6.9.1. So i think the error is find. If you use vector properties in blackboard, shader graph freeze, and if you force save shadergraph file after that, shader graph file looks broken. And when you're change shader with this code : Mesherenderer().material.shader = "HDRP/Lit"
    model with HDRP lit became BLACK
     
  4. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    350
    Ok, now I understand a bit more:
    1. What is your use case here to change the material's shader ? Wouldn't it be simpler to swpt the whole material for an other ? Because of ...
    2. Have you modified the properties in the blackboard so that the reference names match the properties name in the HDRP/Lit shader ? If not, then when you switch the shader, the properties won't match, and the new one will use it's default values. This might explain your issue.
    TLDR: Switch the material instead of the shader.
     
  5. Danua

    Danua

    Joined:
    Feb 20, 2015
    Posts:
    195
  6. Danua

    Danua

    Joined:
    Feb 20, 2015
    Posts:
    195
    another bug here!
    Modifying "_EmissiveIntensity" properties of HDRP lit shader doesn't affect on material at all, but when i change this intensity through inspector it works, how to do this properly?
    I use GetComponent<MeshRenderer>().material.SetFloat("_EmissiveIntensity", 100f);
     
  7. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    350
    Have you set a non black emissive color and enabled the toggle to use the emission intensity before.
    Also note that we have an check that is made in the inspector that enables a define for emission only when the color is not full black. Else the emission code is stripped out, and changing the values at runtime will have no effect.
    An easy fix it to set a very low (0,0,1/255) emission color value.
     
  8. ivangolod

    ivangolod

    Joined:
    Aug 8, 2018
    Posts:
    2

    should it also work with Unity 2019.1.0f2 ? i get the change of the _EmissiveIntensity number in the Inspector but nothing happens with the light itself.
     
    V_endeta likes this.
  9. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    3,211
    This topic is a bit old, but I believe this is still a problem, and this thread comes up near the top of searches related to _EmissiveIntensity not being adjustable in code.

    I expect there must be something else going on within the editor code for the Lit shader that doesn't occur when setting _EmissiveIntensity via other means. I've been trying to adjust the _EmissionIntensity value via an animation clip, without any success. If I drag the Emissive Intensity slider in the inspector, the emission color changes as expected:

    Emissive Intensity = 0, or 0.001:

    upload_2020-7-13_16-1-19.png

    Emissive Intensity = 10:

    upload_2020-7-13_16-1-59.png

    However, trying to change this value through an animation clip causes no change, no matter what I set the value to:

    upload_2020-7-13_16-2-49.png

    Is there a trick to getting this to work? The only option appears to be disabling Emissive Intensity, and setting the Emissive Color instead. That's okay, but it's just a lot sloppier to look at both in the animator and in code, when all I actually want to do is adjust the intensity.
     
  10. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    699

    Your values are probably too low (Not corresponding with EV 100) or maybe the animator just doesn't know how to deal with the physical values for HDRP (EV 100 or Nits).
     
  11. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    3,211
    Are you saying that you've been able to adjust emission intensity using an animation clip? Care to show the clip you're using? Because in my actual testing, I've been unable to get any emission intensity change using an animation clip.

    I've tried Emissive Intensity values of 10000, with no effect. Note that a value of "10" is enough to get strong emission when using the inspector. I also tried changing the "Emissive Intensity Unit" via the animation clip, trying values like 1 and 2, but that doesn't affect the situaton.
     
    azevedco likes this.
  12. azevedco

    azevedco

    Joined:
    Mar 2, 2014
    Posts:
    3
    Hi dgoyette,
    Through some research today, looks like the only way is to set the _EmissiveColor unfortunately. I had written up a script to allow for controlling the intensity of _EmissiveColor via a single float value, in your position, all you'd have to do is animate that float value.

    Here's my code:

    Code (CSharp):
    1.  
    2. public Renderer targetRenderer;
    3. [Range(0f, 1f)]
    4. public float emissiveIntensity = 0f;
    5. public Color baseEmissiveColor;
    6.      
    7. // You may want to alter this value depending on how intense you want your emissive strength to be
    8. private const float MaxIntensity = 30f;
    9.  
    10. private MaterialPropertyBlock _propBlock;
    11.  
    12. private void OnEnable()
    13. {
    14.      _propBlock = new MaterialPropertyBlock();
    15. }
    16.  
    17. // Update is called once per frame
    18. private void Update()
    19. {
    20.      // Get Material Property Block from Material at first index on specified Glove Renderer
    21.      targetRenderer.GetPropertyBlock(_propBlock, 0);
    22.  
    23.      _propBlock.SetColor("_EmissiveColor", baseEmissiveColor * Mathf.Lerp(0f, MaxIntensity, emissiveIntensity));
    24.  
    25.      // Update Material on specified Glove Renderer at first index of materials
    26.      targetRenderer.SetPropertyBlock(_propBlock, 0);
    27. }
    Unfortunately, I could not get the current color from my target material no matter which approach I took with it. Hence my baseEmissiveColor, which should be set with the same color values from your material.

    In case you haven't heard of MaterialPropertyBlocks, i'd highly recommend their use to avoid modifying the base Material files directly.
    https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.html
    And an excellent article on using them here:
    https://thomasmountainborn.com/2016/05/25/materialpropertyblocks/

    During your animation, animate the emissiveIntensity value. In the end, this approach will only see results during gameplay. Anyways, hope this helps! In case anyone is wondering, this was used on a material using the HDRP/Lit shader.

    Glhf,
    azevedco
     
    V_endeta likes this.
unityunity