Search Issue Tracker
By Design
Votes
0
Found in
Issue ID
1332471
Regression
No
[HDRP] Setting emission property _EmissiveColor via material and via material property block leads to different results.
Setting the emission property "_EmissiveColor " from script have different results when we use material.SetColor and materialPropertyBlock.SetColor (set using the material property block of the renderer).
Note that because the animation system uses property blocks, it have the same issues which make it hard to animate the emission property on materials.
Repro with 2021.2.0a13, HDRP 12
Repro steps:
- Create a new scene with a cube in it
- Create a new Unlit material with HDRP/Unlit shader
- Assign this material to the cube.
- Download the attached script and add it to the cube
- Toggle on and off the use material property block field.
- Observe that the intensity on the cube changes even though the script sets the same emission value in both cases.
Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteAlways]
public class SetEmission : MonoBehaviour
{
[ColorUsage(false, true)]
public Color emissionColor;
public bool useMaterialPropertyBlock = false;
new MeshRenderer renderer;
void Start()
{
renderer = GetComponent<MeshRenderer>();
}
void Update()
{
if (useMaterialPropertyBlock)
{
var p = new MaterialPropertyBlock();
p.SetColor("_EmissiveColor", emissionColor);
renderer.SetPropertyBlock(p);
}
else
{
var p = new MaterialPropertyBlock();
renderer.SetPropertyBlock(p);
renderer.sharedMaterial.SetColor("_EmissiveColor", emissionColor);
}
}
}
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- A "Could not generate preview image" error is shown in the Console window when viewing a ".androidlib" asset
- Call stack hyperlinks become unclickable when scrolled down in the Console window
- Package files do not get checked out in Perforce when the project includes a provider callback
- VFX throw errors upon importing it
- "NullReferenceException" error is thrown when swapping between built-in and URP depending on assets loaded out of asset bundles
Resolution Note:
The color value is considered to be always set in sRGB space and is converted to linear if the active color space is linear. You need manual updating of the color value if you switch between color spaces.
so the code should be "p.SetColor("_EmissiveColor", emissionColor.gamma);" to be equivalent to "material.SetColor"