Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGLRenderer: Honor alpha definition in custom context. #23504

Merged
merged 1 commit into from
Feb 17, 2022

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Feb 16, 2022

Fixed #23495.

Description

Ensures the _alpha is properly set if a custom rendering context is passed to WebGLRenderer.

@mrdoob
Copy link
Owner

mrdoob commented Feb 16, 2022

What do you think about doing this instead?

diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js
index e7d52b3292..4a51ea07a1 100644
--- a/src/renderers/WebGLRenderer.js
+++ b/src/renderers/WebGLRenderer.js
@@ -59,7 +59,6 @@ function WebGLRenderer( parameters = {} ) {
 	const _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
 		_context = parameters.context !== undefined ? parameters.context : null,
 
-		_alpha = parameters.alpha !== undefined ? parameters.alpha : false,
 		_depth = parameters.depth !== undefined ? parameters.depth : true,
 		_stencil = parameters.stencil !== undefined ? parameters.stencil : true,
 		_antialias = parameters.antialias !== undefined ? parameters.antialias : false,
@@ -300,7 +299,7 @@ function WebGLRenderer( parameters = {} ) {
 		materials = new WebGLMaterials( properties );
 		renderLists = new WebGLRenderLists();
 		renderStates = new WebGLRenderStates( extensions, capabilities );
-		background = new WebGLBackground( _this, cubemaps, state, objects, _alpha, _premultipliedAlpha );
+		background = new WebGLBackground( _this, cubemaps, state, objects, _premultipliedAlpha );
 		shadowMap = new WebGLShadowMap( _this, objects, capabilities );
 
 		bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
diff --git a/src/renderers/webgl/WebGLBackground.js b/src/renderers/webgl/WebGLBackground.js
index c50575b740..2f8d03d74e 100644
--- a/src/renderers/webgl/WebGLBackground.js
+++ b/src/renderers/webgl/WebGLBackground.js
@@ -7,10 +7,10 @@ import { Mesh } from '../../objects/Mesh.js';
 import { ShaderLib } from '../shaders/ShaderLib.js';
 import { cloneUniforms } from '../shaders/UniformsUtils.js';
 
-function WebGLBackground( renderer, cubemaps, state, objects, alpha, premultipliedAlpha ) {
+function WebGLBackground( renderer, cubemaps, state, objects, premultipliedAlpha ) {
 
 	const clearColor = new Color( 0x000000 );
-	let clearAlpha = alpha === true ? 0 : 1;
+	let clearAlpha = renderer.getContextAttributes().alpha === true ? 0 : 1;
 
 	let planeMesh;
 	let boxMesh;

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Feb 17, 2022

It will work for a custom context with alpha: true. However it breaks the current usage of alpha: true when passed as a ctor parameter to WebGLRenderer.

three.js always creates a rendering context with alpha: true since last release. However, the alpha parameter is still used for picking a different clear alpha value in WebGLBackground. With the above code, this does not happen anymore.

@mrdoob
Copy link
Owner

mrdoob commented Feb 17, 2022

Ah... That's true 👍

@mrdoob mrdoob added this to the r138 milestone Feb 17, 2022
@mrdoob mrdoob merged commit fb9d575 into mrdoob:dev Feb 17, 2022
@mrdoob
Copy link
Owner

mrdoob commented Feb 17, 2022

Thanks!

donmccurdy pushed a commit to donmccurdy/three.js that referenced this pull request Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebGLRenderer: background is not set to transparent on 0.137.0 version
2 participants