Mapping Lights

July 13th, 2006 by Stefano Jannuzzo - Viewed 15244 times -

The State nodes in the rendertree can easily be used to enhance the standard light shaders. Some of the state information, normally used at a material/texturing stage, have their own meaning when triggered by a light ray.

For instance, let’s see how it is possible to texture a spot light’s color based on the angular distance from the spot direction. We just need a few vector math, based on the spot direction and on the point being lit.

First, we need to bring the light’s position and interest into the rendertee. The interest (Spot_Interest) is a Vector_share node whose x,y,z are linked, via an expression, to the spot interest. The position (State_Origin) is a Vector_state node set to Origin. This stands for the origin of the current ray, the light ray in our case. We could have used expressions to do this but using shaders is faster.

Once the two vectors are subtracted the result is a vector that, once normalized, is the direction from the spot to the interest.

Then, we need the direction of the current light ray. This is provided by another Vector_state node, set to Eye Ray. This nomenclature is incorrect because what the node returns in Eye Ray is in fact the current ray direction, not the eye direction.

If we dot product the two nodes (Vector_math_scalar, set to Dot…), we have an output ranging [0..1]. In particular,

dot == 0 if the two vectors are perpendicular
dot == 1 if the two vectors are parallel

We just have to use this value to drive a gradient node which then plugs into the light color.

Light Render Tree

Similar techniques can be used to drive the distance falloff (based on the ray length value) as well as other lights attributes.

Have fun!

8 Responses to “Mapping Lights”

  1. Steven Caron says:

    thanks for all the techniques you have been sharing this month!

  2. Kris says:

    Awesome, thanks!

  3. Keith says:

    Stefano, can you help with the positional expression you”ve entered on the first save state. Only one input node for all three axis… not able to get it to understand the interest”s seperate xyz… thanks!

  4. I know, you have to do it from the Explorer. Expand the spot node until it shows the vector input, there you have the 3 components editable.
    Actually, what I like better in these cases is connecting the node I need to put expression on straight to the root node (in this case the light color, so Xsi will add a vector 2 color converter), so the explorer is easier to climb up. When I”ve set the expression, I restore the initial network. Fortunately, the expressions are kept also if a node is temporarly unconnected.
    However, I would really like a “Track Selection From RenderTree” option in the explorer.

  5. Keith says:

    Thanks Stefano. That works really well. Incase anyone else it doing this, you should apply the expressions as global positions, incase you need to move the spot root null. Also I could only get this to work with the setting of “Distance between V1 and V2″ on the last Vector_math_scalar not the “Dot Product” but works really well. Moving the gradient”s MINimum Active Range will spread out the center. Also I recommend adding an expression to the gradient”s MAXimum Active Range like this: Spot.light.LightCone / 120. So when you move the light”s cone angle, the colors stay relative to the falloff. Thanks for your help Stefano.

  6. Hassana Toukour says:

    Best success in your projects ! I will work with this exciting software too very soon ! I have tons of ideas that must become real. Well, sky is the limit, huh ? ;)

  7. Guillaume Chabot says:

    or… plug `mixer gradient` in the color of the spot light and plug a `texture Space generator` in the`Coord of gradient.In texture space generator, in project method: UV.. and for Space Transformation: Light… And for the gradient in input option.. Input type: vector. Now play with Active range Min/Max.