Implement motion vectors in compatibility renderer#97151
Implement motion vectors in compatibility renderer#97151Repiteo merged 1 commit intogodotengine:masterfrom
Conversation
Yes, motion vectors should be a specialization for now. Then the version will only be compiled when it is actually used.
Not from scene.glsl, no. We will have to do something in the actual particle system. I think that we handled this case already in the RD renderers. Most likely we will need to duplicate the particle buffer to effectively clear the history
I can't think of any reason why one struct would work but not another. We should try to get it working though as the bool will likely create a dynamic branch which we really don't want |
modules/openxr/extensions/openxr_fb_space_warp_extension_wrapper.cpp
Outdated
Show resolved
Hide resolved
174904d to
6af033e
Compare
6af033e to
65211d2
Compare
modules/openxr/extensions/openxr_fb_space_warp_extension_wrapper.cpp
Outdated
Show resolved
Hide resolved
258736c to
c554b2d
Compare
69daeba to
a52b386
Compare
dsnopek
left a comment
There was a problem hiding this comment.
Thanks! This is looking really great to me :-)
I'm going to test the latest version soon, but in the meantime, I have some notes on the public APIs this adds. Some of this will need discussion with the rest of the XR team.
|
Doing some testing with AppSW via GodotVR/godot_openxr_vendors#222, I'm getting this message spammed to logs: I don't see why we should be seeing this unhandled type, I think this is meant to be something that the application logs via OpenGL? And I don't think Godot is doing it. Maybe it's something from the OpenXR runtime? But just this getting sent to the log so often is going to have a negative affect on performance. One option could be updating These appear to be the types we're not handling: |
|
@dsnopek it's of type "Marker" and severity "Notification", I noticed this recently and added the code to make it actually share the log and this is what it shared: Edit: It logged this as well I can add the code to this PR so that its actually logged like above, but yes I'm thinking I'll have to figure out whats causing this and try to stop it. Since it's Marker/Notification I'm assuming what causes this is not actually a problem, but the log itself would be an issue. |
|
@devloglogan @dsnopek I've seen those errors for some time now, even before we added support for OpenXR debug logging (which is turned off by default anyway). |
1f0f05b to
a50a1ee
Compare
|
I'm opening this PR since the XR_FB_space_warp code has been removed and it's in a now arguably merge-able state. :) |
9c55ebe to
8e6efb8
Compare
|
#100282 has been merged, so I'm reopening this PR. :) |
dsnopek
left a comment
There was a problem hiding this comment.
I just retested with the latest version of this PR and GodotVR/godot_openxr_vendors#222 (spacewarp) on the Quest 3, and it's still working as expected!
Skimming through the code, everything seems about the same as the last time I reviewed, and it looks good to me :-)
42d6d66 to
cd78ebd
Compare
|
super excited for this! great work all |
cd78ebd to
14b66c8
Compare
77a1fc5 to
0eb881b
Compare
0eb881b to
8fef9a6
Compare
BastiaanOlij
left a comment
There was a problem hiding this comment.
I'm willing to approve this as is. Tested this on a PICO 4 Ultra with frame synthesis enabled and works great.
Looking at the code, it looks bigger than it really is due to some of the renames (mostly ubo->data), and there are a few changes around multiview that make sense, but make it a little harder to immediately understand whats going on.
But its much less intrusive than I initially thought, if you take away the renames the additions for motion vectors pretty much stand on their own, and as there is a lot of overlap between how motion vectors work in the RendererRD renderer, it should match expectations from anyone having to deal with the code.
|
Thanks! |
|
I've encountered a null pointer exception here with some scenes: godot/drivers/gles3/rasterizer_scene_gles3.cpp Line 2498 in 06827c9 fix with |
|
@huwpascoe thanks for sharing! It looks like this is caused by reflection probes. I've opened #111260 which should fix it. |

This PR implements motion vectors in the compatibility renderer, primarily for use with the
XR_FB_space_warpOpenXR extension.For testing purposes, this PR currently implements this extension as well. Eventually this logic will be handled via GDExtension in godot_openxr_vendors. This PR will remain as a draft until that's the case.Edit: Space warp functionality has been relocated to GodotVR/godot_openxr_vendors#222.
Technical details
I've tried to emulate how motion vectors are implemented in the Forward+ renderer where possible, but it's worth noting that space warp requires 3D motion vectors. Whereas the Forward+ renderer is rendering 2D motion vectors for TAA.
Motion vectors are rendered in a new, separate render pass. Why this was done:
XR_META_recommended_layer_resolutionOpenXR extension, since all attachments would then have to be of the same resolution.The vertex shader code in
scene.glslhas been placed in a newvertex_shader()function. When motion vectors are used, it will run the vertex shader on both previous and current vertex data. The scene state data and multiview data have been duplicated to hold the previous frame’s data. The vertex shader outputs both the previous and current clip positions, which are used to calculate motion vectors in the fragment shader.For skeletons,
GLES::MeshInstance::Surfacenow stores two vertex buffers, generating the second one on demand when motion vectors are enabled. The VBOs will alternate between current/previous, and the previous VBO is used to populate newscene.glslvertex attribs at locations 16/17.Similarly, for multimeshes/particles,
GLES::MultiMeshnow also stores two vertex buffers with the secondary one generated on demand. Newscene.glslvertex attribs (location 18 to 21) store the previous data, and the setup for both the current/previous vertex attribs is now done in a newGLES3::MeshStorage::multimesh_vertex_attrib_setup()function.Issues that need to be addressed
There are a couple things that need to be ironed out that I would really appreciate some input on from those who have a bit more rendering know how.
This implementation of motion vectors requires the GPU to have a max vertex attribute value of at least 22. This requirement is met on Quest hardware (or any other headset which uses the Qualcomm XR-series chips), and we check it before running the motion vector pass. But when opening the editor on desktop some errors might be thrown fromShaderGLES3::_initialize_version(), which attempts to compile all shader variants at startup, including the motion vector variant of scene.glsl. What is the best way to prevent it from compiling this variant if there aren’t enough vertex attributes?In non-one-shot particle systems, it's possible for a particle instance to go from the end of its lifetime one frame to the beginning of its lifetime the next frame. At the moment this causes an undesired result on the motion vector texture (we should draw nothing for the particle on these frames). Is there a way we can determine if this is the case inscene.glsl?As mentioned above the vertex shader inscene.glslhas moved into a newvertex_shader()function. For multiview data, I'm currently passing in a boolean value indicating whether to usemultiview_data_block.prev_dataormultiview_data_block.data. I'd rather just pass in theMultiviewDatastructs themselves rather than the boolean, similar to how the SceneData structs are passed in. However, doing this seems to cause anything using multiview data to just not be rendered. What I have in the PR works, so maybe it's not a big deal, but if anybody has ideas on how to fix this I'd appreciate it!UPDATED (2024-10-28): I believe all of the areas of concern have been addressed. While technically the second point regarding particle systems still exists, I don't think this is something that needs to be addressed in this PR. Beyond just particles, there should be a way to exclude objects from being drawn to motion vectors (Ex: when an object is teleporting rather than moving smoothly). This is something the current Vulkan motion vectors implementation could benefit from. I think a fix for this warrants its own PR.
Contributed with ❤️ by W4Games