bevy_pbr: Reuse the mesh.wgsl vertex stage for shadow mapping and remove depth.wgsl#4303
bevy_pbr: Reuse the mesh.wgsl vertex stage for shadow mapping and remove depth.wgsl#4303superdump wants to merge 2 commits intobevyengine:mainfrom
Conversation
…ain passes Use the SHADOW_MAPPING shader def for shadow mapping passes.
| shader: MESH_SHADER_HANDLE.typed::<Shader>(), | ||
| entry_point: "vertex".into(), | ||
| shader_defs: vec![], | ||
| shader_defs: vec!["SHADOW_MAPPING".to_string()], |
There was a problem hiding this comment.
For this to be correct in the general case, we need to inherit the shaderdefs of the specialized mesh pipeline in addition to this one.
There was a problem hiding this comment.
The point was that with SHADOW_MAPPING defined, only code that is either without any other shader defs or that has shader defs that are configured for shadow passes are included.
There was a problem hiding this comment.
That is a ‘by convention’ maintenance burden, but I think it’s pretty manageable because so little is needed for shadow mapping. Just clip position.
There was a problem hiding this comment.
I guess your comment was about, for example, VERTEX_TANGENTS. My point is that if SHADOW_MAPPING is set, no other shader defs are part of what remains.
There was a problem hiding this comment.
This is likely going to be needed when we merge in skinning and morph target support. Where they are needed in the shadow vertex shader to be correct. Any other user made specialized define would also likely need to be reflected here too.
There was a problem hiding this comment.
Yeah, I realised what you meant when I looked over the mesh skinning PR last night. I'll have to figure out how to hook that up then.
|
I'm going to close this because I want to move in the opposite direction to a more specialised depth pass. The problem with reusing the mesh vertex stage is that it needs to load all vertex attributes. For non-animated geometry for depth-only passes, only the position attribute is needed. I have learned since making this PR that it is a good idea to have separate vertex buffers for the position attribute and for everything else so that depth passes do not even read the unused vertex attribute data, have better cache usage, and improve performance. |
Objective
depth.wgslis 'missed'Solution
Viewstruct out ofmesh_view_bind_group.wgslintoview_struct.wgsland define thebevy_pbr::view_structimport. Import this intomesh_view_bind_group.wgslas it is used there for bindings.depth.wgsland reworkmesh.wgslto reproduce the same vertex stage by excluding unneeded code with the help of aSHADOW_MAPPINGshader defChangelog
Migration Guide
MESH_SHADER_HANDLEwith theSHADOW_MAPPINGshader def for the vertex stage of shadow mapping passes instead ofSHADOW_SHADER_HANDLE