Repository navigation
Description
Description
On the WebGL2 backend of WebGPURenderer, a color clear does nothing if the previous draw used a material with colorWrite: false: the render target keeps its old content.
WebGLBackend.clear() re-enables the depth and stencil write masks before clearing, but not the color one:
if ( depth ) this.state.setDepthMask( true );
if ( stencil ) this.state.setStencilMask( 0xffffffff );
// no setColorMask( true )gl.clear() / gl.clearBufferfv() honor gl.colorMask, so the clear is masked out. The WebGPU backend is not affected, since its clear is a render pass loadOp, which ignores write masks.
Real-world impact: we hit it with a depth-only occluder pass (colorWrite: false) rendered before the main scene. The next frame's clear did nothing, and a blended plane drawn on top accumulated frame after frame, turning to black.
Reproduction steps
- Create
new WebGPURenderer( { forceWebGL: true } ). - Render a mesh with
MeshBasicMaterial( { colorWrite: false } )into a render target, clear color green. - Render an empty scene into the same target with
autoClearon and clear color red. - Read the target back: it is still green. With
forceWebGL: falseit is red, as expected.
Code
import * as THREE from 'three/webgpu';
const renderer = new THREE.WebGPURenderer( { forceWebGL: true } );
await renderer.init();
const target = new THREE.RenderTarget( 4, 4 );
const camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0.1, 10 );
camera.position.z = 1;
const occluderScene = new THREE.Scene();
occluderScene.add( new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), new THREE.MeshBasicMaterial( { colorWrite: false } ) ) );
renderer.setRenderTarget( target );
renderer.setClearColor( 0x00ff00, 1 );
renderer.render( occluderScene, camera ); // leaves gl.colorMask( false, ... )
renderer.setClearColor( 0xff0000, 1 );
renderer.render( new THREE.Scene(), camera ); // should clear to red
renderer.setRenderTarget( null );
const px = await renderer.readRenderTargetPixelsAsync( target, 0, 0, 1, 1 );
console.log( [ ...px ] ); // WebGLBackend: [0, 255, 0, 255] — WebGPUBackend: [255, 0, 0, 255]Proposed fix, in WebGLBackend.clear():
if ( color ) this.state.setColorMask( true );
if ( depth ) this.state.setDepthMask( true );
if ( stencil ) this.state.setStencilMask( 0xffffffff );It is safe, because every draw sets the mask again from its material (setMaterial() → setColorMask( material.colorWrite )). With this change applied as a patch, the repro reads red on both backends.
Live example
https://jsfiddle.net/j9xewz2f/1/
Version
r186 (0.186.1). The same code is still in WebGLBackend.js on dev.
Version
r186.1
Device
Desktop
Browser
Chrome
OS
MacOS
Activity
cedricpinson commentedon Oct 1, 2026
thank you