PDA

View Full Version : Object Behind The Blending Transparency Clipped



DavidJr
01-05-2016, 10:40 PM
Hello, try to play with blending alpha function in GLSL. I got the window glass transparent.

If I render the object ordered by:
1. Building, car, window, skybox, I can look through the window and the building and the car, while the skybox clipped.
2. Window, building, car, skybox, the building, car, and sky are clipped.
3. Skybox, building, car, window, I can look through the window correctly, no models are clipped.

Picture companion:
1. 2217
2. http://s25.postimg.org/fhe9pjpy7/Incorrect_2.jpg
3. http://s25.postimg.org/xhngtxi5b/Correct.jpg

Thank you.

GClements
01-06-2016, 07:56 AM
By "clipped", I presume that you mean "discarded by depth testing".

If you render the window with depth writes enabled, then it will update the depth buffer, and any farther objects will fail the depth test.

If you render the window with depth writes disabled, then it won't update the depth buffer, and any objects drawn after the window will overwrite it, regardless of whether they're nearer or farther than the window.

In order for translucency to work correctly, it's necessary to render the translucent surface after any opaque surfaces.

If you have multiple translucent surfaces, they have to be rendered in the correct order; if surface A is in front of surface B, A must be rendered after B. This can be done using a topological sort (https://en.wikipedia.org/wiki/Topological_sorting), or a BSP tree (https://en.wikipedia.org/wiki/Binary_space_partitioning). For complex geometry, it's typical to perform the sorting on a per-pixel basis using depth peeling (http://www.eng.utah.edu/~cs5610/handouts/order_independent_transparency.pdf) or by storing a linked-list of fragments for each pixel.

DavidJr
01-09-2016, 09:38 PM
Thanks for the clear explanation, GClements :)