Related: How to get length of specific ray type and use that as color?

So the idea is to use the Light Path node's Ray Length to form the basis for ambient occlusion but the Camera position relative to the object is a part of the Ray Length info and this makes such a calculation difficult since this alter the results based on how far a specific position is to the camera.

Here is a demonstration of what I meanenter image description here.

Here's a node setup that shows this effect.

enter image description here

For AO to work, this effect has to be cancelled out since the dirt and grime which tends to accumulate in crevices will not be affected by how far the viewer is from the object.

So my question is this. Does anyone have some ideas on how to remove the camera influence from the Ray Length result?

  • $\begingroup$ is camera ray is going to be your solution, if there is one. $\endgroup$ Jul 30, 2014 at 5:08

1 Answer 1


If you think about it, it's pretty easy; The way Booleans (true or false, not the modifier) are represented inside Blender by either 1 or 0; So if you do "1 - is Camera Ray", you will get ,basically, is NOT Camera Ray; if you multiply the Ray Length with is Not Camera Ray you will get the length for all rays except for the Camera ones. You could choose another Ray, and multiply it with Ray Length, to basicly get the length of that Ray.

Also note there's a Ambient Occlusion node.

Node Setup

After the part inside the box, you can use the rest of your material.

  • $\begingroup$ The only problem for my case is that it seems impossible to use the length of the non camera rays to determine the appearance of the object itself.. $\endgroup$
    – gandalf3
    Jul 30, 2014 at 10:25
  • $\begingroup$ @gandalf3 indeed $\endgroup$ Jul 30, 2014 at 11:00
  • $\begingroup$ gandalf3: maybe the TriGAO OSL script will suit your needs. It can detect nearby geometry for self-shading, it does not work well for baking but it does seem useful for camera renders. pressf9.free.fr/compounds/TriGAO.osl $\endgroup$ Jul 30, 2014 at 12:26
  • $\begingroup$ If this is indeed the approach, can someone show an example of an AO render using this method? $\endgroup$
    – Greg Zaal
    Jul 30, 2014 at 14:06

You must log in to answer this question.

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