DirectX11 Geom. Shaders, MVP matrix, OVRCameraController?
I'm working on a project that uses compute shaders and geometry shaders to generate procedural geometry at runtime. My material uses a Geometry Shader, and is drawn like so:
When viewing the scene with a regular Unity camera or in the editor during preview, this works great -- I see my procedurally-generated object in the world, and it is positioned correctly. When I move the camera around in the world, the generated object remains in the correct orientation relative to the world.
As soon as I produce a build with the OVRCameraController enabled, things fall apart. It looks like the model-view-projection matrix is rotated incorrectly -- pitching and rolling the HMD seems to cause rolling and pitching of the procedurally-generated object, and I think I'm seeing the back of it rather than the front, based on the little bits of geometry I can see.
Is this a known issue, or is there a known workaround? Only thing I can think of is that the OVRCameraController is generating extra calls to OnRenderObject, or draw calls with Camera.current not set to what I expect..
[edit] Hold up here, I just tried rendering the scene from two views (two Unity cameras with modified viewport rectangles), and that got "interesting" in unpleasant ways. I think I've got a general problem, not an OVR-specific problem..[/edit]
[edit 2] It looks like for some reason the result of DrawProcedural() is being called after the end of the current camera's rendering, so that it ends up with Camera A's MVP matrix being used when DrawProcedural happens for Camera B, and vice versa. If I add a third camera, everything's off-by-one in the same way (A -> B, B->C, C->A). Understandable based on GPU pipelining, but frustrating..[/edit]
void OnRenderObject()
{
if (!enabled)
return;
Matrix4x4 m = transform.localToWorldMatrix;
Matrix4x4 v = Camera.current.worldToCameraMatrix;
Matrix4x4 p = Camera.current.projectionMatrix;
Matrix4x4 MVP = p * v * m;
Graphics.ClearRandomWriteTargets();
proceduralMaterial.SetPass(0);
proceduralMaterial.SetMatrix("ModelViewProjection", MVP);
Graphics.DrawProcedural(MeshTopology.Points, 640 * 480);
Graphics.ClearRandomWriteTargets();
}
When viewing the scene with a regular Unity camera or in the editor during preview, this works great -- I see my procedurally-generated object in the world, and it is positioned correctly. When I move the camera around in the world, the generated object remains in the correct orientation relative to the world.
As soon as I produce a build with the OVRCameraController enabled, things fall apart. It looks like the model-view-projection matrix is rotated incorrectly -- pitching and rolling the HMD seems to cause rolling and pitching of the procedurally-generated object, and I think I'm seeing the back of it rather than the front, based on the little bits of geometry I can see.
Is this a known issue, or is there a known workaround? Only thing I can think of is that the OVRCameraController is generating extra calls to OnRenderObject, or draw calls with Camera.current not set to what I expect..
[edit] Hold up here, I just tried rendering the scene from two views (two Unity cameras with modified viewport rectangles), and that got "interesting" in unpleasant ways. I think I've got a general problem, not an OVR-specific problem..[/edit]
[edit 2] It looks like for some reason the result of DrawProcedural() is being called after the end of the current camera's rendering, so that it ends up with Camera A's MVP matrix being used when DrawProcedural happens for Camera B, and vice versa. If I add a third camera, everything's off-by-one in the same way (A -> B, B->C, C->A). Understandable based on GPU pipelining, but frustrating..[/edit]
