Your online Softimage Educational Resource

The blog has been online for more than 4 years and there’s still not a single post even remotely related to the delicious brew called coffee… Perhaps it will someday, but in the meantime you can read the articles about Softimage. Most of the material are tutorials and Q&As I’ve written for 3D World Magazine sometime between today and 2003. If you have any questions please don’t hesitate sending me an email.

Thanks to Letterbox Animation Studios for hosting all the scene files.

Make sure you visit their for 100s of hours of free XSI video tutorials.

Tuesday, January 25, 2011

Changing color of an objects based on its distance to another object

You can use the scalar to vector node to extract the position of an object and make it available in the Render Tree
There are many instances where you want to be able to control an attribute of a shader based on its distance to the camera or another object in the scene. Regardless of the end effect you’re trying to achieve, the procedure of getting there is about the same.

Select any of the spheres (they all share the same material) and press [7] to open a Render Tree. From the Nodes > Conversions menu, get a Scalar to Vector node. This node enables you to enter any XYZ coordinates and by linking their separate values to the corresponding value of the Ctrl_Null, you’ve efficiently extracted the nulls position and made it available in the render tree. Open its PPG and click the Lock icon to pin it to the screen. Select the Ctrl_Null and press [Ctrl] + [K] to open its transform PPG. Drag the animation icon (the green divot) for the X Position (in the transform PPG) and drop it onto the animation icon of the Input X in the Scalar to Vector PPG. Repeat for the Y and Z position.

Rather than extracting the position of the object holding the material, which you can’t do anyway in this scenario since there are multiple objects, you’ll use its intersection point. By comparing the intersection point with the position of the Ctrl_Null you can extract the distance between them. From the Nodes > State menu get a Vector state. Open its PPG and change the State Parameter to Intersection point. From the Nodes > Math menu get a Vector-Scalar node. Open its PPG and change the operation to Distance between V1 and V2. Connect the Scalar to Vector node to the vector_input1 of the Vector_math_scalar node and the Vector state to the vector_input2. Depending on the scale of your scene the distance value can be extremely small or large so you’ll have to change its range to something more useful. From the Nodes > Mixers menu get a Gradient node and a Mix 2 Colors node. Connect the Vector_math_scalar node to the input of the Gradient node and the Gradient node to the Weight input of the Mix_2colors node. Connect the Mix_2colors node to the ambient and diffuse input of the Blinn node.

Open the Gradient PPG and switch to the Input tab. In the Active Range section, change the Maximum to 20. Switch back to the RGBA Gradient tab and click the Black/White preset. The minimum and Maximum values in the Active Range controls at which distance the Ctrl_Null start effecting the material and the gradient controls the falloff of the effect. So for a sharper falloff, simply move the markers closer together.

The project files used in this tutorial can be found at:

You can then compare the position of the object with the intersection point on surface to extract the distance between them.

Quick tip
To further enhance the effects falloff you can add a third marker in the middle of the gradient and connect a greyscale texture, such as a fractal, to it. This way you can breakup the regularity of the transition from black to white.

Read the full post>>