- Home /
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?
think of 2 transparent layers. One is infront of the other one. The layer which is behind shouldn't be affected by the layer which is in front. The texture which is behind should be seen as itself.
so you are wanting to have a transparent layer in front of a coloured object, but do not want the colour of the behind object to be affected?
Well that does not make any sense. What is the point of having a transparent layer if you don't want it to affect anything?
Are you referring to alpha blending problems where a transparent layer completely masks another object because alpha blended layers are not z-sorted?
No, I surely want my transparent layer to affect other layers. But - I do not want some of my layers to be effected from the transparent layer, but I also don't want those layers to be in front.
That's all.
Answer by Wolfram · Jan 18, 2012 at 03:35 PM
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.
Unfortunately renderQueue isn't a proper solution for me. There are more than two layers. What I want to do is for example; we have layers A, B, C. Let's say A is the transparent layer which is closest to the camera. B shouldn't be effected by Layer A. Layer B and layer C should be z-sorted. Finally, layer C should be effected by Layer B. I know it sounds complicated but I don't know another way to explain it