-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
Add Shadows for Transparent Objects #15999
base: dev
Are you sure you want to change the base?
Conversation
…dows # Conflicts: # src/renderers/webgl/WebGLShadowMap.js
I just resolved the conflicts and made a few updates including using an 8x8 dither pattern as Babylon used. The example on another branch from the original post has been updated, as well, with a larger shadow map (2048 x 2048). Right now shadow transparency is universally toggled with And cc @donmccurdy -- you've mentioned an interest in introducing alpha hashing previously and this may be a start. The approach used here for shadows is just a 2d pattern seeded by screen space position so it's consistent but there could be other options in the future. For shadows, at least, using an alpha hash approach like you mention here might be noisier (even if it doesn't change per frame thought it might not be so noticeable) but would allow shadows of overlapping objects with the same alpha to to get darker: |
For alpha hash we'd probably want texture-space or object-space coordinates, but no matter here. I do see pretty noticeable banding though, viewed from an angle. ... and I'm wondering if a small blue noise texture would do better? We can figure out how to embed it in the source code as a Uint8Array or Data URI if it gives good results. |
Yeah I've taken a look at that presentation -- it is a slightly different technique but we could provide options to use various clipping approaches for transparency. Alpha hashing does look really noisy, though. Is it often used without some kind of temporal accumulation like TRAA? Regarding the banding, though, I'm not sure if there's a great way to avoid a pattern here -- here's what the shadows would look like with blue noise (I've written a blue noise generator here): And here's the same demo with a 4x4 bayer pattern: https://raw.githack.com/gkjohnson/threejs-sandbox/master/screendoor-transparency/index.html I'm not sure if I feel it's a lot better. |
I don't think it needs to be (example: https://twitter.com/thespite/status/1221532206562258945), but, yeah there's certainly a grain. For alpha hashing (or even just starting with alpha dither, no per-object hash) I think I'd prefer a noise pattern to a screen grid. But for the shadows, agreed, the Bayer pattern appears to be working better. Tweaking the shadow radius seems to hide the banding, depending on the angle etc., that could work for now. 👍 |
"mrdoob modified the milestones: r123, r124 23 minutes ago" :( |
@LinoPhil The milestone modification happens automatically when the assigned milestone is released and the PR is still open. |
@Mugen87 ok, but the feature itself, you are not satisfied with the quality or is it breaking something? The demos look promising to me and im looking forward to use it in our viewer. |
@LinoPhil Sorry, there was just no opportunity to deeply review this PR so far. There are so many of them (with different priorities and complexities) and time is unfortunately limited. |
Just want to give a push. Maybe after 3 years (initial ticket 10600) its time to finish? |
Looks like this feature has been added into react-three-fiber's Drei based on this PR. It was also added into Babylon (also based on my original sandbox example 😅) and Playcanvas, as well. |
Yes, we should rebase and merge the PR! |
depthPacking: RGBADepthPacking, | ||
ditherTransparency: true | ||
} ), | ||
_ditheredDistanceMaterial = new MeshDepthMaterial( { ditherTransparency: true } ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be MeshDistanceMaterial
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reviewed the PR today and apart from the above tiny issue, the code looks good 👍 !
A bit that is missing are updates to the program cache key computation which was differently implemented in 2019. During rebase, ditherTransparency
needs to be added to the getProgramCacheKeyBooleans()
function.
we have same issue when rendering hair(transparent texturing) shadow, looking forward to get this feature in next release, thanks for the good work. |
A first pass at shadows for transparent objects as discussed in #10600.
I've modified an example here on another branch so you can see how the shadows are affected and the artifacts associated with this technique:
As I mentioned before the artifacts are pretty apparent but can be hidden a bit by setting the shadow radius to a good value. There may be some other shadow sampling techniques that can better hide the dither pattern.