View Full Version : Vary gradient color by distance

08-16-2011, 06:22 PM
I need to color a surface with a specific gradient (Green to Yellow to red) based on the distance from the origin of the object (i.e 0,0,0) along each axis according to the formula

color= (+Z) * ((+X) / (+Y))

where when color is less than 2 the color is green, from 2 to three it's in the yellow range above 3 gets redder and redder.


08-16-2011, 07:05 PM
Build a node tree with the expression (using vector nodes to get the components and put them back together, scalar nodes for the maths) and then pipe that as the input into a gradient node.
You can use the spot info node to get the current position.

I can build something for you tomorrow if you haven't sussed it out by then.


08-16-2011, 08:54 PM
Thanks for your reply. That's got me most of the way.
Unfortunately I'm still a hair off (it's varying by one axis, but not the others)
Not sure where the issue is.
Node Tree:


Thanks again!

08-17-2011, 08:19 AM
Try Input instead of Bg Color, in Gradient node?

09-28-2011, 10:03 AM
Try that.

B value of Vector multiply are 1,0,0 for x, 0,1,0 for y; 0,0,1 for z. I think it's easier to understand, and you avoid many vector to scalar, which can be surely tricky.

However, I'm very surprised about that formula, since y value won't react like x and z values...

Edit: I've made a mistake with y and x value, so the multiply and divide part must be changed...

09-28-2011, 12:30 PM
I've updated my picture and made a rendering. The pivot point is on center of that cube. Is it what you expected?

Edit: Nodal gradient range must be changed, according to the values you want (color red=5, yellow=2 and so on) so the minimum range is 0-5.