Jelajahi Sumber

WebGPURenderer: Harmonize clear of MRT textures. (#30586)

* WebGPURenderer: Harmonize clear of MRT textures.

* E2E: Update screenshots.
Michael Herzog 10 bulan lalu
induk
melakukan
bcae459799

TEMPAT SAMPAH
examples/screenshots/webgpu_multiple_rendertargets.jpg


TEMPAT SAMPAH
examples/screenshots/webgpu_multiple_rendertargets_readback.jpg


+ 9 - 1
src/renderers/webgl-fallback/WebGLBackend.js

@@ -793,7 +793,15 @@ class WebGLBackend extends Backend {
 
 					for ( let i = 0; i < descriptor.textures.length; i ++ ) {
 
-						gl.clearBufferfv( gl.COLOR, i, [ clearColor.r, clearColor.g, clearColor.b, clearColor.a ] );
+						if ( i === 0 ) {
+
+							gl.clearBufferfv( gl.COLOR, i, [ clearColor.r, clearColor.g, clearColor.b, clearColor.a ] );
+
+						} else {
+
+							gl.clearBufferfv( gl.COLOR, i, [ 0, 0, 0, 1 ] );
+
+						}
 
 					}
 

+ 13 - 3
src/renderers/webgpu/WebGPUBackend.js

@@ -442,13 +442,23 @@ class WebGPUBackend extends Backend {
 
 				}
 
+				// only apply the user-defined clearValue to the first color attachment like in beginRender()
+
+				let clearValue = { r: 0, g: 0, b: 0, a: 1 };
+
+				if ( i === 0 && colorAttachmentsConfig.clearValue ) {
+
+					clearValue = colorAttachmentsConfig.clearValue;
+
+				}
+
 				colorAttachments.push( {
 					view,
 					depthSlice: sliceIndex,
 					resolveTarget,
-					loadOp: GPULoadOp.Load,
-					storeOp: GPUStoreOp.Store,
-					...colorAttachmentsConfig
+					loadOp: colorAttachmentsConfig.loadOP || GPULoadOp.Load,
+					storeOp: colorAttachmentsConfig.storeOP || GPUStoreOp.Store,
+					clearValue: clearValue
 				} );
 
 			}

粤ICP备19079148号