Skip to content

Fix transparent surfaces occlusion (Issue #34)#38

Open
Paramveersingh-S wants to merge 5 commits into
CERN:mainfrom
Paramveersingh-S:fix/transparency-occlusion
Open

Fix transparent surfaces occlusion (Issue #34)#38
Paramveersingh-S wants to merge 5 commits into
CERN:mainfrom
Paramveersingh-S:fix/transparency-occlusion

Conversation

@Paramveersingh-S

Copy link
Copy Markdown
Contributor

This PR completely overhauls how order-independent transparency is handled in the rendering pipeline, specifically resolving Issue #34. Previously, a hack toggled the depth mask on a per-polygon basis inside the tessellator, which failed when opaque tracks were drawn before the transparent detector boundaries but failed the depth test.

To resolve this properly, this implements a Multi-Pass rendering strategy:

  1. Pass 1 (Opaque): Draws only opaque elements (alpha == 1.0) with depth writing ON. Transparent elements are skipped. (Opaque objects like the yellow tracks render normally and populate the depth buffer).
  2. Pass 2 (Transparent): Draws only transparent elements (alpha < 1.0) with depth writing OFF. Opaque elements are skipped. (Transparent elements like the blue/red detectors render over the yellow tracks without occluding each other).

Changes include:

  • wsb.c: Refactored phg_wsb_traverse_all_postings into a two-pass architecture.
  • wsgl.c & wsgl_attr.c: Added global wsgl_current_transparency_pass tracking and strict depth mask enforcement.
  • wsgl_tess.c, wsgl_line.c, wsgl_marker.c, wsgl_text.c: Implemented pass-checking skip logic dynamically based on GL_CURRENT_COLOR or vertex colors.

@schwicke could you please compile and test this patch on your end with the scene from Issue #34 to verify the occlusion is resolved properly?

@schwicke

schwicke commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks once again for the contribution! This one still needs some iterations. If you run test_c1 (see attached output) you see that now all surfaces are rendered black. Lines do not turn up at all it seems, e.g. test_f1 stays entirely
image

What is remarkable is that first the scene seems to be rendered but then things get erased. This might be a buffer visibility issue, it looks as if the rendering buffer is visible, and then its swapped against something empty (?). This would explain at least what I see for the hourglass test (test_f4).

@Paramveersingh-S

Copy link
Copy Markdown
Contributor Author

@schwicke Thank you for the test images.

The issue was exactly a buffer visibility problem caused by wsgl_begin_rendering and wsgl_end_rendering being called incorrectly inside the multipass loop. wsgl_begin_rendering forcefully clears both the color and depth buffers (via glClear), and wsgl_end_rendering swaps the buffers (via glXSwapBuffers).

Because my previous implementation wrapped each pass inside begin and end, what happened was:

  1. Pass 1 (Opaque) drew the opaque elements perfectly and immediately swapped the buffers.
  2. Pass 2 (Transparent) immediately started by clearing the buffer entirely (erasing Pass 1 completely) and then drew the transparent lines/polygons onto an empty black background, before swapping the buffer again.

I have pushed a new commit to this PR that fixes this by pulling wsgl_begin_rendering and wsgl_end_rendering outside of the multipass logic. To ensure the OpenGL state (matrix stack, colors, attributes) is still properly initialized for Pass 2 without clearing the buffers, I exposed the internal init_rendering_state function as wsgl_init_rendering_state in wsglP.h and called it between the passes.

This preserves the buffer between rendering passes while maintaining state consistency. Could you kindly compile this updated branch and re-run your test_c1 and test_f4 scenes?

@schwicke

schwicke commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Hi,
Thanks for the fix. This works better, however, it does not solve the issue yet:
image

@schwicke

schwicke commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Please, don't waste too much time with this one, it is not really important - just a nice to have.

Having said that, the latest patch comes with a new feature: somehow the clipping of the borders does not work as expected:
image
I have verified that this is specific to this patch set. The current main branch looks fine:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants