# How to change HDR color's intensity via shader

HSV, ie: Hue, Saturation, Value, is also known as HSB, or Hue, Saturation, Brightness. The brightness or value is in effect the absolute intensity, lower that at the same time you’re reducing the saturation and you’ll make it darker. Alternatively, like in @Johannski 's example, just multiply that emission color by some value to increase or decrease the intensity.

As for what the intensity value is in the HDR color picker actually is, that’s a bit more complicated. Internally it’s treated as an exposure value which they calculate as:

Color * 2f ^ Exposure

So if you have a color value of [1.0, 1.0, 1.0], then an intensity of -1 produces [0.5, 0.5, 0.5]. -2 produces [0.25, 0.25, 0.25], and on the flip an intensity of 1 is the equivalent of [2.0, 2.0, 2.0]. One thing to be mindful of though is that all of these values are being calculated in sRGB color space, referred to by Unity as “gamma” space. If you’re using linear color space for your project, the value you get in the shader has already been transformed. If you want to perfectly match the effect of an intensity of “-2” in the color picker, you need to convert your color values to sRGB space, multiply by 2^-2 (or 0.25), and convert back to linear space. Luckily there are handy functions included with Unity for this:

// if not using gamma color space, convert from linear to gamma
#ifndef UNITY_COLORSPACE_GAMMA
emissiveColor.rgb = LinearToGammaSpace(emissiveColor.rgb);
#endif
// apply intensity exposure
emissiveColor.rgb *= pow(2.0, _foggedIntensity);
// if not using gamma color space, convert back to linear
#ifndef UNITY_COLORSPACE_GAMMA
emissiveColor.rgb = GammaToLinearSpace(emissiveColor.rgb);
#endif

Or, you could simplify this with a cheap approximation:

half intensityMul = pow(2.0, _foggedIntensity);
#ifndef UNITY_COLORSPACE_GAMMA
intensityMul = pow(intensityMul, 2.2);
#endif
emissiveColor.rgb *= intensityMul;

This isn’t perfect, especially for highly saturated non-primary colors, but since you’re already desaturating the colors to nearly white it’s kind of moot, as long as you do this after you apply the desaturation. You could also apply the intensity multiplier to the V before converting from HSV to RGB.

If you want to know more about what the HDR color picker is doing, the source code for it is here:
https://github.com/Unity-Technologies/UnityCsReference/blob/11bcfd801fccd2a52b09bb6fd636c1ddcc9f1705/Editor/Mono/GUI/ColorMutator.cs

11 Likes