cancel
Showing results for 
Search instead for 
Did you mean: 

Coin3D Integration - WIP

Afuerg
Level 2
Hi,
I'm trying to get the Rift view working with Coin3D, based on an "old" example by jherico.

Basically I'm building a simple Coin scene with a perspective camera, light and cube that I render with SoSceneManager. Also I replaced the GLFW window with a QGLWidget, but kept the original OpenGL Cube for comparison.

The rendering of the Coin scene happens in renderScene() with
SoSceneManager->setViewportRegion(vpRegion);
SoSceneManager->render(false, false);

In the original example, a shader named Simple.vs/Simple.fs is used to color the sides of the cube and correct its position/rotation for each eye, by calculating the translation*rotation matrix and setting gl_Position to it.

Applying the position manipulation of the shader to the scene didn't work for some reason, so I tried replicating this behavior with Coins camera, by extracting the translation and rotation from the calculated matrix with SbMatrix.getTransform(translation, rotation, scaleFactor, scaleOrientation); and setting
SoPerspectiveCamera->position = translation;
SoPerspectiveCamera->orientation = rotation;

Also I'm setting the heightAngle, aspectRatio, nearDistance and farDistance of the camera, according to the values used in the example.

Unfortunately this doesn't create the results I was hoping for. Coins Cube is too wide apart so the two images won't align properly when viewed through the rift.

Anyway here's some quick & dirty (less quick and more dirty) adaption of Example00.cpp:
http://pastebin.com/tLPeGap2

I'm in no way a Coin expert, so I'm sure that there are many better ways to do this, but I decided to stick closely to an already working example, because I realized from a previous attempt, that debbuging a slightly off view is a nightmare.

Just thought I'd share this with you guys.
12 REPLIES 12

veelo
Level 2
For reference: This is how support was integrated into OpenSceneGraph: https://github.com/bjornblissing/osgoculusviewer

Bastiaan.

Afuerg
Level 2
Here's an example of stereo rendering with the Rift using QML and Qt3D, but I haven't tried it out yet:
https://github.com/dragly/oculusqt3d

Also to make it easier for you guys to try my modifications, I forked/branched the example, cleaned up the code a bit and uploaded it here:
https://github.com/Cherum/OculusRiftInAction/tree/CoinOculus

Use the CoinOculus branch, copy Coin in /libraries/Coin_3.1.3_vs10 and coin3d.dll to build/Debug (sorry, was too lazy to find out how to do this with Cmake) and the example should run.

Afuerg
Level 2
"Afuerg" wrote:
Here's an example of stereo rendering with the Rift using QML and Qt3D, but I haven't tried it out yet:
https://github.com/dragly/oculusqt3d

Started porting it to Windows using CMake so I can try it out, see my fork:
https://github.com/Cherum/oculusqt3d

Still have to fix a "multiple defined symbols" error though.

veelo
Level 2
I am making progress (finally -- after a week of hard work) with rendering a Coin scene for the Rift using the 0.3.1 SDK preview, using SDK rendering. Using the OffscreenRenderer for starters, which does not produce sufficiently high framerates as you mentioned. But getting something rendered at all is promissing.

"Afuerg" wrote:
Also I'm setting the heightAngle, aspectRatio, nearDistance and farDistance of the camera, according to the values used in the example.

Unfortunately this doesn't create the results I was hoping for. Coins Cube is too wide apart so the two images won't align properly when viewed through the rift.


I am seeing these issues as well, and I have an idea why. Coin renders equally much left and right of the line of sight, i.e., the line of sight is in the middle of the rendered texture. However, that is not what the SDK requires. I printed the values of the FoV for left and right eyes, and get

Left UpTan: 1.75 Right UpTan: 1.75
Left DownTan: 1.75 Right DownTan: 1.75
Left LeftTan: 1.725 Right LeftTan: 0.970739
Left RightTan: 0.970739 Right RightTan: 1.725


So the line of sight should not be centered in the texture, but offset towards the nose. I have yet to find out how to adjust the camera appropriately, maybe I will have to subclass the camera. This is accomplished by using a SoFrustumCamera for each eye. Then set the nearDistance to 1.0f and use the above values for the top, bottom, left and right fields. It works 🙂

To increase the frame rates I guess I will have to follow your example, or use Client Distortion with SoSceneTexture2 (although the power-of-two requirement on the texture size may be a problem). Done, the git repository below now works using frame buffer objects.

Bastiaan Veelo.

veelo
Level 2
Have a look at it here: https://github.com/veelo/OculusCoin.

Afuerg
Level 2
Interesting find with the line of sight, I'm going to try out your example as soon as possible. 🙂

Afuerg
Level 2
Unfortunately, your example produces the following output with 0.3.1 and 0.3.2:


The fix from the "Problem with Oculus Rift SDK and OpenGL.." Topic for 0.3.1 does not work for me.

e: Seems to be an issue with my AMD graphic card.

veelo
Level 2
I don't know, I don't have an AMD card, I'm on an Intel HD Graphics 4000, virtualised by Parallels. It does look very similar to the issue you linked to. Maybe a note there asking them to look into this will help?

Do you restore OpenGL state as per viewtopic.php?f=34&t=8159#p112532?

Afuerg
Level 2
Ok the fix from the "Simple OpenGL example with GLFW, GLEW and OculusSDK 0.3.1" thread works, but for some reason not while I used qcreator and qmake for building.
A few hours and a CMakeLists.txt later I can confirm, that we have a working example for 0.3.1! Good job! 😄