-
-
Notifications
You must be signed in to change notification settings - Fork 56
Simplify blending #1002
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
Simplify blending #1002
Conversation
I was able to fit in the weighted blending (user sets `material.blending = "weighted"). Yes you can also mix e.g. dithered objects with weighted ones 🚀 |
I addressed the feedback so far. |
Somewhat related, I recently found that ThreeJS also supports dithered blending! It does so via |
@Korijn I would like to move this forward. I plan to do a few quick follow-ups on this PR because objects with mixed opaque/transparent fragments are prone to artifacts (they already were, but ordered2 avoided a subset of problems). In short, my plan is to add support for fxaa and turn off aa on lines/points by default. I have this working as a POC now and it looks great! So what I would like to do, step by step:
Once that is done we have the same quality (in terms of jaggyness), with much better support for different kinds of blending, and less artifacts. 🚀 |
Alt to #989. See #1065
Intro
This drops our system of per-renderer blend modes, instead using per-object blending. We managed to keep the "weighted" and "dithered" blending modes. The multi-pass "ordered2" and "weighted_plus" are gone. We include examples that demonstrate how these can be mimicked.
The new system:
depth_write
and other props.But also:
Context
You may ask why we have different blend modes in the first place. The short answer is that blending semi-transparent objects is really hard and there is not a single solution that does the trick. And then there are some more special types of blending, like additive.
In the previous system we kind of tried to offer a few blend modes that did their best to "fix" blending for the user. The new system accepts that transparency is non-trivial, relies on the user to think about the problem, and it provides the user with more tools to approach the problem.
Ordered2 blending
The previous default blending was "ordered2", which had the great feature that distinguishing between opaque and transparent fragments happens per-fragment instead of per object. It did this by rendering most objects twice,
discarding transparent fragments in the first pass, and opaque fragments in the second. This solves a range of problems, (but not everything).
The costs are quite high:
discard
, which prevents the GPU from doing early-z optimizations.See #1003 for more details.
API changes
WorldObject.render_mask
.Renderer.blend_mode
, useMaterial.blending
instead.Material.blending
.Material.transparent
, default is None (auto).Material.depth_write
, default is None (auto).Material.alpha_test
.Material.alpha_compare
, default is "<".material.color_is_transparent
forLine
,Mesh
,Points
,Text
. Usematerial.color.a < 1
instead.material.edge_color_is_transparent
forPoints
. Usematerial.edge_color.a < 1
instead.material.outline_color_is_transparent
forText
. Usematerial.outline_color.a < 1
instead.Other changes
renderer.sort_objects
is True by default.render_order
of -1e6, so they are usually drawn first.