alelievr / HDRP-Custom-Passes

A bunch of custom passes made for HDRP
MIT License
1.25k stars 136 forks source link

Issues with motion vector for camera rotation #41

Closed adepierre closed 7 months ago

adepierre commented 2 years ago

Hello!

I've tried to run the CopyBuffer scene to see how motion vectors work. And there is something weird about them: when the camera is moving (translation), they seem to work correctly, with the objects being kind of visible in the motion vector display (picture 1). However, when the camera is simply looking around (no translation, rotation only), it seems that the objects don't appear (picture 2).

I'm not sure if this is just a misunderstanding of motion vectors from me or a real error, but any info about this matter would help me a lot!

Edit: I tried to copy the render texture to a normal texture in order to inspect the values using the following code, but it seems RGHalf is not the right format. The RenderTextureFormat is 29, which ... doesn't exist in the enum?

RenderTexture.active = motionVectors;
Texture2D tex = new Texture2D(motionVectors.width, motionVectors.height,  TextureFormat.RGHalf, false);
tex.ReadPixels(new Rect(0, 0, motionVectors.width, motionVectors.height), 0, 0);
tex.Apply();
byte[] bytes = tex.EncodeToEXR(Texture2D.EXRFlags.CompressZIP);
System.IO.File.WriteAllBytes(path, bytes);

Camera translation: image

Camera rotation only: image

Unity: 2021.2.16f1 HDRP: 12.1.6

HsiangYangChu commented 2 years ago

Could you provide the complete code?

adepierre commented 2 years ago

What do you mean the complete code? I just ran the CopyBuffer scene from this repo with no modifications.

alelievr commented 1 year ago

I think this is expected, when you rotate the camera it doesn't change the position of objects in the camera relative space so the motion vector is only relative to the rotation of the camera in screen space.

In any case, if you don't have an issue with temporal effects, then it means that the motion vectors are correct, and since this is only a copy it should work as expected.