January 2011

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

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.

Read more →