Skip to content

feat(core): Support clear color, depth, and stencil on multiple views - #9650

Merged
chrisgervang merged 14 commits into
masterfrom
chr/clear-color-per-view
Jul 14, 2025
Merged

chrisgervang merged 14 commits into
masterfrom
chr/clear-color-per-view

Conversation

@chrisgervang

@chrisgervang chrisgervang commented Jun 2, 2025 •

Copy link
Copy Markdown
Collaborator

Closes #8838

Enhances the clear properties for managing viewport buffers across multiple views. Adding new properties (clearColor, clearDepth, and clearStencil) to control buffer clearing behavior. The value used to clear stencil and depth buffers can now be customized.

Change List

  • View#clear is now a simple boolean flag. Removed the object interface. Customize buffer settings with the new props instead.
  • Adds View#clearColor: number[] | false
  • Adds View#clearDepth: number | false
  • Adds View#clearStencil: number | false

Comment thread docs/api-reference/core/view.md Resolved
Comment thread docs/api-reference/core/view.md Outdated
Comment on lines +90 to +94
**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`).

@chrisgervang chrisgervang Jun 2, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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?

Comment thread modules/core/src/views/view.ts Outdated
Comment on lines +34 to +39
/** 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;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just a nit, my understanding of the options is:

  • true: clear the view
  • false: do not clear the view
  • undefined: no opinion, respect what is passed in via renderOpts

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Where are renderOpts set? The view docs don't mention it and maybe they should

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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?

Comment thread modules/core/src/passes/layers-pass.ts Resolved

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

@coveralls

coveralls commented Jun 3, 2025 •

Copy link
Copy Markdown

Coverage Status

coverage: 91.695% (+0.02%) from 91.679%
when pulling 78449b3 on chr/clear-color-per-view
into a1f5321 on master.

@felixpalmer felixpalmer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.
@chrisgervang

Copy link
Copy Markdown
Collaborator Author

@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({

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 ibgreen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread docs/api-reference/core/view.md Resolved
stencilToUse = clearStencil;
}

const clearRenderPass = this.device.beginRenderPass({

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

@chrisgervang chrisgervang changed the title feat: clear color per view feat(core): Support clear color, depth, and stencil on multiple views Jul 14, 2025
@chrisgervang
chrisgervang merged commit b04748b into master Jul 14, 2025
@chrisgervang
chrisgervang deleted the chr/clear-color-per-view branch July 14, 2025 23:16
chrisgervang added a commit that referenced this pull request Jul 14, 2026
* 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]>
chrisgervang added a commit that referenced this pull request Jul 16, 2026
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] Specify clearColor per view

4 participants