Skip to content

Fix transparent objects rendering #2368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SzymonOzog
Copy link

Motivation

Currently transparent objects are not rendered correctly and are highly dependant on the ordering of how the objects were added, consider the following example:

        l = Line3D(LEFT, RIGHT ,width=0.5).scale(2)
        l2 = Line3D(UP, DOWN, width=0.5, opacity=0.3).scale(2).move_to(l).shift(OUT)
        self.add(l2, l)

it renders like this:

image

If we switch the order in which we added the mobjects it starts rendering the opacity correctly

        l = Line3D(LEFT, RIGHT ,width=0.5).scale(2)
        l2 = Line3D(UP, DOWN, width=0.5, opacity=0.3).scale(2).move_to(l).shift(OUT)
        self.add(l, l2)
image

Proposed changes

We render fully opaqaue objects first and then transparent objects sorted by user specified z index as a primary key and then distance

Quoting from OpenGL FAQ

When using depth buffering in an application, you need to be careful about the order in which you render primitives. Fully opaque primitives need to be rendered first, followed by partially opaque primitives in back-to-front order. If you don't render primitives in this order, the primitives, which would otherwise be visible through a partially opaque primitive, might lose the depth test entirely.

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.

1 participant