Skip to content

Commit 55c095d

Browse files
authored
WebGPURenderer: Set opaque blend mode for secondary MRT targets (#32265)
1 parent f367f20 commit 55c095d

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

src/renderers/webgl-fallback/WebGLBackend.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ class WebGLBackend extends Backend {
268268

269269
this.disjoint = this.extensions.get( 'EXT_disjoint_timer_query_webgl2' );
270270
this.parallel = this.extensions.get( 'KHR_parallel_shader_compile' );
271+
this.drawBuffersIndexedExt = this.extensions.get( 'OES_draw_buffers_indexed' );
271272

272273
}
273274

@@ -957,6 +958,12 @@ class WebGLBackend extends Backend {
957958

958959
state.setMaterial( material, frontFaceCW, hardwareClippingPlanes );
959960

961+
if ( context.textures !== null && context.textures.length > 1 ) {
962+
963+
state.setMRTBlending( context.textures );
964+
965+
}
966+
960967
state.useProgram( programGPU );
961968

962969
// vertex state

src/renderers/webgl-fallback/utils/WebGLState.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class WebGLState {
8585
this.currentBoundTextures = {};
8686
this.currentBoundBufferBases = {};
8787

88-
8988
this._init();
9089

9190
}
@@ -271,6 +270,22 @@ class WebGLState {
271270

272271
}
273272

273+
setMRTBlending( textures ) {
274+
275+
const gl = this.gl;
276+
const drawBuffersIndexedExt = this.backend.drawBuffersIndexedExt;
277+
278+
if ( ! drawBuffersIndexedExt ) return;
279+
280+
for ( let i = 1; i < textures.length; i ++ ) {
281+
282+
// use opaque blending for additional render targets
283+
drawBuffersIndexedExt.blendFuncSeparateiOES( i, gl.ONE, gl.ZERO, gl.ONE, gl.ZERO );
284+
285+
}
286+
287+
}
288+
274289
/**
275290
* Defines the blending.
276291
*

src/renderers/webgpu/utils/WebGPUPipelineUtils.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,22 @@ class WebGPUPipelineUtils {
152152

153153
const colorFormat = utils.getTextureFormatGPU( textures[ i ] );
154154

155-
targets.push( {
156-
format: colorFormat,
157-
blend: blending,
158-
writeMask: colorWriteMask
159-
} );
155+
if ( i === 0 ) {
156+
157+
targets.push( {
158+
format: colorFormat,
159+
blend: blending,
160+
writeMask: colorWriteMask
161+
} );
162+
163+
} else {
164+
165+
targets.push( {
166+
format: colorFormat,
167+
writeMask: colorWriteMask
168+
} );
169+
170+
}
160171

161172
}
162173

0 commit comments

Comments
 (0)