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.
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
You can use the Backfacing output of the Geometry node.
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:
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:
This uses only the fresnel shader on front faces for other ray types and ignores backfaces.