Repository navigation
feat(core): Support clear color, depth, and stencil on multiple views - #9650
Conversation
| **Interaction between clearing properties:** | ||
| * `clear: false` - Disables all clearing operations for this view, regardless of `clearColor` or `clearDepth` settings. | ||
| * `clear: true` - Clears both color and depth buffers. | ||
| * `clearColor` - When defined, specifies the color used for clearing, but only has an effect if `clear` is not `false` (i.e., `true` or `undefined`). | ||
| * `clearDepth` - When defined, controls depth buffer clearing, but only has an effect if `clear` is not `false` (i.e., `true` or `undefined`). |
There was a problem hiding this comment.
I want to remark that these prop interactions are a bit complicated.
I wonder if it would be simpler if clearColor and clearDepth settings overrode clear: false instead of the other way around (the current version)?
Basically, should clearColor setting take priority, or clear: false?
clear: true is more obvious -- the transparent color should override by clearColor.
Zooming out, the clear property mainly remains for backwards compatibility and convenience so that users don't need to set clearColor: [0,0,0,0] and clearDepth: true. Is it worth keeping and if so, what interaction is the simplest?
Should we go back to the nested option?
There was a problem hiding this comment.
Bear in mind the use case of interleaved rendering. Here a single flag is explicitly saying not to clear: https://github.com/visgl/deck.gl/blob/master/modules/mapbox/src/deck-utils.ts#L181
Also having just spent a lot of time trying to get blending working in all scenarios, I would be very cautious of changing how these flags interact.
There was a problem hiding this comment.
Good point, interleaved renders into a fullscreen MapView.. I wonder if that can be configured to not clear rather than using this private flag?
I share your concern as well. The question of prop interaction is moreso scoped to this new flat api design (per the issue discussion), where previously we had a clear flag or a configuration, and we now have both. And the question is what to do when any combination is set? Or, should we go back to the nested api?
There was a problem hiding this comment.
Circling back to the interleaved case,
The default is not to clear, so the default views made for interleaved rendering should continue to work as before.
I need to check what appending a overlapping view with clearing enabled does. I wonder if deck ever supported the combination of a minimap with clearing, maplibre and an interleaved deck view?
| /** When using multiple views, set this flag to wipe the pixels drawn by other overlapping views. Default `undefined` */ | ||
| clear?: boolean; | ||
| /** Color to clear the viewport with, in RGBA format [r, g, b, a]. Values are 0-255. Default `undefined` */ | ||
| clearColor?: number[]; | ||
| /** Whether to clear the depth buffer. Default `undefined` */ | ||
| clearDepth?: boolean; |
There was a problem hiding this comment.
As the docs note, deck clears the entire screen before each render so I assumed these are per-view overrides, and therefore, should all be undefined by default (e.g. don't perform clearing)
There was a problem hiding this comment.
Just a nit, my understanding of the options is:
true: clear the viewfalse: do not clear the viewundefined: no opinion, respect what is passed in viarenderOpts
There was a problem hiding this comment.
Where are renderOpts set? The view docs don't mention it and maybe they should
There was a problem hiding this comment.
I think your understanding simplifies this a bit if we followed it.. I have implemented something more complicated here where I'd treated clearColor as a flag and an option. That way, if clearColor was set and clear was not then it'd still clear.. this brevity shortcut might be nice but is it worth the amount of explaining it requires?
There was a problem hiding this comment.
I've updated this PR and think the implementation is aligned with your understanding now.
There might be some more discussion to have around how we're setting up render passes. We set up one main pass prior to inspecting the views, and then more brief passes for each viewport with clearing enabled.
I'm wondering why we don't just set up a new render pass for each view? I'm assuming there was some good reason to do it as we are currently, or maybe this is left over and a candidate for a refactor?
There was a problem hiding this comment.
Note: the fullscreen semi-opaque blue view is cleared on the top view explicitly. The bottom left explicitly disabled clearing despite clearColor being set, and the bottom right shows the default behavior.
felixpalmer
left a comment
There was a problem hiding this comment.
Looks good to me, but think it could benefit from another pair of eyes
Introduces a new clearStencil property. Also reverts to a simple clear flag (option 1 in #9650). Now clearColor, clearDepth, and clearStencil are just options for customizing the clear values to use. Setting any to false will also disable clearing that buffer (and instead load the existing value)
The clear flag is now required to clear, and test that clearColor can be disabled with false
Clarifies and expands documentation for the `clear`, `clearColor`, `clearDepth`, and `clearStencil` properties in the View API reference. Adds details on default values, buffer clearing behavior, and updates examples to reflect the new options and usage.
Changed the default clearColor to [0, 0, 0, 0] (transparent), clearDepth to 1.0 (far plane), and clearStencil to 0 (clear) in documentation and code. Updated type annotations and comments for clarity and consistency with the new defaults.
|
@felixpalmer @ibgreen @Pessimistress I've updated this PR to implement option 1 from #9650, verbatim. I'd like to get your eyes on it.. hoping this can go into 9.2 |
| stencilToUse = clearStencil; | ||
| } | ||
|
|
||
| const clearRenderPass = this.device.beginRenderPass({ |
There was a problem hiding this comment.
We probably do not care about WebGPU right now, but I don't think this is going to work on WebGPU.
- The commands recorded in the render passes are going to be injected into the command stream at the location of beginRenderPass.
- So, we need to begin this clear render pass before the render pass that has been passed in.
- If we can do that, we can probably just apply the clear parameters to the creation of that render pass.
There was a problem hiding this comment.
Is there a tracker for potential issues like this?
@felixpalmer and I discussed this a bit. The current implementation re-uses the same pass for all views (draws the layer multiple times with a different viewport).
Might need to create a pass for each view
|
|
||
| #### `clearColor` (number[] | false, optional) {#clearcolor} | ||
|
|
||
| Specifies the color to clear the viewport with, as an array of four numbers `[r, g, b, a?]`. Each channel should be an integer between 0 and 255. For example, `[255, 0, 0, 255]` for opaque red. If `clearColor` is `false`, the depth buffer will not be cleared. If `clear` is set to `false`, this property will be ignored. |
There was a problem hiding this comment.
Just thinking to myself, doubt that we'll get to any meaningful concluson at this point.
- A little confusing that this almost copies luma.gl props but "quitely" changes the range of one of them.
- Maybe we could offer a separate prop to distinguish color scales, like
clearColor255
ibgreen
left a comment
There was a problem hiding this comment.
I think it would be worth mentioning in whats-new that this has been fixed. We don't normally talk about bug fixes but this is a nice feature that has been restored and we don't have too much in the news right now.
| stencilToUse = clearStencil; | ||
| } | ||
|
|
||
| const clearRenderPass = this.device.beginRenderPass({ |
There was a problem hiding this comment.
Is there a tracker for potential issues like this?
@felixpalmer and I discussed this a bit. The current implementation re-uses the same pass for all views (draws the layer multiple times with a different viewport).
Might need to create a pass for each view
* fix(core): do not write View clearColor into the picking buffer Since #9650, the View clear/clearColor props were applied to every render target, including the picking framebuffer. Picking colors encode object references, so clearing with a non-transparent color makes every background pixel decode as a picked object, breaking picks within the picking radius and logging "Picked non-existent layer" errors. Clear with transparent black instead when picking. * fix(core): preserve clearColor:false semantics while picking Per review feedback, only substitute transparent black for the view's clearColor when a color clear was actually requested. A view with clear: true and clearColor: false still means "clear depth/stencil but don't touch color" during picking, preserving picking data rendered by underlying overlapping views. Add a regression test with two overlapping views that fails if the color is force-cleared. --------- Co-authored-by: Chris Gervang <[email protected]>
* fix(core): do not write View clearColor into the picking buffer Since #9650, the View clear/clearColor props were applied to every render target, including the picking framebuffer. Picking colors encode object references, so clearing with a non-transparent color makes every background pixel decode as a picked object, breaking picks within the picking radius and logging "Picked non-existent layer" errors. Clear with transparent black instead when picking. * fix(core): preserve clearColor:false semantics while picking Per review feedback, only substitute transparent black for the view's clearColor when a color clear was actually requested. A view with clear: true and clearColor: false still means "clear depth/stencil but don't touch color" during picking, preserving picking data rendered by underlying overlapping views. Add a regression test with two overlapping views that fails if the color is force-cleared. --------- Co-authored-by: Chris Gervang <[email protected]>
Closes #8838
Enhances the
clearproperties for managing viewport buffers across multiple views. Adding new properties (clearColor,clearDepth, andclearStencil) to control buffer clearing behavior. The value used to clear stencil and depth buffers can now be customized.Change List
View#clearis now a simple boolean flag. Removed the object interface. Customize buffer settings with the new props instead.View#clearColor: number[] | falseView#clearDepth: number | falseView#clearStencil: number | false