bjornblissing / osgoculusviewer

An OsgViewer with support for the Oculus Rift
Other
106 stars 67 forks source link

Render Order applied to wide in 0.6 SDK version and view matrix offsets are negated #66

Closed ChrisDenham closed 9 years ago

ChrisDenham commented 9 years ago

I've just been checking though my changes for MSAA support and noticed that I had to put in a kludge to swap the left and right eye camera transforms. On investigation why that was necessary, it looks to me as though the problem may have arisen in the merging of changes to support Oculus 0.7.0.0 SDK, in 8076d605c3e5b078634fa05f55057c51516ee411 This change removed calls to a function named renderOrder which my guess may have been responsible for swapping the eyes images? I'm not sure, but thought it might be worth raising as a issue as I didn't want to include my kludge for a possible render order issue in my MSAA pull request.

bjornblissing commented 9 years ago

In 0.6.0.1 SDK (and earlier) there was an field in the ovrHmdDesc struct called EyeRenderOrder which contained information on which eye that should be rendered first (According to the header file this was to minimize latency on sideways-scanned screens).

In 0.7.0.0 SDK this field is removed and the render order is hard coded in the examples. The OculusDevice::renderOrder() function was removed due to the fact that Oculus removed this field and the order is now hard coded as in the examples.

This will have no effect on the swapTextures, it only handles in which order the eyes are rendered. Which is done according to the int values inside the enum OculusDevice::Eye, ie left eye first then right.

My guess is that the render order is of little importance (maybe some of the Oculus internal timeWarp code may benefit from having the right order). So the root of your problem probably lies somewhere else.

ChrisDenham commented 9 years ago

Ah, ok, I'll investigate further then. However, I was fairly sure I was getting the same problem with a clean build of your master branch without any of my changes, so I'll check to confirm tomorrow.

ChrisDenham commented 9 years ago

To test the problem I have set the clear color of left camera to red and also increased the eye separation like:

    float worldUnitsPerMetre = 100.0f;
    osg::ref_ptr<OculusDevice> oculusDevice = new OculusDevice(nearClip, farClip, pixelsPerDisplayPixel, worldUnitsPerMetre);
....
    m_cameraRTTLeft = m_device->createRTTCamera(OculusDevice::LEFT, osg::Camera::RELATIVE_RF, osg::Vec4(1,0,0,1), gc);
    m_cameraRTTRight = m_device->createRTTCamera(OculusDevice::RIGHT, osg::Camera::RELATIVE_RF, osg::Vec4(0,0,1,1), gc);

This is what I get after the 0.7.0.0 support was added: image

So, you can see that although the left eye is now correctly rendering with the red background, it would appear to have the right eye's transform. Prior to the 0.7.0.0 support being added, it would seem that incorrect transforms were cancelled out because the left camera was being rendered to the right eye, like so: image

ChrisDenham commented 9 years ago

Ouch... it just occurred to me the consequences of this bug for users with asymmetrical eye offsets configured. Presumably the eye offsets configured in the Oculus Configuration Utility would also have swapped, which could have explained at least some of my headaches. lol.

bjornblissing commented 9 years ago

So this is actually two errors.

First the result from the renderOrder() is applied way to wide. It should only be applied to the camera::setRenderOrder() function. Otherwise we need to setup our textures differently.

Secondly the view matrix offsets should be negated to give the correct result.

ChrisDenham commented 9 years ago

Yeah, interestingly, two errors that very nearly cancelled each other out prior to the 0,7.0.0 changes. :-)