Skip to content

Commit 9023ca8

Browse files
committed
Renderers: Set premultipliedAlpha to true when using SubtractiveBlending/MultiplyBlending.
1 parent 74e50e8 commit 9023ca8

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,17 @@ class WebGLState {
338338

339339
}
340340

341+
if ( premultipliedAlpha === false ) {
342+
343+
if ( blending === SubtractiveBlending || blending === MultiplyBlending ) {
344+
345+
warnOnce( 'WebGLState: Material premultipliedAlpha was set to true because MultiplyBlending and SubtractiveBlending require it.' );
346+
premultipliedAlpha = true;
347+
348+
}
349+
350+
}
351+
341352
if ( premultipliedAlpha ) {
342353

343354
switch ( blending ) {
@@ -376,16 +387,6 @@ class WebGLState {
376387
gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE );
377388
break;
378389

379-
case SubtractiveBlending:
380-
warnOnce( 'WebGLState: SubtractiveBlending works best with material.premultipliedAlpha = true.' );
381-
gl.blendFuncSeparate( gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE );
382-
break;
383-
384-
case MultiplyBlending:
385-
warnOnce( 'WebGLState: MultiplyBlending works best with material.premultipliedAlpha = true.' );
386-
gl.blendFuncSeparate( gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, gl.ZERO, gl.ONE );
387-
break;
388-
389390
default:
390391
error( 'WebGLState: Invalid blending: ', blending );
391392
break;

src/renderers/webgl/WebGLState.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,17 @@ function WebGLState( gl, extensions ) {
651651

652652
}
653653

654+
if ( premultipliedAlpha === false ) {
655+
656+
if ( blending === SubtractiveBlending || blending === MultiplyBlending ) {
657+
658+
warnOnce( 'WebGLState: Material premultipliedAlpha was set to true because MultiplyBlending and SubtractiveBlending require it.' );
659+
premultipliedAlpha = true;
660+
661+
}
662+
663+
}
664+
654665
if ( premultipliedAlpha ) {
655666

656667
switch ( blending ) {
@@ -689,16 +700,6 @@ function WebGLState( gl, extensions ) {
689700
gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE );
690701
break;
691702

692-
case SubtractiveBlending:
693-
warnOnce( 'WebGLState: SubtractiveBlending works best with material.premultipliedAlpha = true.' );
694-
gl.blendFuncSeparate( gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE );
695-
break;
696-
697-
case MultiplyBlending:
698-
warnOnce( 'WebGLState: MultiplyBlending works best with material.premultipliedAlpha = true.' );
699-
gl.blendFuncSeparate( gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA, gl.ZERO, gl.ONE );
700-
break;
701-
702703
default:
703704
error( 'WebGLState: Invalid blending: ', blending );
704705
break;

src/renderers/webgpu/utils/WebGPUPipelineUtils.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,17 @@ class WebGPUPipelineUtils {
413413

414414
};
415415

416+
if ( premultipliedAlpha === false ) {
417+
418+
if ( blending === SubtractiveBlending || blending === MultiplyBlending ) {
419+
420+
warnOnce( 'WebGPURenderer: Material premultipliedAlpha was set to true because MultiplyBlending and SubtractiveBlending require it.' );
421+
premultipliedAlpha = true;
422+
423+
}
424+
425+
}
426+
416427
if ( premultipliedAlpha ) {
417428

418429
switch ( blending ) {
@@ -447,16 +458,6 @@ class WebGPUPipelineUtils {
447458
setBlend( GPUBlendFactor.SrcAlpha, GPUBlendFactor.One, GPUBlendFactor.One, GPUBlendFactor.One );
448459
break;
449460

450-
case SubtractiveBlending:
451-
warnOnce( 'WebGPURenderer: SubtractiveBlending works best with material.premultipliedAlpha = true.' );
452-
setBlend( GPUBlendFactor.Zero, GPUBlendFactor.OneMinusSrc, GPUBlendFactor.Zero, GPUBlendFactor.One );
453-
break;
454-
455-
case MultiplyBlending:
456-
warnOnce( 'WebGPURenderer: MultiplyBlending works best with material.premultipliedAlpha = true.' );
457-
setBlend( GPUBlendFactor.Dst, GPUBlendFactor.OneMinusSrcAlpha, GPUBlendFactor.Zero, GPUBlendFactor.One );
458-
break;
459-
460461
}
461462

462463
}

0 commit comments

Comments
 (0)