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

Alpha mask shadow mapping - if there isn't one #4576

Closed
DerKarlos opened this issue Apr 24, 2022 · 7 comments
Closed

Alpha mask shadow mapping - if there isn't one #4576

DerKarlos opened this issue Apr 24, 2022 · 7 comments
Labels
A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible

Comments

@DerKarlos
Copy link

What problem does this solve or what need does it fill?

If there is a Mesh with a StandardMaterial with base_color_texture and alpha_mode: Mask(0.5)
Native build works fine. In Web/WASM, the shadows are not partly transparent.

What solution would you like?

Transparent shadows are needed to have the same rendering native and web

What alternative(s) have you considered?

May be using plain wgpu could do it?

Additional context

Here you may se what I do:
https://github.com/DerKarlos/OSMeta/blob/87c096780bfa35f4b3730194b302577b47f8d4d2/src/main.rs

Screenshot

@DerKarlos DerKarlos added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Apr 24, 2022
@superdump superdump added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Apr 24, 2022
@superdump
Copy link
Contributor

The way this should work is that there is a shadow pipeline for alpha mode mask materials that has a fragment stage that evaluates the fragment's alpha, compares it to the alpha mask threshold, and discard the fragment if the fragment alpha is below the threshold. This needs a separate render phase for those meshes (similar to AlphaMask3d), separate draw function in order to bind the material bindings, and a clear story for how to do this for specialised materials where it would likely be necessary to always specialise the shadow alpha mask fragment shader as well as the main pass fragment shader, whenever you have alpha mask meshes.

This seems quite tricky to solve in a generic way. @cart - do you have any ideas about how to support this and have it all be ergonomic?

I think the fragment shader for 'standard material' would need to support a vertex colours, a flat material colour, and a colour texture but it doesn't need other bindings. Custom materials could need all sorts of bindings to define the alpha (noise textures and whatever). I think then it would be necessary to be able to override and provide a material bind group (and layout) for alpha mask shadows, and the full alpha mask shadow fragment shader.

@superdump superdump moved this to Todo in Rendering Apr 24, 2022
@DerKarlos
Copy link
Author

Sounds complicated; it's far above my knowledge. I just wonder: native and web it's the same hardware and firmware. I assumed wgpu cares for the different GPU-APIs but uses the same "logic" and offers the same rendering. May be in wgpu, the web part is less implemented in wgpu, yet? Or is it all done and different in bevy?

@superdump
Copy link
Contributor

Sounds complicated; it's far above my knowledge. I just wonder: native and web it's the same hardware and firmware. I assumed wgpu cares for the different GPU-APIs but uses the same "logic" and offers the same rendering. May be in wgpu, the web part is less implemented in wgpu, yet? Or is it all done and different in bevy?

You’re saying this works properly on native but not on web? In theory, running on the web should work about the same as native. When I tried native earlier it was showing the full quads as shadow, and it makes sense that it would.

@DerKarlos
Copy link
Author

Oh sorry, you are right, it does NOT work in native. Because of Issue #3315:
"macOS intel with integrated gpu - strange shadows artifacts", I misinterpreted the native.

@cart
Copy link
Member

cart commented May 26, 2022

This seems quite tricky to solve in a generic way. @cart - do you have any ideas about how to support this and have it all be ergonomic?

Hmm off the top of my head no. Definitely sounds like a hard design problem (but one worth solving).

@superdump
Copy link
Contributor

I guess alpha mask is perhaps not the primary, common case for opaque so maybe having optional specialisation and doing the wrong thing by default, but implementing it the right way for standard material is a good start.

I haven’t looked at how to do this for transparent materials. I think I saw something where you use alpha to adjust the ‘intensity’ of the shadow and the colour of the occluder to tint the shadow colour, but that required storing and looking up the material of the occluder for transparent materials and it sounded like it only supported one occluder unless you do some… I think the term is depth peeling (?) though I’m guessing at what that term means but I’m assuming here that it means to store multiple depth values of surfaces along a ray to enable look up of multiple if desired. In this case it would also be material properties at those surfaces. So lots of data used to do it. Naively, supporting just one surface without alpha/tinting it’s maybe something to consider. I’d have to see what other engines do I guess to see if it’s worth it. The main more advanced case I’m thinking of is maybe there was some stuff in the light colour puzzles in The Witness.

@james7132
Copy link
Member

This should be fixed now that we're using the prepass shaders for shadows.

@github-project-automation github-project-automation bot moved this from Todo to Done in Rendering Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible
Projects
Status: Done
Development

No branches or pull requests

4 participants