8000 Add multiplicative blending by brisvag · Pull Request #7868 · napari/napari · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add multiplicative blending #7868

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

Merged
merged 2 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions napari/_vispy/utils/gl.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,11 @@ def fix_data_dtype(data: npt.NDArray) -> npt.NDArray:
'blend': True,
'blend_equation': 'min',
},
'multiplicative': {
'depth_test': False,
'cull_face': False,
'blend': True,
'blend_func': ('dst_color', 'zero', 'one', 'one'),
'blend_equation': 'func_add',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brisvag can you explain to me how this work? The func_add really threw me. 😂

what are the contents of the blend_func tuple?

Maybe a comment here would be interesting.

Copy link
Contributor Author
@brisvag brisvag May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's trippy, yeah. I learned from https://www.khronos.org/opengl/wiki/Blending#Blending_Parameters

Maybe I'll just put a link, cause this requires some background.

The relevant bits are:

Blending equation:

* Orgb = srgb * Srgb + drgb * Drgb
* Oa = sa * Sa + da * Da

(O = origin, D = destination, small is parameter, capitalized is the value itself)

"For example, if the blending you want is a straight multiplication of the source and destination colors, O = S * D, then you should set the GL_FUNC_ADD function. Then set the source parameter for that equation to GL_DST_COLOR, and set the destination parameter to GL_ZERO (we don't want to do addition, so null out the additive term). This will give O = D * S + 0 * D. "

Basically, we're using the destination color as a parameter for the origin color, and ignoring the destination color itself because it's already accounted for.

},
}
2 changes: 2 additions & 0 deletions napari/layers/base/_base_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Blending(StringEnum):
ADDITIVE = auto()
MINIMUM = auto()
OPAQUE = auto()
MULTIPLICATIVE = auto()


BLENDING_TRANSLATIONS = OrderedDict(
Expand All @@ -51,6 +52,7 @@ class Blending(StringEnum):
(Blending.ADDITIVE, trans._('additive')),
(Blending.MINIMUM, trans._('minimum')),
(Blending.OPAQUE, trans._('opaque')),
(Blending.MULTIPLICATIVE, trans._('multiplicative')),
]
)

Expand Down
Loading
0