Assigning HDR color to material property via script

I’m trying to assign an HDR emission color (with components with values greater than 1.0) to a material at runtime via script, but I’m not sure how to do this. I’m using a Color, but all my values get clamped to the usual 0-1 range. I can set a >1 value using the material inspector, but I don’t seem to be able to accomplish the same effect via script at runtime. To be clear, I’m able to assign a color to the material, just not an HDR one with components outside the usual 0-1 range.

Any ideas?

[ColorUsage(true, true)]
public Color myColor;

This lets you pick hdr color in inspector

I too had this issue.

I found the easiest way is:

public Material laserMaterial;

private Color laserRed = new Vector4 (1.988f, 0.438f, 0.438f, 1.0f);

void Start() {

laserMaterial.SetColor("_TintColor", laserRed);

You can create as many Vector4 colors as you want and simply assign them using yourMaterial.SetColor(“_TintColor”, yourColor); anywhere in your script.

To get the HDR color picker in the Inspector use ColorUsageAttribute.

example:
[ColorUsageAttribute(true,true,0f,8f,0.125f,3f)]
public Color colour;

In case you want to HDR colors in MaterialPropertyBlocks, use Vector4 functions instead of Color functions:

[ColorUsage(true, true)]
public Color hdr_col;
private MaterialPropertyBlock _propBlock;

hdr_col = (Color)_propBlock.GetVector("activeColor");
_propBlock.SetVector("activeColor", (Vector4)hdr_col);

It looks like SetColor clamps the values between [0,1].