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

ShaderChunks: Ignore alpha in output_fragment when using NoBlending #22424

Merged
merged 4 commits into from
Aug 25, 2021
Merged

Conversation

mrdoob
Copy link
Owner

@mrdoob mrdoob commented Aug 25, 2021

Related issue: #15483 #18631 #21744 #22196 #22414

Description

This makes NoBlending behave as expected. Before this PR NoBlending was writing alpha pixels when the framebuffer had an alpha channel.

We can not use NoBlending to support GLTF's OPAQUE and MASK alpha modes which was previously broken when setting alpha: true in WebGLRenderer.

Here is an example with alpha: true and renderer.domElement.style.backgroundColor = 'red':

Before After
Screen Shot 2021-08-25 at 1 57 31 AM Screen Shot 2021-08-25 at 1 57 01 AM

Note: I'm following a similar implementation to Khronos' GLTF Viewer:

/cc @elalish @donmccurdy

@mrdoob mrdoob added this to the r132 milestone Aug 25, 2021
@WestLangley
Copy link
Collaborator

WestLangley commented Aug 25, 2021

Why are you overwriting diffuseColor.a to 1 at the end, rather than at the beginning?

OPAQUE - The rendered output is fully opaque and any alpha value is ignored.

That means it must be ignored from the start of the shader, no?

@mrdoob
Copy link
Owner Author

mrdoob commented Aug 25, 2021

@WestLangley
Copy link
Collaborator

But that is not "ignoring any alpha value" if you are honoring it.

The alphaMode property defines how the alpha value of the main factor and texture should be interpreted.
OPAQUE - The rendered output is fully opaque and any alpha value is ignored.

What you are doing is reasonable, it seems... I'm just not sure if that is what the spec calls for...

@mrdoob
Copy link
Owner Author

mrdoob commented Aug 25, 2021

I've just had a chat with @elalish about this and made me unsure about alphaMap but...

The GLTF spec says this:

https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#alpha-coverage

  • OPAQUE - The rendered output is fully opaque and any alpha value is ignored.
  • MASK - The rendered output is either fully opaque or fully transparent depending on the alpha value and the specified alpha cutoff value. This mode is used to simulate geometry such as tree leaves or wire fences.

Which makes me think the shader part of this PR is fine. But things get complicated when trying to get transmission working with alpha: #22425

I guess the GLTF spec doesn't say anything about disabling gl blend, so it's not possible in the current three.js API to do that. In the meantime, I'm going to try solving this by creating a OpaqueBlending (we can rename later).

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.

2 participants