View Full Version : Vary gradient color by distance

eheupel

08-16-2011, 07: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.

Help?

Lightwolf

08-16-2011, 08: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.

Cheers,

Mike

eheupel

08-16-2011, 09: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:

http://heupel.com/NodeTree.png

Gradient:

http://heupel.com/Gradient.png

Thanks again!

Medi8or

08-17-2011, 09:19 AM

Try Input instead of Bg Color, in Gradient node?

Joearchi

09-28-2011, 11: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...

Joearchi

09-28-2011, 01: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.

Powered by vBulletin® Version 4.2.3 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.