Case: HDRP shader change via script in build lead to black material on model.
Without further informations, it will be hard to help you. What/how do you change it through script ? HDRP and Unity version ?
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
Ok, now I understand a bit more:
- 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 …
- 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.
I’ve solve this issue. I just remove all vector properties from blackboard and then it work fine. It looks like something wrong with blackboard properties?
p.s i’ve found simillar issue here.
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().material.SetFloat(“_EmissiveIntensity”, 100f);
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.
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.
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:
Emissive Intensity = 10:
However, trying to change this value through an animation clip causes no change, no matter what I set the value to:
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.
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).
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.
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:
public Renderer targetRenderer;
[Range(0f, 1f)]
public float emissiveIntensity = 0f;
public Color baseEmissiveColor;
// You may want to alter this value depending on how intense you want your emissive strength to be
private const float MaxIntensity = 30f;
private MaterialPropertyBlock _propBlock;
private void OnEnable()
{
_propBlock = new MaterialPropertyBlock();
}
// Update is called once per frame
private void Update()
{
// Get Material Property Block from Material at first index on specified Glove Renderer
targetRenderer.GetPropertyBlock(_propBlock, 0);
_propBlock.SetColor("_EmissiveColor", baseEmissiveColor * Mathf.Lerp(0f, MaxIntensity, emissiveIntensity));
// Update Material on specified Glove Renderer at first index of materials
targetRenderer.SetPropertyBlock(_propBlock, 0);
}
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.
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
Bump as this still isn’t working in 2021. I think multiplying the color is a bit of a hack…
Hi there, well I looked at LitGUI inspector code, at it seems like multiplying the color is the only way.
This function called each time when intesity changed:
public static void UpdateEmissiveColorFromIntensityAndEmissiveColorLDR(Material material)
{
const string kEmissiveColorLDR = "_EmissiveColorLDR";
const string kEmissiveColor = "_EmissiveColor";
const string kEmissiveIntensity = "_EmissiveIntensity";
if (material.HasProperty(kEmissiveColorLDR) && material.HasProperty(kEmissiveIntensity) && material.HasProperty(kEmissiveColor))
{
// Important: The color picker for kEmissiveColorLDR is LDR and in sRGB color space but Unity don't perform any color space conversion in the color
// picker BUT only when sending the color data to the shader... So as we are doing our own calculation here in C#, we must do the conversion ourselves.
Color emissiveColorLDR = material.GetColor(kEmissiveColorLDR);
Color emissiveColorLDRLinear = new Color(Mathf.GammaToLinearSpace(emissiveColorLDR.r), Mathf.GammaToLinearSpace(emissiveColorLDR.g), Mathf.GammaToLinearSpace(emissiveColorLDR.b));
material.SetColor(kEmissiveColor, emissiveColorLDRLinear * material.GetFloat(kEmissiveIntensity));
}
}
Unfortunatly it is located in
UnityEditor.Rendering.HighDefinition.MaterialExtension so you have to copy it.
Just call it after changing intensity from code.
And in 2024. This is the top hit on google for this.
Here is another way to set the HDRP Lit Shader Emissive Intensity at runtime that I found:
HDMaterial.SetEmissiveIntensity(r.material, 22f, UnityEditor.Rendering.HighDefinition.EmissiveIntensityUnit.EV100);
I don’t even think the pages are on google.
I dunno, but I think it won’t work inside a build but rather only on editor