Prevent Objects from Appearing Behind a Glass Shader


(webdunce) #1

I want to create a transparent material (glass shader) that doesn’t allow objects behind it to appear. I know that sounds weird, but it’s important for what I want to do (rendering gems set in metal, it doesn’t look right if you can see the metal thru the gems).

So far, I have only been able to accomplish this by setting the materials of all of the objects behind the glass/gem objects to “transparent” if the transmission ray bounces are greater than zero. But I would like to make it a property of the glass/gem object, because, what If I want to render say a pane of glass in front of the metal? With my set up, the object (a ring, usually) will disappear behind the glass. So, I only want CERTAIN glass/gem objects to not allow objects behind them to be seen. (I can get by with my current set up, but it would be better if I could solve this issue). Also, you can see how the gems dull out if you can see the objects behind them.

Any way to do what I’m wanting to do (make the gems themselves block out materials behind them)?

The render below is using simple glass shaders for the diamonds and glass panes. The gold setting on the left is using a simple glossy shader. The gold setting on the right (the one that disappears behind the pane of glass), is a glossy shader mixed with a transparent shader that kicks in if there are any transmission ray bounces (the node set up is below).

(omgold) #2

I don’t think it can be done reliably via material nodes. It just doesn’t fit with the concept of global lighting.

For tricks like these the compositor is around. Although it is also not completely obvious how to do it there. Object Index likely won’t help when a glass pane is in front. You would have to use tricks like putting an emission shader on the gem (for a separate render pass), to determine where the gem is seen, and/or doing a separate pass for the reflection of the glass pane, and such.