-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Material: Add "material.alphaHash" transparency mode #24271
Conversation
This is really cool! It is fast and the results are nice! With regards to TAA causing things to get brighter when it is enabled, it appears to do this with or without your changes. I checked here and it has that same bug in main: https://threejs.org/examples/?q=taa#webgl_postprocessing_taa. This wasn't the case a long time ago so some change in the last year or two must have broken it. But it is unrelated to your changes. |
Thanks @bhouston! I'll file that as a separate issue then, I'm having some other trouble with color management in post-processing (unrelated to TAARenderPass) that may be worth looking at. Assuming we'll find a fix so that the scene brightness doesn't fluctuate, I would be interested in everyone's feedback on whether we want to support this. Happy to clean up the example and implementation more if so. :) |
@donmccurdy Can you please check if reverting #23671 fixes the issue? If so, |
Thanks @Mugen87! Unfortunately I don't see a difference after reverting #23671. The same thing happens in the official TAA example if I add this line: scene.background = new THREE.Color( 0x505050 ); |
Possibly #9051? |
Setting
|
Great to see! Typically transparency-through-noise can be improved with alpha to coverage, have you tried that? Could reduce the noise even more for low-ish AA values. |
@hybridherbst can you explain how alpha to coverage should help here? A2C will only have any affect if MSAA is enabled and the written fragment is partially transparent. It doesn't guarantee correct depth order of fragments as far as I know, either, with or without depth write enabled. Alpha hash or dithered transparency only works because it reliably writes to the depth buffer. @donmccurdy can you explain the value of the of the "alphaHashScale" parameter? I would have expected that it would be possible to hash such that the noise is always 1 px in size. |
@gkjohnson from the paper, emphasis mine —
With TAA, I'm finding 0.1 looks pretty good. This may depend on the number of samples. Without TAA, I also see an improvement when decreasing the scale from 1 to 0.5, but not much change below that — unsure why that would happen. The paper also discusses "Applications to Alpha-to-Coverage" but I haven't gotten into that area yet, it may require more work. I was also hoping to test with |
Hmm, from one of the authors...
https://twitter.com/_cwyman_/status/935743334244605953 I don't think WebGL 1.0 or 2.0 include |
I've filed the issues about TAARenderPass at #24318 — it turns out we can work around them both by using a black scene background and keeping Here's the preview link once again: Visually, this is comparable to Blender, so I probably won't make any further changes here unless we decide to move forward with the feature. If so, some further testing and cleanup would be needed. |
You should have this model to process your branch test. |
991d7c6
to
e3dd77b
Compare
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
Updates on TAARenderPass in #24318 (comment). |
e402e70
to
13f23d0
Compare
I believe this is a useful improvement for the example shared by @sdarpeng as well. The appearance is stable (no sort issues) under different camera angles.
|
I think the example is ideal for demonstrating this technique 👍 . |
I vote to add IMO, TAA should be used for acceptable image quality. But given the manageable amount of changes related to the core, I think it's worth an addition. |
I know it doesn't sound like much, but to me a really compelling use for alpha hash is being able to fade opaque objects in/out while avoiding "inside-out" display... cases like that — where the alpha hashed surface is temporary or small — do not necessarily require TAA. This has come up repeatedly in projects. I'll work on cleaning up the remaining issues here, thanks! |
Yeah, this looks good to me 👍 As per the example, maybe something like this one but every sphere has a different color and alpha |
Material.alphaHash: Add example Clean up. Update builds Examples: Clean up alpha hash params Fix background color changes, add GammaCorrectionShader TAARenderPass: Initialize .accumulateIndex Alpha Hash: Initialize sampleLevel=0 in example Avoids flashing from TAARenderPass Clean up alpha hash example. Lint Update builds Add screenshot
I might shuffle the order of instances to make the problems with alpha blending more obvious from any angle, but yes that sounds fine! If there are no objections, I'd like to remove the |
f354cdd
to
80c40c4
Compare
To simplify things I've removed the demo, and will create a new demo in a separate PR. I've also moved the alphaHash GLSL out of the alphaTest shader chunks, and into its own chunks. Happy to revert that if we'd prefer otherwise. |
PR for the example: |
Greaaaaat Job, guys. |
2023-09-01.12-12-07.mp4The new three.js alphaHash transparency looks fucking good. |
Related issues:
Description:
Proposal for adding
.alphaHash: boolean
and.alphaHashScale: number
properties to all three.js Material types. This is an alternative method of transparency distinct from alpha blending (.transparent=true
) and physically-based transmission (.transmission > 0
), which is not a panacea but has some significant benefits:The major drawback of the method is noise / grain, which can be reduced significantly with appropriate anti-aliasing. With or without AA, alpha hash is a good choice in several use cases:
In these cases a bit of grain might be a reasonable tradeoff to avoid alpha blending issues — particularly if the transparent region is temporary, small, or distant from the camera.
The effect closely resembles Blender's Blend Mode: Alpha Hashed material property. Blender enables multi-sampling by default, which hides most of the grain, but this can be disabled in its renderer settings. The
.alphaHashScale: number
parameter should be used to tune the hash function to fit the multi-sampling method, with values in the range of 0.1–0.5 working well in my tests. When multi-sampling is not used, 1.0 is fine.Questions:
Do we want to supportmaterial.alphaHash
? We could also consider a NodeMaterial-only solution, as a separate node:material.alphaTest = new AlphaHashNode( opacityNode, scale );
TAARenderPass is brightening the scene, and I'm not sure why. I've omitted all color management settings for now, to isolate that underlying problem. Any ideas here? Is this an appropriate type of multi-sampling to be using for this example? /cc @bhoustonSee below.Better example? I used this chloroplast scene from Sketchfab, mainly because it doesn't work well with alpha blending, for any choice of depthWrite.References:
This contribution is funded by The New York Times.