GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Refactor handling of alpha by almarklein · Pull Request #873 · fastplotlib/fastplotlib

Conversation

@almarklein

@almarklein almarklein commented Jul 8, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Context

Previously, Pygfx automatically distinguished between opaque and transparent fragments on a per-fragment level. With the new blending in Pygfx (current main), this distinction will have to be made per object. This means that somewhere a decision will have to be made whether an object is opaque or transparent.

The PyGfx material.alpha_mode is the easy way to control this behavior. The two values that make the most sense for Fastplotlib are:

  • 'auto': applies blending, and writes depth when material.opacity is 1.
  • 'blend': applies blending but does not write depth: relies on the correct render order.

This PR uses 'blend' for all WorldObjects. We can use material.render_queue to control the order of axes, grids, legends etc, with respect to other objects. This means that they do not write to the depth buffer.

Using 'auto' would also work, but self-intersecting objects like noisy lines or scattered points would be prone to show artifacts in semi-transparent regions (e.g. the aa edge).

If we add support for 3D objects (e.g. meshes) these should probably use `alpha_mode='auto' or 'opaque'.

Places where users can introduce transparency

(Let me know if I missed one!)

  • the graphic's alpha argument.
  • alpha in colormaps.
  • alpha in a uniform color
  • alpha in per-point colors.
  • alpha in image pixels.

Ideas (at the start of this PR)

Some ideas, some compatible, some mutually exclusive:

  • The alpha value passed to the graphic could be used to set world_object.material.opacity.
  • Also allow RGB colors, and maybe even promote that a bit over RGBA.
  • Automatically make a graphic transparent when alpha < 1. Easy to do either in fpl or pygfx. Covers quite some use-cases.
    • Somewhat intuitive: people who wonder why their transparent image is opaque may set alpha and see that it works then. Then they can set it to 0.999 to fix it.
  • For other cases (e.g. images or per-point colors), require setting alpha_mode.
    • A bit harder on users, but easy enough to document?
  • Or check the alpha values in images and colorlists, and automatically set the alpha_mode when values < 1 are present.
    • Makes it easier for users, but adds complexity and possible source of bugs.
  • Default to "dither", which always works. Then users can set alpha_mode="blend" for smoother results of transparent objects.

cc @Korijn because this is is a topic that touches both fpl and pygfx

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Korijn reacted with eyes emoji
All reactions
  • 👀 1 reaction
@almarklein
Refactor handling of alpha
fffc308
kushalkolar
kushalkolar reviewed Jul 8, 2025
View reviewed changes
Comment thread examples/gridplot/multigraphic_gridplot.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@kushalkolar

kushalkolar commented Jul 8, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Thanks! Will check this in detail later today, but I wanted to mention this: #754

We want to make alpha a separate graphic feature and thus an entirely independent Graphic property (in general we're trying to make the constructor as symmetric as possible with the settable properties, just like pygfx) . This would probably be a good time to do that?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@almarklein

almarklein commented Jul 8, 2025

Copy link
Copy Markdown
Collaborator Author

We want to make alpha a separate graphic feature and thus an entirely independent Graphic property

Good to know this was already on the agenda! Yeah I think it makes sense both from an API perspective, but also technically; changing a color is fine, but changing an alpha value might affect how you want to blend things.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@almarklein almarklein mentioned this pull request Jul 10, 2025
Improve dithered alpha_mode pygfx/pygfx#1139
Merged
6 tasks done
@Korijn

Korijn commented Jul 11, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Then they can set it to 0.999 to fix it.

This seems a bit awkward. I foresee users would complain about having to do this.

  • Or check the alpha values in images and colorlists, and automatically set the alpha_mode when values < 1 are present.

From your list of options, this seems most straight forward.

  • Default to "dither", which always works. Then users can set alpha_mode="blend" for smoother results of transparent objects.

After thinking about this for a while, I guess what I would expect from a 2D plotting library as a user:

  • All graphics have alpha_mode="blend"
  • Graphics are drawn in the order that I add them to the figure, transparent or not, so the depth buffer is kind of ignored I guess

I'm not sure if fastplotlib also does 3D plotting, but in that case I would expect it to behave as pygfx does naturally.

By the way, I appreciate you calling for my thoughts, so I'm sharing them here, but I really have not been keeping up with fastplotlib's development for a while, so take it with a grain of salt.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kushalkolar

kushalkolar commented Jul 12, 2025

Copy link
Copy Markdown
Member
  • Or check the alpha values in images and colorlists, and automatically set the alpha_mode when values < 1 are present.

From your list of options, this seems most straight forward.

I'm leaning towards this as well.

After thinking about this for a while, I guess what I would expect from a 2D plotting library as a user:

  • Graphics are drawn in the order that I add them to the figure, transparent or not, so the depth buffer is kind of ignored I guess

When using an orthographic projection graphics are stacked in z.

I'm not sure if fastplotlib also does 3D plotting, but in that case I would expect it to behave as pygfx does naturally.

Everything is 3D just like pygfx, perspective camera for everything. We just don't have a high level API for meshes yet, I've rarely used meshes myself so I hope someone else would be able to contributre a high level API for that. Or maybe meshes are so specific that the pygfx level of abstraction is the best for it, I don't know yet.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@almarklein

almarklein commented Jul 15, 2025

Copy link
Copy Markdown
Collaborator Author

When using an orthographic projection graphics are stacked in z.

Do you mean that the objects are offset in their ob.local.z?

Is it possible to clearly identify whether the current graphic is in a 2D or 3D scene? If that is the case we could indeed default to blend.

Or maybe meshes are so specific

Haha!. Some Pygfx users consider meshes the "normal object" and think all the non-meshes are special 😉

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Korijn

Korijn commented Jul 15, 2025

Copy link
Copy Markdown

When using an orthographic projection graphics are stacked in z.

And what determines the stacking order? Insertion order?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kushalkolar

kushalkolar commented Jul 15, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

When using an orthographic projection graphics are stacked in z.

Do you mean that the objects are offset in their ob.local.z?

Yup!

When using an orthographic projection graphics are stacked in z.

And what determines the stacking order? Insertion order?

Yup. Though the z can be set when added, or later at any time.

Is it possible to clearly identify whether the current graphic is in a 2D or 3D scene? If that is the case we could indeed default to blend.

If camera.fov == 0

You can switch between them and it's something I do all the time when looking at low dimensional projections with lines and scatters.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

almarklein added 7 commits September 1, 2025 16:23
@almarklein
x
5d142d2
@almarklein
Merge branch 'main' into alpha
e002038
@almarklein
preserve formatting of transform
2dafd6f
@almarklein
Tweaks
a76f6d3
@almarklein
Set aa on for text
0e6cddd
@almarklein
add alpha_mode arg
b700112
@almarklein
Use alpha_mode everywhere
0f86bcc
@almarklein almarklein mentioned this pull request Sep 2, 2025
Implement PolygonSelector #837
Merged
4 tasks done
@almarklein

almarklein commented Sep 2, 2025

Copy link
Copy Markdown
Collaborator Author

Tests pass again! (or am I missing something?)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@almarklein
fix axes
0a34819
@almarklein

almarklein commented Sep 2, 2025

Copy link
Copy Markdown
Collaborator Author

oh lol, all tests are skipped 😆

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@almarklein
almarklein marked this pull request as ready for review September 2, 2025 10:11
@almarklein
almarklein requested a review from clewis7 as a code owner September 2, 2025 10:11
@github-actions

github-actions Bot commented Sep 2, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

📚 Docs preview built and uploaded! https://www.fastplotlib.org/ver/alpha

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

almarklein added 2 commits September 2, 2025 12:50
@almarklein
alpha_mode for ruler
6aca6b1
@almarklein
Update tests for color
dc3995c
@Korijn

Korijn commented Sep 2, 2025

Copy link
Copy Markdown

How are you feeling about this refactor @almarklein, now that you can experience the revamped transparency system as a user?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@almarklein
Update env var
62f8271
@almarklein

almarklein commented Sep 3, 2025

Copy link
Copy Markdown
Collaborator Author

How are you feeling about this refactor @almarklein, now that you can experience the revamped transparency system as a user?

I'm feeling pretty good about it in general.

I felt rather disappointed that we cannot abstract the whole transparency thing away from the user. But after having done quite a bit of research on the topic I'm confident that even with the more advanced methods (which would consume more memory and/or be slower) it'd still not be fool proof. That's what it is.

So the only way to go is to shove the problem on the user 😄 , but as gentle as possible, and providing multiple different options to deal with it. I think we've now now done that pretty well, providing pretty powerful options, but also easy-to-use shorthands with alpha_mode.

As for this PR in Fastplotlib, I think it helps a lot if we can determine/assume the scene to be 2D, so we can just use 'blend'. If no object writes depth, Pygfx will not create the depth buffer, so it'd be a bit lighter too.

Korijn reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kushalkolar

kushalkolar commented Sep 3, 2025

Copy link
Copy Markdown
Member

if we can determine/assume the scene to be 2D, so we can just use 'blend'. If no object writes depth, Pygfx will not create the depth buffer, so it'd be a bit lighter too

3D is used often, easiest way to check is if camera.fov > 0

This will also need some refactoring of the graphic features, will add more thoughts soon

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

almarklein and others added 3 commits September 25, 2025 12:11
@almarklein @kushalkolar
Update examples/gridplot/multigraphic_gridplot.py
71a3239
Co-authored-by: Kushal Kolar <[email protected]>
@almarklein
Use an enum for render_queue values
b028165
@almarklein
use GraphicsFeature for alpha and alpha_mode
daef7d7
@almarklein

almarklein commented Sep 25, 2025

Copy link
Copy Markdown
Collaborator Author

I implemented a GraphicsFeature for alpha and alpha_mode. This indeed helps to make the code cleaner (less duplication).

However, setting the alpha / alpga_mode in figure[0, 0].add_scatter(.. , alpha=0.07) does not work. While it does work for visible which is also a graphics feature. Any idea why? I may have missed some init step or something.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

almarklein added 3 commits September 25, 2025 13:46
@almarklein
bump pygfx
6c980d0
@almarklein
fix syntax
5645009
@almarklein
fix init for alpha and alpha_mode
54b2249
@almarklein

almarklein commented Sep 25, 2025

Copy link
Copy Markdown
Collaborator Author

However, setting the alpha / alpga_mode in figure[0, 0].add_scatter(.. , alpha=0.07) does not work. While it does work for visible which is also a graphics feature. Any idea why? I may have missed some init step or something.

Fixed; these were set in _set_world_object()

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

almarklein added 3 commits September 25, 2025 14:24
@almarklein
allow material to be None
afcb62c
@almarklein
update examples
2519f36
@almarklein
new notebook screenshots
ec578b9
@almarklein

almarklein commented Sep 25, 2025

Copy link
Copy Markdown
Collaborator Author

Also updated screenshots. Two examples have a diff above the threshold: image_widget_single_video and image_widget_videos. I tried copying the screenshots from the screenshots CI build, but the screenshots are the same (git status is empty). Any ideas?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@almarklein
Remove last refs to wgpu.gui
4e63cf9
@kushalkolar

kushalkolar commented Sep 26, 2025

Copy link
Copy Markdown
Member

Also updated screenshots. Two examples have a diff above the threshold: image_widget_single_video and image_widget_videos. I tried copying the screenshots from the screenshots CI build, but the screenshots are the same (git status is empty). Any ideas?

ImageWidget screenshots aren't being generated, that regeneration action is failing: https://github.com/fastplotlib/fastplotlib/actions/runs/18008358652/job/51234040316?pr=873

Must be because newer wgpu uses newer imgui, so I'm going to try and put the fastplotlib imgui option to just point to "wgpu[imgui]", will see if that works.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kushalkolar added 4 commits September 26, 2025 02:44
@kushalkolar
imgui optional dependency just points to wgpu[imgui]
63ee693
@kushalkolar
update imgui things to v1.92
f1746be
@kushalkolar
update Frame, resize handle not visible if subpot isnt resizeable, up…
a23b6dc
…date IMGUI_TOOLBAR_HEIGHT
@kushalkolar
black
f7634bd
@kushalkolar

kushalkolar commented Sep 26, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

updated to latest imgui, uses the new texture registering method, uses a merged font so regular text and font awesome icons can be used together without push/pop font. @almarklein I think one last thing is to set the render order so that axes lines and points are on top when camera.fov == 0, but not on top of any overlays:

This is examples/gridplot/gridplot.py

image

If it doesn't cause a performance hit you could put a check for camera.fov in Axes.update:

        if self._plot_area.camera.fov == 0:
            # set render order for ruler line, points, text
        else:
            ...

A better way might be if it's possible to add an event handler when camera.fov changes?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kushalkolar added 6 commits September 26, 2025 23:42
@kushalkolar
update screenshots
37314ff
@kushalkolar
update more screenshots
680c4d8
@kushalkolar
more retries and longer delay for grabbing sklearn dataset
786e55a
@kushalkolar
update api docs
49ae64a
@kushalkolar
use diabetes dataset because of download issues with cali housing dat…
0dbd12f
…aset
@kushalkolar
EdgeWindow window flags was causing problems with autodoc
346c06b
@kushalkolar

kushalkolar commented Sep 27, 2025

Copy link
Copy Markdown
Member

All tests against pygfx@main are passing so I will merge, can do the axes thing in another PR, #903

The tests that are failing are all against the latest release of pygfx, which does not work with the latest imgui so it's fine to skip.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kushalkolar
kushalkolar approved these changes Sep 27, 2025
View reviewed changes
@kushalkolar
kushalkolar merged commit 0e75f6c into main Sep 27, 2025
@kushalkolar
kushalkolar deleted the alpha branch September 27, 2025 06:36
@kushalkolar kushalkolar mentioned this pull request Sep 27, 2025
separate AlphaFeature for PositionsGraphic subclasses? #754
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@kushalkolar kushalkolar kushalkolar approved these changes
@clewis7 clewis7 Awaiting requested review from clewis7 clewis7 is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@almarklein @kushalkolar @Korijn
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.