-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Comments
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. |
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. |
Oh sorry, you are right, it does NOT work in native. Because of Issue #3315: |
Hmm off the top of my head no. Definitely sounds like a hard design problem (but one worth solving). |
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. |
This should be fixed now that we're using the prepass shaders for shadows. |
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
The text was updated successfully, but these errors were encountered: