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

Add Shadows for Transparent Objects #15999

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from

Conversation

gkjohnson
Copy link
Collaborator

@gkjohnson gkjohnson commented Mar 16, 2019

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:

image

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.

Repository owner deleted a comment from makc Jul 31, 2020
@mrdoob mrdoob added this to the r123 milestone Nov 10, 2020
@gkjohnson
Copy link
Collaborator Author

gkjohnson commented Nov 10, 2020

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 renderer.shadow.dithering (like you mentioned in #10600 (comment)) but it could be set per light -- perhaps that's a better place for it? It would be nice to move most / all shadowmap flags to the lights if possible I think.

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:

image

@donmccurdy
Copy link
Collaborator

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.

Screen Shot 2020-11-12 at 8 28 48 PM

... 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.

@gkjohnson
Copy link
Collaborator Author

For alpha hash we'd probably want texture-space or object-space coordinates, but no matter here

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):

https://raw.githack.com/gkjohnson/threejs-sandbox/bluenoise-shadows/screendoor-transparency/index.html

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.

@donmccurdy
Copy link
Collaborator

Alpha hashing does look really noisy, though. Is it often used without some kind of temporal accumulation like TRAA?

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 mrdoob modified the milestones: r123, r124 Nov 25, 2020
@LinoPhil
Copy link

"mrdoob modified the milestones: r123, r124 23 minutes ago" :(
Why ?

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 25, 2020

@LinoPhil The milestone modification happens automatically when the assigned milestone is released and the PR is still open.

@LinoPhil
Copy link

@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.

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 25, 2020

@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.

@mrdoob mrdoob modified the milestones: r124, r125 Dec 24, 2020
@mrdoob mrdoob modified the milestones: r125, r126 Jan 27, 2021
@mrdoob mrdoob modified the milestones: r126, r127 Feb 23, 2021
@LinoPhil
Copy link

LinoPhil commented Mar 4, 2021

Just want to give a push. Maybe after 3 years (initial ticket 10600) its time to finish?

@mrdoob mrdoob removed this from the r127 milestone Mar 30, 2021
@mrdoob mrdoob added this to the r159 milestone Oct 27, 2023
@mrdoob mrdoob modified the milestones: r159, r160 Nov 30, 2023
@mrdoob mrdoob modified the milestones: r160, r161 Dec 22, 2023
@gkjohnson
Copy link
Collaborator Author

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.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 6, 2024

Yes, we should rebase and merge the PR!

depthPacking: RGBADepthPacking,
ditherTransparency: true
} ),
_ditheredDistanceMaterial = new MeshDepthMaterial( { ditherTransparency: true } ),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be MeshDistanceMaterial.

Copy link
Collaborator

@Mugen87 Mugen87 Jan 6, 2024

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.

@iefreer
Copy link
Contributor

iefreer commented Jan 15, 2024

we have same issue when rendering hair(transparent texturing) shadow, looking forward to get this feature in next release, thanks for the good work.

@mrdoob mrdoob modified the milestones: r161, r162 Jan 31, 2024
@mrdoob mrdoob modified the milestones: r162, r163 Feb 29, 2024
@mrdoob mrdoob modified the milestones: r163, r164 Mar 29, 2024
@mrdoob mrdoob modified the milestones: r164, r165 Apr 25, 2024
@mrdoob mrdoob modified the milestones: r165, r166 May 31, 2024
@mrdoob mrdoob modified the milestones: r166, r167 Jun 28, 2024
@mrdoob mrdoob modified the milestones: r167, r168 Jul 25, 2024
@mrdoob mrdoob modified the milestones: r168, r169 Aug 30, 2024
@mrdoob mrdoob modified the milestones: r169, r170 Sep 26, 2024
@mrdoob mrdoob modified the milestones: r170, r171 Oct 31, 2024
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.

7 participants