2
$\begingroup$

I would like to be able to render a model/scene using the standard renderer (not game mode) where the color of each face/polygon is determined by its world-space normal. For example, looking at a cube from an angle where I can see the +x/+y/+z faces should render the faces with colours (255, 127, 127) / (127, 255, 127) / (127, 127, 255) respectively.

Importantly, moving the camera slightly should not change these colours (not screen-space normal based) and rotating the cube should change the colours (not object-space normals).

I've managed to create the effect by following this guide and writing my own fragment shader, but can't figure out how to use it during a standard render. Likewise I have found the normal output mode for material nodes but this only gives screen-space information.

I'm not too picky about the method as long as it can be used to generate animations and be reasonably automated.

$\endgroup$
9
$\begingroup$

You can do this in cycles using the Vector Transform node:

enter image description here

No matter how the object is rotated, the faces facing a particular direction are always the same color.

To map colors to the normals, you can use Separate and Combine RGB nodes to manipulate each channel individually:

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Perfect - I had no idea cycles had so many more options. I wasn't able to use ColorRamp as it doesn't handle negatives, instead I used VectorMath->add (1,1,1) followed by VectorMap->scale(0.5). Full setup i.imgur.com/PYfkbZS.png $\endgroup$ – Guy Cook Feb 14 '14 at 9:32
  • $\begingroup$ For anyone wondering, normals in Blender Internal are in camera space, so you need to convert from camera to world to achieve the same effect. $\endgroup$ – Pisurquatre Dec 23 '16 at 12:05
3
$\begingroup$

One way to solve this is to place different colored lights far away from the center of your scene, one at each axis. Depending on whether you want other objects in the scene, this could be a very quick and simple solution.

Another solution is to make a material with as many colors as you want. Each color should be mixed in with this as a factor:

dot product(world normal of mesh, vector where you want this color).

$\endgroup$
  • $\begingroup$ The 3 suns solution is ingenious haha. $\endgroup$ – Mike Pan Feb 13 '14 at 23:43
  • 1
    $\begingroup$ +1'd for an interesting light solution - I think gandalf's is more correct though $\endgroup$ – Guy Cook Feb 14 '14 at 9:25
  • $\begingroup$ This solution is very useful for volumetric rendering and relighting. $\endgroup$ – Pisurquatre Dec 23 '16 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.