Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/misc_exporter_usdz.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@

const geometry = new THREE.PlaneGeometry();
const material = new THREE.MeshBasicMaterial( {
map: shadowTexture, blending: THREE.MultiplyBlending, toneMapped: false, premultipliedAlpha: true
map: shadowTexture, blending: THREE.MultiplyBlending, toneMapped: false
} );

const mesh = new THREE.Mesh( geometry, material );
Expand Down
1 change: 0 additions & 1 deletion examples/webgl_materials_blending.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
const material = new THREE.MeshBasicMaterial( { map: map } );
material.transparent = true;
material.blending = blending.constant;

material.premultipliedAlpha = true;

const x = ( i - blendings.length / 2 ) * 110;
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_materials_car.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry( 0.655 * 4, 1.3 * 4 ),
new THREE.MeshBasicMaterial( {
map: shadow, blending: THREE.MultiplyBlending, toneMapped: false, transparent: true, premultipliedAlpha: true
map: shadow, blending: THREE.MultiplyBlending, toneMapped: false, transparent: true
} )
);
mesh.rotation.x = - Math.PI / 2;
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_materials_envmaps_groundprojected.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry( 0.655 * 4, 1.3 * 4 ),
new THREE.MeshBasicMaterial( {
map: shadow, blending: THREE.MultiplyBlending, toneMapped: false, transparent: true, premultipliedAlpha: true
map: shadow, blending: THREE.MultiplyBlending, toneMapped: false, transparent: true
} )
);
mesh.rotation.x = - Math.PI / 2;
Expand Down
21 changes: 12 additions & 9 deletions src/renderers/webgl-fallback/utils/WebGLState.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth
} from '../../../constants.js';
import { Vector4 } from '../../../math/Vector4.js';
import { error } from '../../../utils.js';
import { error, warnOnce } from '../../../utils.js';

let equationToGL, factorToGL;

Expand Down Expand Up @@ -376,14 +376,6 @@ class WebGLState {
gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE );
break;

case SubtractiveBlending:
error( 'WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true' );
break;

case MultiplyBlending:
error( 'WebGLState: MultiplyBlending requires material.premultipliedAlpha = true' );
break;

default:
error( 'WebGLState: Invalid blending: ', blending );
break;
Expand Down Expand Up @@ -749,6 +741,17 @@ class WebGLState {

this.setFlipSided( flipSided );

if ( material.premultipliedAlpha === false ) {

if ( material.blending === MultiplyBlending || material.blending === SubtractiveBlending ) {

warnOnce( 'WebGLState: Material premultipliedAlpha was set to true because MultiplyBlending and SubtractiveBlending require it.' );
material.premultipliedAlpha = true;

}

}

( material.blending === NormalBlending && material.transparent === false )
? this.setBlending( NoBlending )
: this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
Expand Down
21 changes: 12 additions & 9 deletions src/renderers/webgl/WebGLState.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessEqualDepth, LessDepth, AlwaysDepth, NeverDepth, CullFaceFront, CullFaceBack, CullFaceNone, DoubleSide, BackSide, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, NoBlending, NormalBlending, AddEquation, SubtractEquation, ReverseSubtractEquation, MinEquation, MaxEquation, ZeroFactor, OneFactor, SrcColorFactor, SrcAlphaFactor, SrcAlphaSaturateFactor, DstColorFactor, DstAlphaFactor, OneMinusSrcColorFactor, OneMinusSrcAlphaFactor, OneMinusDstColorFactor, OneMinusDstAlphaFactor, ConstantColorFactor, OneMinusConstantColorFactor, ConstantAlphaFactor, OneMinusConstantAlphaFactor } from '../../constants.js';
import { Color } from '../../math/Color.js';
import { Vector4 } from '../../math/Vector4.js';
import { error } from '../../utils.js';
import { error, warnOnce } from '../../utils.js';

const reversedFuncs = {
[ NeverDepth ]: AlwaysDepth,
Expand Down Expand Up @@ -689,14 +689,6 @@ function WebGLState( gl, extensions ) {
gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE );
break;

case SubtractiveBlending:
error( 'WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true' );
break;

case MultiplyBlending:
error( 'WebGLState: MultiplyBlending requires material.premultipliedAlpha = true' );
break;

default:
error( 'WebGLState: Invalid blending: ', blending );
break;
Expand Down Expand Up @@ -772,6 +764,17 @@ function WebGLState( gl, extensions ) {

setFlipSided( flipSided );

if ( material.premultipliedAlpha === false ) {

if ( material.blending === MultiplyBlending || material.blending === SubtractiveBlending ) {

warnOnce( 'WebGLState: Material premultipliedAlpha was set to true because MultiplyBlending and SubtractiveBlending require it.' );
material.premultipliedAlpha = true;

}

}

( material.blending === NormalBlending && material.transparent === false )
? setBlending( NoBlending )
: setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.blendColor, material.blendAlpha, material.premultipliedAlpha );
Expand Down
21 changes: 12 additions & 9 deletions src/renderers/webgpu/utils/WebGPUPipelineUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
NeverStencilFunc, AlwaysStencilFunc, LessStencilFunc, LessEqualStencilFunc, EqualStencilFunc, GreaterEqualStencilFunc, GreaterStencilFunc, NotEqualStencilFunc
} from '../../../constants.js';

import { error } from '../../../utils.js';
import { error, warnOnce } from '../../../utils.js';

/**
* A WebGPU backend utility module for managing pipelines.
Expand Down Expand Up @@ -120,6 +120,17 @@ class WebGPUPipelineUtils {

let blending;

if ( material.premultipliedAlpha === false ) {

if ( material.blending === MultiplyBlending || material.blending === SubtractiveBlending ) {

warnOnce( 'WebGPURenderer: Material premultipliedAlpha was set to true because MultiplyBlending and SubtractiveBlending require it.' );
material.premultipliedAlpha = true;

}

}

if ( material.blending !== NoBlending && ( material.blending !== NormalBlending || material.transparent !== false ) ) {

blending = this._getBlending( material );
Expand Down Expand Up @@ -447,14 +458,6 @@ class WebGPUPipelineUtils {
setBlend( GPUBlendFactor.SrcAlpha, GPUBlendFactor.One, GPUBlendFactor.One, GPUBlendFactor.One );
break;

case SubtractiveBlending:
error( 'WebGPURenderer: SubtractiveBlending requires material.premultipliedAlpha = true' );
break;

case MultiplyBlending:
error( 'WebGPURenderer: MultiplyBlending requires material.premultipliedAlpha = true' );
break;

}

}
Expand Down