Home / Xpresso / Xpresso Anonymous / Lights


Controling lights with Xpresso

Using Xpresso to tweak your lighting can be a great helper especialy if you have a great number of lights that need to be controlled.
The goal of this setup to create a corridor that is lit by a number of lights that are controlled depending on their distance to an object moving along the corridor. Think of a room that will automaticaly switch on the lights for the parts your are walking in. Simply switching the lights on and off might be a bit unnerving and also we don't want the corridor completely dark at any time.
As usual there are several ways to solve this, we will show two of them.
The first is to create a Xpresso setup for every light that controls the lights brightness depending on the distance to the object.
The second one is to create a single setup that will controll all the lights.
Basicaly both work in the same way, the main differenc is in how you adress the lights. The first setup can be made portable so you can easily reuse it, while the second one is easier to adjust since you only have to modify one setup.
We start by creating a setup after the first method, later on we will modify it to the second.

basic scene

Create a Xpresoo expression tag on the first light and drag the light itself and the Sphere object into the Xpresso editor. We will need the global position of both to determine their distance. The distance can be calculated either by subtracting both positions and converting the resulting vector to a real value (Info) or by using the distance node. In our example we will use the distance node.
Your setup should look like this:
Now we have to map the distance to the lights brightness. To get an idea of the range of values we are talking about create a Result node and connect it to the distance nodes output port. Switch on Animation Refesh in the Xpresso->Calculate menu to get a live update of the result value.
Moving the sphere along it's z-axis you can test the setup. If you don't change the X and Y positon of the sphere the smallest distance should be somewhere just below 140 units, so this is our minimum distance which shall result in maximum brightness. Now move the sphere away along the z-axis until you reach the next light. The distance should be somewhere around 330 units which will be the distance where the light will have it's lowest brightness.
Since we don't want the light to become totaly dark we will use a range of brightness between 20% and 100% (0.2 - 1.0). To convert the range (Info) of 330/140 to 20%/100% you can use a number of math nodes or the range mapper node. We will use the range mapper since it was created for exactly this purpose. Replace the Result node by the Range Mapper. We will need a second light object node to control the brightness. Just drag it from the object Manager and place it to the right of the Range Mapper. You can create the connection by starting a wire from the Range Mapper output port and dragging it on the blue rectangle in the top left corner of the light node.
Set the output range of the Range Mapper to Percent and enable Clamp Lower(Info) as well as Clamp Upper. Since our ranges are inverted (High value will be mapped to low value) enable the Reverse option. We will not use the Spline option in this example so deactivate it. Enter the ranges in the parameter fields.
Now we have one light working as intended (scene). Please create an animation that moves the sphere from one end of the corridor to the other so we can test our setup (animation).
To copy this setup to the other lights we will have to make some changes first. What we need is to change the reference of the lights object node. Currently it's set to light1 and copying the Xpresso tag to other lights won't change this. The solution here is to use the Relative reference. Select both light nodes and change the reference type from absolute to relative.
From now on these object nodes will referenc to the object that has the Xpresso tag, regardless the type of object. If you copy the tag to an object that does not have the ports you are using they will be set to undefined. I.e. there is no Brightness value on a cube object.
Now we can safely create copies of the Xpresso tag for all the other lights by using Ctrl+drag on the tags. (scene) (animation)

The setup we created has some drawbacks. If you want to change the distance or brightness range you will have to do this seperately for every Xpresso tag or you have to replace the tags by a changed one. A first step to make this easier is to allow access to the needed values from outside Xpresso by one of the methods shown here. This will enable you to multi select the lights (when using User Data) or the tags (XGroup Ports) and change all values simultanously. However you are still stuck with one Xpresso tag for every light. (scene)
To avoid this we will use an iterator to repeat the same operation on every light. In this case two iterators are usable. The Hierarchy and the Object List iterator. Hierarchy enables you to iterate to all children of our Null called lights, which might pose a problem if you use a more complex hierarchy for your lighting setup. In this case the better choice is the Object List iterator which will iterate through all objects you put in the list.
Delete all Xpresso tags except for the one on Light1, then create an object List iterator node. Since we will use the setup on the Null please set the reference of the Light object nodes to absolute, otherwise they will change to the Null which doe snot have a brightness value. Now move the tag from Light1 to the Null named Lights.

Now we connect the Instance output port of the Object List iterator to the object input ports of the two light object nodes. This way the reference will be changed to all objects in the object list in succsession. To make the setup easier to use let's make all the values that might need tweaking available as properties of the Xpresso tag. (Info). Also you can change the order of ports by dragging the port name. This makes it easier to keep our setup clean. (scene)

You can easily modify this setup so that instead of lights going brighter there are doors opening and closing automaticaly. Just animate the doors rotation instead of a lights brightness.

Keep in mind that there is always more then one solution to a problem.
Try to find more then one solution for a problem. This will help you when the going gets tough and you have to produce something in limited time or within restrictions.

Back to Xpresso Anonymous