Using a shader, I need to determine if any given polygon is facing North/South or East/West.

enter image description here Something like this, when viewed from above.

I thought I could use Dot Product against a vector of (0,1,0) to determine North and South, and then invert for East and West, but that got me this result: enter image description here

This technique will work quite nicely for top and bottom caps: enter image description here

but how could I obtain a diagonally segmented division of the sphere as opposed to the horizontal slice I have now?


1 Answer 1


Let's do one quadrant first; the other three will be simple after that:

enter image description here

Presumably we want the object-space normal, which I'm getting via a texture coordinate node. Because we don't care about one of our axes, we'll discard the Z component of the normal and then renormalize it. Then, we'll compare it to a cardinal direction-- 1,0,0, what we might consider "East"-- and if the dot product is greater than the cosine of pi/4-- plus or minus 45 degrees, the square root of 2 divided by 2-- then we'll mix in a color for that direction.

After that, we can repeat our dot product with different vectors to fill out the rest of it:

enter image description here

This can certainly be optimized to fewer nodes and probably faster performance (depending on how smart Blender is at optimizing automatically) but I feel that these nodes best demonstrate exactly what we're doing, with the least ambiguity. We could skip one quadrant since it's determined by the other three, and we don't really need to check dot products with both positive and negative versions of the same vector, and of course our cosine node is just a constant we could supply with a value node.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .