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
- Fixing Message Loss in UMPE During Domain Reload
- The Editor freezes when ScheduleReadOnly of IJobParallelForTransform with dependency is used
- Text is truncated in the Inspector when the display scale is set to 150%
- CancellationTokenSource(<timeout>) has incorrect cancellation status when used in WebGL Player
- VFX property value names are cut off when properties with 'Arc' are viewed in the VFX Blackboard
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"