Support for new blend modes: CLEAR, ALPHA_MAX
John Hendrikx
john.hendrikx at gmail.com
Tue Jun 24 19:41:38 UTC 2025
I've been doing some Canvas work to implement a simple image editing
system, and I noticed that some things are quite hard to do due to a
lack of certain blend modes.
1) Given an empty fully transparent Canvas, you can easily draw opaque
ovals onto it (using a circular brush) but cannot use `fillOval` to
clear an area (back to fully transparent). The only option available
here seems to be `clearRect` which obviously is not going to look very
nice when working with a circular brush...
A blend mode "CLEAR" (which is pretty common) would really help here.
2) Given an empty fully transparent Canvas, drawing partially
transparent ovals (or even a RadialGradient where the brush becomes less
transparent at the edges) doesn't work nicely when strokes partially
overlap, or when you compensate for mouse movements by drawing
intermediate ovals -- the intended transparency at the edges of strokes
quickly disappears when the stroke overlaps multiple times because of
repeated fillOvals to draw the full stroke made by the mouse. Single
clicks work as expected.
A blend mode "ALPHA_MAX" (uncommon) could allow this; given a source and
destination pixel, it would never set alpha to a value that is higher
than either source or destination (it just takes the maximum); SRC_OVER
will keep increasing alpha until it is fully opaque. This blend mode
would be useful when drawing into an overlapping Canvas and merging the
results with the underlying Canvas after each stroke completes.
--
Now it seems to me that all it would take to add additional blend modes
is extending the BlendMode enum, the internal Mode enum, and adding a
new shader file per blend mode. The software pipeline could also be
extended to support these (but I think that may be optional as this
pipeline doesn't need to support all blend modes?)
So my question, is this something that would get support if a PR is
provided, or is there a reason to limit the BlendModes and/or shader
files to some specific set?
--John
More information about the openjfx-dev
mailing list