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
- Articulation Body with 'Revolute' Joint Type has erratic behavior when Upper Limit is set to above 360
- WebGL Player fails to render Scene when Terrain with Detail Mesh is added and WebGPU Graphics API is used
- Inconsistent errors are logged when different types are passed into the Query "Q<>" method in UIToolkit and the ancestor VisualElement is null
- Crash on GetMaterialPropertyByIndex when opening a specific Scene
- Discrepancies in the styling are present when using a TSS file instead of a USS file in custom EditorWindow
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"