HDAdditionalLightData.SetIntensity(): Why is it deprecated, and why is the workaround so clunky?

I was converting some code, and found that HDAdditionalLightData.SetIntensity() is deprecated, even though the documentation explains its usage:
https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@17.0/manual/creating-and-editing-lights-at-runtime.html

The warning suggests that instead of using the very simple SetIntensity, I should instead use the fairly confusing ConvertIntensity() method, and assign that directly to the light’s intensity. So, a couple of things:

  1. The docs should be updated to not suggest using a deprecated approach.
  2. The new approach recommended by the depreciation warning is honestly a pain. I need to pass in a light, the new intensity, and what I’m converting from and to. Why make us do that, when SetIntensity could have just need made to do that?
  3. What value is a light actually expecting when I set its intensity? I have a light that’s set to use Lumen in the inspector. If I assign it an intensity value of 120 at runtime (which is what it has in the editor), it seems that Unity thinks I’m assigning a value of 120 nits instead. So, it seems like any time I assign an intensity value at runtime, I’m always assigning nits, and I need to always manually convert to nits any time I assign intensity?

Simple workaround:

using UnityEngine;
using UnityEngine.Rendering;

namespace ExtensionMethods
{
    public static class LightExtensions
    {
        public static void SetIntensity(this Light light, float intensity, LightUnit unit)
        {
            light.intensity = LightUnitUtils.ConvertIntensity(light, intensity, unit, LightUnitUtils.GetNativeLightUnit(light.type));
            light.lightUnit = unit;
        }
    }
}
1 Like

Well this is slowly getting less dumb. Thanks for sharing.