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

Rendering Engine: Fix alpha support #16144

Merged
merged 3 commits into from
Feb 5, 2025
Merged

Conversation

Popov72
Copy link
Contributor

@Popov72 Popov72 commented Feb 4, 2025

I took Gary's WIP PR (#15573) as a base, but decided to go another way: keep all the existing code and simply honor the transparencyMode value when it's set.

This is because the existing code is quite complicated and has a lot of interconnections. I felt that trying to simplify it was too complicated and error-prone, so I made changes to simply use the transparencyMode parameter when set and keep the existing code-path otherwise.

At some point, we could deprecate the existing code and keep only the code related to transparencyMode. In addition, I think it's easier to document the breaking change:

  • if you give a non-null value to transparencyMode, it will always be honored, whatever values you give to other properties (like mesh visibility, material alpha, etc)
  • If transparencyMode is null, no change is made to the existing behavior, which is fully compatible with the past.

Other changes (from Gary's PR):

  • _shouldTurnAlphaTestOn has been renamed to needAlphaTestingForMesh. This is not a breaking change, since _shouldTurnAlphaTestOn was protected, and more in line with the existing needAlphaBlendingForMesh method.
  • All occurrences of needAlphaTesting have been replaced by needAlphaTestingForMesh: the behavior might change because of this, but it's not a breaking change but a bug fix.

Regarding failed visualization tests (3):

  • "NME loop block". It didn't fail because of the changes but because of timing issues (a node material was loaded in parallel to the test - I now wait for the material to load before returning from the createScene function).
  • "Visibility" and "Prepass SSAO + visibility" are in fact the same test. They are expected to fail, as they set transparencyMode=OPAQUE and define certain properties that allow blending in the current code path, whereas with the PR, the material is no longer transparent. To correct the tests, I set transparencyMode=ALPHABLEND and useAlphaFromAlbedoTexture=false. Indeed, when useAlphaFromAlbedoTexture=true (as was the case in the test), the alpha of the albedo texture is taken into account when transparencyMode=ALPHABLEND (as expected), but not in the actual code path when transparencyMode=OPAQUE. So the images were different if I didn't set useAlphaFromAlbedoTexture to false.

cc @sebavan and @bghgary

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 4, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 4, 2025

@bghgary bghgary mentioned this pull request Feb 4, 2025
@bjsplat
Copy link
Collaborator

bjsplat commented Feb 4, 2025

@bghgary
Copy link
Contributor

bghgary commented Feb 4, 2025

@Popov72 Can you make sure your changes fixes the problem described here? #15504

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 4, 2025

@sebavan
Copy link
Member

sebavan commented Feb 4, 2025

@RaananW is there an easy way to flag some functions to error out if they are used within the repo itself ? so that we could be sure to not make any mistake by using them in the future.

@bghgary
Copy link
Contributor

bghgary commented Feb 4, 2025

@Popov72 Sorry, one more issue to check: #15557

@Popov72
Copy link
Contributor Author

Popov72 commented Feb 4, 2025

@Popov72 Can you make sure your changes fixes the problem described here? #15504

It doesn't, but it seems the problem is with NVidia GPU. Even Khronos Sample Viewer doesn't display it correctly on my computer (RTX 3080), contrary to what Ed Mackey says in KhronosGroup/glTF-Sample-Assets#146:

image

In Babylon with the PR:

image

I will create an issue in the Chromium repo about this bug.

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 4, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 4, 2025

@Popov72
Copy link
Contributor Author

Popov72 commented Feb 4, 2025

@Popov72 Sorry, one more issue to check: #15557

This one does work with the PR.

@bghgary
Copy link
Contributor

bghgary commented Feb 4, 2025

It doesn't, but it seems the problem is with NVidia GPU. Even Khronos Sample Viewer doesn't display it correctly on my computer (RTX 3080), contrary to what Ed Mackey says in KhronosGroup/glTF-Sample-Assets#146:

Sorry, I wasn't expecting this change to fix the middle two issues. I'm only worried about the first one. I don't think it makes sense for the middle two in practice. I would not expect assets that use floating point boundaries to work.

@RaananW
Copy link
Member

RaananW commented Feb 4, 2025

@RaananW is there an easy way to flag some functions to error out if they are used within the repo itself ? so that we could be sure to not make any mistake by using them in the future.

Any example in this PR? So I will understand the use case?

@sebavan
Copy link
Member

sebavan commented Feb 4, 2025

@RaananW is there an easy way to flag some functions to error out if they are used within the repo itself ? so that we could be sure to not make any mistake by using them in the future.

Any example in this PR? So I will understand the use case?

Material needAlphaBlending() and needAlphaTesting() are only kept for back compat but should never be called from within the framework as we need to rely on their replacements needAlphaBlendingForMesh and needAlphaTestingForMesh.

So we want to keep the old ones in but prevent their use internally.

@RaananW
Copy link
Member

RaananW commented Feb 5, 2025

Material needAlphaBlending() and needAlphaTesting() are only kept for back compat but should never be called from within the framework as we need to rely on their replacements needAlphaBlendingForMesh and needAlphaTestingForMesh.

So we want to keep the old ones in but prevent their use internally.

Set them to be deprecated. We can then enable a no-deprecated API rule on eslint.

@sebavan
Copy link
Member

sebavan commented Feb 5, 2025

Material needAlphaBlending() and needAlphaTesting() are only kept for back compat but should never be called from within the framework as we need to rely on their replacements needAlphaBlendingForMesh and needAlphaTestingForMesh.
So we want to keep the old ones in but prevent their use internally.

Set them to be deprecated. We can then enable a no-deprecated API rule on eslint.

Perfect !!! cc @Popov72

@sebavan sebavan enabled auto-merge (squash) February 5, 2025 18:01
@bjsplat
Copy link
Collaborator

bjsplat commented Feb 5, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 5, 2025

@sebavan sebavan merged commit 69cdc19 into BabylonJS:master Feb 5, 2025
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants