7
$\begingroup$

Is it possible in a Cycles material node setup to get when a light ray is exiting an object?

Use case: I'm using a Fresnel input to mix transparent and diffuse shaders. I want to see into the object, but never out its back.

enter image description here

$\endgroup$
7
$\begingroup$

You can use the Backfacing output of the Geometry node.

enter image description here

enter image description here

The way this works:

The outer material is mixed with a transparent shader based on how much the surface is facing the camera. This is then mixed with the Backfacing output of the geometry node. This output is 1 or 0 based on the normal of any face the ray encounters.
In this case, if goes ray hits the back of a face, it will bounce off of the "inner material" diffuse shader.

You might think we are done at this point, but the shader won't let light inside; rays which go inside the Suzanne from the camera can't get back out to hit light sources, as they are surrounded by diffuse back-faces.

To get around this, we use a final mix shader to make rays directly from the camera (camera rays) use the backface diffuse + fresnel frontface, however rays not directly from the camera will use transparent for the backfaces (allowing rays to exit the Suzanne after hitting a diffuse backface and becoming a diffuse ray). I plugged the inner material diffuse shader into the other slot just because I liked the indirect lighting it cast, but you can do other things too. Here are some examples:

No shadow

Without the mix shader, using just transparency, the Suzanne will not exist for any kind of ray besides camera ray, so this will remove the shadow and indirect lighting:

enter image description here

enter image description here

Fresnel shadow

This uses only the fresnel shader on front faces for other ray types and ignores backfaces.

enter image description here

enter image description here

$\endgroup$
  • $\begingroup$ @ajwood I completely rethought my answer (I hope it's what you want). This method will work in 2.70. $\endgroup$ – gandalf3 May 30 '14 at 20:41
  • 2
    $\begingroup$ Woohoo! I love it! $\endgroup$ – ajwood May 30 '14 at 21:31
  • $\begingroup$ @ajwood Here's the .blend too, if you want to play with it. $\endgroup$ – gandalf3 May 30 '14 at 21:32

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.