Get access to SkinnedMeshRenderers prev-vert-pos?

Unity docs say skinning is double-buffered mesh verts.
So how do I get access to the last-frames verts in a shader?

This doesn’t work for example. So in what buffer or buffer-stream are these stored?

float3 positionOS_Last : POSITION1;

TEXCOORD4

Are those stored in “float3”? I’m not getting expected results.

In my custom SRP with “context.DrawRenderers” I’m setting “drawSettings.perObjectData = PerObjectData.MotionVectors;”. I’m not sure if this matters or if some other setting is needed for it to generate these correctly in the SkinnedMeshRenderer.

Here are the last positions represented as RGB (I don’t see any blue values [aka Z])

If I subtract the “current (POSITION) & last-position (TEXCOORD4)” from one another I would expect everything to be at zero for the most part but as you can see in this image the last-position data is wrong.

Yes, it’s a float3. Those however look like standard UVs.

For the built in renderer, skinnedMotionVectors needed to be enabled on the SkinnedMeshRenderer component itself for them to show up. I assume the same is true for the SRPs, but I have little experience with those. However once skinnedMotionVectors was enabled, TEXCOORD4 was filled with the previous frame’s object space position regardless of if motion vectors were enabled on the camera or used elsewhere.

I will hunt more though the URP to see if I can find whats missing but its got to be something simple.

There is probably some ScriptableRenderContext.DrawRenderers setting that needs to be on for this but I don’t see anything in more than “PerObjectData.MotionVectors” thats relevent. Really wish there were better docs on something so fundamental to the system.

Looks like I’m not the only one with this issue since 2018: Get skinned mesh's previous frame vertex position in Shader

Ok figured it out. Because a custom SRP doesn’t expose the “depthTextureMode” property on the camera for some reason. In the SRP I just set it “camera.depthTextureMode = DepthTextureMode.MotionVectors;” Then invoke “ScriptableRenderContext.DrawRenderers” with “DrawingSettings.perObjectData = PerObjectData.MotionVectors”

Now skinned last-pose “float3 positionOS_Last : TEXCOORD4” and “float4x4 unity_MatrixPreviousM”, “float4 unity_MotionVectorsParams” seems to be coming through correctly. As I figured, something super simple.

And motion blur works. Thanks for the initial tip. Was able to find the rest of what I needed from that.

I’d like to ask that , how to enable skinnedMotionVectors option in URP editor.

LTS 2020.3.32f1, lastPos at TEXCOORD4 can be accessed only when the camera MotionVectors is on. I tried On/Off in both runtime and editor. There should be an option to last access this lastPos without having to use the texture.

7996689--1027881--upload_2022-3-26_20-7-33.png
Would be fun for these kind of cheap, vertex manipulation effects :slight_smile: