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: background is not set to transparent on 0.137.0 version #23495

Closed
japie1235813 opened this issue Feb 15, 2022 · 7 comments · Fixed by #23504
Closed

WebGLRenderer: background is not set to transparent on 0.137.0 version #23495

japie1235813 opened this issue Feb 15, 2022 · 7 comments · Fixed by #23504

Comments

@japie1235813
Copy link

Describe the bug
We upgrades the threejs version recently from 0.131.3 to 0.137.0 tensorflow/tensorboard@420916a. It breaks our repo by not setting the background to black. (see screenshots before)
After debugging we found the cause is from the background is not set to transparent by "alpha: true". (which means, we can fix our issue by adding renderer.setClearColor(0x000000, 0);)
Is there any changes from the version that makes this stop working?

To Reproduce
You can reproduce the issue by clone our repo. Checkout to the upgrade comment and run TensorBoard (https://github.com/tensorflow/tensorboard).
However it requires some demo data to run the card. Let me know how I can assist.

Code
code point

//ts
   this.renderer = new THREE.WebGLRenderer({
      canvas: canvas as HTMLCanvasElement,
      context: canvas.getContext('webgl2', {
        antialias: true,
        precision: 'highp',
        alpha: true,
      } as WebGLContextAttributes) as WebGLRenderingContext,
    });

Screenshots
before (0.131.3)
Screen Shot 2022-02-14 at 3 50 06 PM

after (0.137.0)
Screen Shot 2022-02-14 at 4 04 13 PM

Platform:

  • Device: Desktop
  • OS: MacOS
  • Browser: Chrome
  • Three.js version: 0.131.3 (works) 0.137.0 (breaks)
@japie1235813 japie1235813 changed the title WebGLRenderer WebGLRenderer: background is not set to transparent on 0.137.0 version Feb 15, 2022
@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 15, 2022

Instead of creating the context by yourself, the following should fix the issue:

this.renderer = new THREE.WebGLRenderer({
  canvas: canvas as HTMLCanvasElement,
  antialias: true,
  alpha: true
});

BTW: AFAIK, precision is no WebGL context attribute.

In r137 the renderer always uses alpha: true when creating the WebGL rendering context. A fallback was implemented to support existing setups however it does not work for your case since you create the context by yourself. Meaning since you pass no alpha parameter when creating the renderer, the following line assigns false to _alpha:

_alpha = parameters.alpha !== undefined ? parameters.alpha : false,

And this value leads to a wrong alpha clear value in WebGLBackground:

let clearAlpha = alpha === true ? 0 : 1;

@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 15, 2022

@mrdoob We could fix this issue on our side however it means we have to call getContextAttributes() on the user provided context and then evaluate the defined alpha value.

@japie1235813
Copy link
Author

Thanks for the reply! Moving the params out of context fixes the issue.

@mrdoob
Copy link
Owner

mrdoob commented Feb 15, 2022

@mrdoob We could fix this issue on our side however it means we have to call getContextAttributes() on the user provided context and then evaluate the defined alpha value.

That sounds good 👍

@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 16, 2022

@japie1235813 The PR you have filed at tensorboard is not entirely correct. If you pass in context parameters like alpha or antialias to WebGLRenderer, you have to let three.js create the rendering context. You have to use:

this.renderer = new THREE.WebGLRenderer({
  canvas: canvas as HTMLCanvasElement,
  antialias: true,
  alpha: true
});

/cc @bmd3k

@japie1235813
Copy link
Author

so after #23504
it's one of the two usage?

this.renderer = new THREE.WebGLRenderer({
  canvas: canvas as HTMLCanvasElement,
  antialias: true,
  alpha: true
});

or

this.renderer = new THREE.WebGLRenderer({
      canvas: canvas as HTMLCanvasElement,
      context: canvas.getContext('webgl2', {
        antialias: true, // this looks not being taken?
        alpha: true,
      } as WebGLContextAttributes) as WebGLRenderingContext,
    });

@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 16, 2022

Correct. I recommend the first one though. Creating a rendering context manually should only be done if there is a compelling reason.

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 a pull request may close this issue.

3 participants