Custom Trasnparent Glass

Hello everybody,

I’m totally sure that this thread should be here. I would like to create a “transparent” glass using a plane or box. I would like the block to show the virtual world without deformation. However, some gameobject (that I select) will have to be seen deformated (distorted as a translucent glass) or filter color (as a colored glass) when they are behind of the glass.

First, I thought that I need to investigate about shaders… However, I think that it is not valid because it is only for the own glass object… I couldn’t select some gameobjects that they were seen diffent when they are behind of the glass. Second, I think to detect if the gameobject is behind to the glass to change the gameobject’s shape and color… However, it gameobject is parcially occluded by the glass I wouldn’t get a proper effect.

Thank you,

You could try the stencil buffer for that. First render all the normal objects. Then render your special “transparent” object and also write to the stencil buffer. Lastly render your special game object in two passes. One pass, where the stencil test passes and one pass where the stencil test fails. In each pass you can color/deform/etc… the object however you like.

Stencil buffers can be a bit confusing at first, but they are quite a versatile tool: Unity - Manual: ShaderLab command: Stencil