Object not effected by transparent object in front

Hi,

I am trying to put a game object behind a transparent layer but I dont’t want it to be effected by the alpha channel of the transparent layer. Using a second camera isn’t a solution for my problem. Is there a way to do it with shaders or some other way?

If the object in the back uses non-transparent shaders, increase its render queue by 1001 (by modifying the shader code, or by adding a script containing this line: )

renderer.material.shader.renderQueue += 1001;

If the object in the back uses a transparent shader, you can achieve the same effect by just increasing the renderQueue be 1, but the look will only be the same if your back object’s alpha is 1. For smaller alphas (i.e., if the object is actually (semi-)transparent, instead of merely using a transparent shader), the solution is not so simple I guess. You might be able to modify the shader to use a different blend function.

The renderQueue approach works because transparent shaders do not write to the zBuffer. So if you make sure your object renders after your transparent front object, it will overwrite its frame buffer values. Opaque geometry is rendered with a render queue value 1000 lower than transparent geometry, so you need to add at least 1001 to make it render later.