View Full Version : distance to object gradient
pooby 11-24-2006, 01:38 PM Hi . I wonder if anyone knows how to drive a gradient based on the distance to an object?
an example to explain what I mean--
I have a null and I want the surface to be red where the null is, but with a falloff radius around the null so that 1 unit away the red fades to nothing. So by animating the null, the red 'moves' over the surface.
In LW this is called a 'distance to object gradient'
Is it possible in XSI? I've gone through every forum and book and DVD and asked around but can't find it
|
|
Mathaeus
11-24-2006, 04:22 PM
Try this in rendertree: Get a vector share node, with global position of your null (you can link positions by drag-n-dropping). Then Vector state, set this one to 'intersection point'. Put both into vector-scalar node , with 'distance between V1 and V2'. Then vector-scalar into the change range, set 'old range end' to a maximum distance of effect. Set new range start to zero, end to 1. Put change range into the input of gradient mixer, and drive whatever you want with gradient mixer.
pooby
11-24-2006, 05:31 PM
That works a treat.. thanks a lot.
Now I'll just have to try and work out why it works. I'm new to the render tree.
tachy0n
11-24-2006, 10:12 PM
When mentalray renders anything, it always maintains a list of its internal variables as it uses various shaders in the scene. This list has all kinds of useful info like normal of the poly being rendered, motion vectors, current screen positon, ray lengths and so on. In the rendertree, you can access the info of this list using the Vector and scalar state nodes.
Now in that list, the 'intersection point' is that point on a surface which mr is currently trying to render. The vector state node returns this point in the form of a location in your scene (a vector position.) You take this position, find its distance from your null with a math node and scale it down to a (0,1) range with the change range, since the gradient expects values between 0 and 1. Then you use that to color something.
Or in other words, for every point on the mesh you're shading, the point gets a color from the grad, based on how far it is from the null.
pooby
11-25-2006, 08:43 AM
That makes complete sense - I really appreciate you taking the time to explain it. Thanks
CGTalk Moderation
11-25-2006, 08:43 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.