Allow external motion vector injection into prepass textures#22723
Allow external motion vector injection into prepass textures#22723kurtkuehnert wants to merge 2 commits into
Conversation
|
I don't love this solution :/. Do you need to use the view bind group? Can you just bind the view yourself? Or I guess you want to bind all the view-space lighting data still? |
Yeah I totally agree. This is not the optimal solution, but it is minimal in scope and gets the job done (for my use case at least). Now the problem is, that rendering the terrain twice (prepass and main pass) is too expensive, so I can only run it once. I still want to integrate with lighting, etc. The other solution would be to create a separate TerrainViewBindGroup, which just omits the prepass textures (binding 20-24 if I remember correctly. Unfortunately this is not currently possible, since not all parts in prepare_mesh_view_bind_groups are public (most are). bevy/crates/bevy_pbr/src/render/mesh_view_bindings.rs Lines 579 to 917 in 419f25d Keeping them both in sync would be a hassle, but could work. Do you prefer this approach? Fortunately I can currently hack around this limitation by just using a fullscreen pass to copy the motion vectors, but that is also far from ideal. |
Objective
Enable external passes to populate prepass motion vectors and normals by allowing copies into prepass textures and exposing a way to suppress the prepass clear when data is written earlier in the frame.
Motivation
Some pipelines need to produce motion vectors (for TAA) and normals outside the prepass. For example, a terrain pass renders once before everything else, and its depth/motion data should feed the prepass outputs without re‑rendering the terrain. Because prepass textures are already bound in the view bind group, they can’t be simultaneously bound as render attachments, so direct rendering into them isn’t possible. The practical workaround is to render into separate textures and copy over before the prepass. This PR makes that viable by allowing COPY_DST usage and by letting callers mark the prepass motion vector/normal attachments as already cleared to avoid the prepass overwriting externally provided data.
This isn’t a perfect solution, but the pattern is rare and the change is minimal and non‑invasive compared to alternatives like removing prepass textures from the view bindings or building a custom view bind group.