Project Graveyard – Devlog 007
Scaling dynamic lights based on the size of a volume.
The new lamps in Project Graveyard each use a dynamic light from RealityKit. When I tired these on device, I ran into an issue right away. Users can resize the volume at anytime. I have some code in place to scale the root entity of the volume, but the lights didn’t “scale” with it. See this How to scale RealityView content when a Volume is resized for more info.
The issue is that the dynamic light settings don’t scale with the rest of the scenes. As we change the distance between the light source and the ground, the intensity of the spotlight needs to be adjusted. The attenuation radius is always in meters in world space, not units in the current scene space. Take at look at these two images. The light appears brighter when the volume is small and dimmer when large.


We can solve this by scaling the intensity and the attenuation radius. As a quick hack to test this, we can use Entity Observation to watch for changes to the scale. This gives us a number we can use to scale the light settings. We need to scale the intensity by scaler². This keeps the apparent brightness (power) consistent as the distance it has to travel changes. We can also adjust the attenuation radius so the light has the same relative reach.
let scaler = volumeRootEntity.observable.transform.scale.x
light.intensity = 1500 * scaler * scaler // boost by scaler ² so brightness stays consistent with distance scaling
light.attenuationRadius = 6 * scaler // scale reach by scaler so the light covers the same relative area

Now our scene is lit but the same power and reach regardless of scale.
As you can see in the video demo, this works by the way I’m accessing scale and updating the values could use some work. There is a bit of stutter as we resize the volume. I’m going to try to turn this into a new component and system with some debouncing logic so we don’t adjust the light every frame/update.

Follow Step Into Vision