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
- Too little validation messages in the "WebAssembly Language Features" Memory settings
- Project Settings Search Highlights are misaligned when using the Bitmap Text Rendering Mode
- "GetControlID at event ValidateCommand returns a controlID different from the one in Layout event" Warning is thrown when undoing the deletion of Sprite Shape Profile
- Memory related fields in the "WebAssembly Language Features" can be set to the negative numbers
- "WebAssembly Language Features" Header in the Player Settings has a smaller indentation
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"