-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[Feat] Add autoHighlightBlending prop to Layer #9291
Comments
Thanks for looking into this tricky problem! And for prepping some examples (I always wanted a deck.gl doc page about blending with image / video examples such as these to help demystify blending for users.) In terms of feedback on the proposal, first I note that luma.gl exposes the WebGPU blend parameter system, see https://luma.gl/docs/api-reference/core/parameters#blending This system offers a lot of control with separate parameters for color and alpha blending. However in the proposal we are not just passing through these parameters. Instead it looks like we are defining some new prop that offers a few combinations using some "higher level" constants. That might be fine, but one of the blend functions in the underlying blend system is called Also, if we are in effect defining a new higher level blending system, should we make sure we document it in a central place, and use it (or at least plan to use it) across the API - For example, I believe that Mesh and ScenegraphLayers blend their instance colors into the underlying meshes etc and could offer similar control using similarly named props? |
Side note: Perhaps surprisingly, blending in GPU APIs is not a "frozen" feature. There is a lot of activity in blending right now:
|
Another thing to consider is that we might want to move to premultiplied colors in the future to further improve blending quality. |
Thanks for the input. My intention with I would hope we could reduce the number of variables that can be configured to just one, but not by introducing "higher-level" constants, but by mandating that some of the original 6 constants them cannot be configured |
Just to make sense of what luma does right now, the blending code looks like this: float highLightAlpha = picking.highlightColor.a;
float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
float highLightRatio = highLightAlpha / blendedAlpha;
vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
return vec4(blendedRGB, blendedAlpha); If we go by the notation from MDN:
we have:
Thus for the alpha calculation the current constants used are:
However the RGB is computed using To move forward and to align with standards I would propose we re-write the shader to support passing in As for the color blending I'm not sure how much value there is in allowing this, as we are always just blending with a constant color anyway & the driving motivation for this proposal is the removal of aliased edges, not to implement some complex hover effects |
Target Use Case
Currently the picking module always blends the alpha of
autohighlightColor
with the alpha of the fragment. Layers with partial transparency thus end up with an ugly aliased outline, in particular this is obvious withIconLayer
(but alsoScatterplotLayer
)Screen.Recording.2024-12-11.at.10.01.24.mov
Proposal
The luma picking module is enhanced with a new prop,
blendHighlightAlpha
. It defaults to'normal'
to maintain existing behavior, but when it is'src'
the fragment color is blended as before, but the alpha is unchanged.The
Layer
class adds a new prop,autoHighlightBlending
(also defaulting to'normal'
), with select layers (likeIconLayer
) changing the default to'src'
.Why add a new prop?
The
highlightColor
prop supports bothRGB
&RGBA
colors, so in theory we could only apply'normal'
blending when anRGBA
highlightColor
is used, and use'src'
withRGB
.However there is value in allowing the user to explicitly use the
autoHighlightBlending
prop to support different behaviors:highlightColor
autoHighlightBlending
[255, 0, 0, 255]
'normal'
[255, 0, 0, 255]
'src'
[255, 255, 255, 128]
'src'
[0, 0, 0, 128]
'src'
The prop is defined as a string constant in order to allow future expansion, for example
'multiply'
could compute the output alpha ascolor.a * picking.highlightColor.a
to allow for fading (not sure if this is useful).Tint all pixels, while preserving transparency
Screen.Recording.2024-12-11.at.10.02.16.mov
Lighten all pixels, while preserving transparency
Screen.Recording.2024-12-11.at.10.34.26.mov
Darken all pixels, while preserving transparency
Screen.Recording.2024-12-11.at.10.35.00.mov
The text was updated successfully, but these errors were encountered: