Skip to content

Add per-attachment clear colors for multiple render targets - #9142

Merged
mvaligursky merged 1 commit into
mainfrom
mv-mrt-clear
Jul 30, 2026
Merged

Add per-attachment clear colors for multiple render targets#9142
mvaligursky merged 1 commit into
mainfrom
mv-mrt-clear

Conversation

@mvaligursky

Copy link
Copy Markdown
Contributor

Allows each color attachment of a multiple-render-target render pass to use its own clear color and clear flag. Previously WebGL cleared all attachments using a single gl.clear call, which applied attachment 0's clear color to every attachment, and ignored the per-attachment clear flags. WebGPU already supported this.

Changes:

  • RenderPass#setClearColor accepts an optional attachment index. When not specified, all attachments are modified as before.
  • On WebGL, a render pass with multiple color attachments now clears them individually using clearBufferfv, applying each attachment's own clear color and preserving the content of attachments which do not clear. Depth and stencil are cleared by the existing path, and the single-attachment path is unchanged.
  • The render pass clear no longer allocates the clear options per frame on WebGL.

API Changes:

  • RenderPass#setClearColor(color, index) - new optional index parameter, in 0 to 7 range, selecting the color attachment to modify.

Note that clearing integer format color attachments is not supported and asserts in debug builds - this can be added using clearBufferiv/clearBufferuiv when needed.

Examples:

  • The hidden test/independent-blending example now also demonstrates per-attachment clear colors - a standalone clear-only render pass clears each attachment to a different color, visible as the border around each panel, and the camera renders on top without clearing.

@github-actions

Copy link
Copy Markdown

Build size report

This PR changes the size of the minified bundles.

Bundle Minified Gzip Brotli
playcanvas.min.js 2355.3 KB (+0.3 KB, +0.01%) 604.9 KB (+0.1 KB, +0.02%) 469.8 KB (−0.0 KB, −0.01%)
playcanvas.min.mjs 2352.7 KB (+0.3 KB, +0.01%) 603.9 KB (+0.2 KB, +0.03%) 469.3 KB (+0.2 KB, +0.05%)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the engine’s render-pass clearing semantics to support per-color-attachment clear colors and clear enable flags for MRT (multiple render targets), bringing WebGL behavior in line with WebGPU and avoiding unnecessary per-frame allocations.

Changes:

  • Extends RenderPass#setClearColor(color, index) with an optional attachment index; omitting the index preserves the prior “apply to all attachments” behavior.
  • Updates the WebGL render-pass start path to clear MRT color attachments individually via gl.clearBufferfv, honoring per-attachment clear colors/flags while preserving attachments that are not cleared.
  • Adds unit tests validating setClearColor behavior across multiple attachments, and updates the independent-blending example to demonstrate per-attachment clears.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
test/platform/graphics/render-pass.test.mjs Adds unit tests for per-attachment clear-color API behavior on RenderPass.
src/platform/graphics/webgl/webgl-graphics-device.js Implements per-attachment MRT clearing on WebGL using clearBufferfv and removes per-frame clear-options allocations.
src/platform/graphics/render-pass.js Extends setClearColor to accept an optional attachment index and updates clear ops accordingly.
examples/src/examples/test/independent-blending.example.mjs Demonstrates per-attachment clear colors using a standalone clear-only render pass.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mvaligursky
mvaligursky merged commit d0da8bc into main Jul 30, 2026
11 checks passed
@mvaligursky
mvaligursky deleted the mv-mrt-clear branch July 30, 2026 15:23
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.

2 participants