Oculus Rift DK2 Support - Extended mode only

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
Germanunkol
Halfling
Posts: 87
Joined: Mon Oct 11, 2010 6:39 pm
x 12

Oculus Rift DK2 Support - Extended mode only

Post by Germanunkol »

Hi everyone,

While Kojak is working on a proper solution, I have decided to go ahead and write my own, simplified version for using the Oculus Rift DK2 with Ogre, because I needed it now.
My version only works with the extended mode (Oculus Rift screen set up to extend your desktop, like a normal second monitor would), not with the direct mode.

Features
  • Headtracking (Position and Orientation)
  • Distortion Rendering, including chromatic dispersion compensation
  • Very simple to set up
  • Rotates the view in case you can't rotate it in your windows settings.
Note: As mentioned, this is kept very simple. I will probably not add the Time Warp to it, as that requires more changes in the render loop, and I don't need it for my current project (my framerate is high enough as it is). However, I'll gladly accept changes and pull requests, if someone wants to add it.

Get the code from github.

Image

You can use this in any projects (I'll add a permissive license later on today). It'd be cool if you let me know about your project, though.

Cheers,
Germanunkol

Update:

With the new Oculus Rift SDK 0.4.3, this also works with Linux! (Tested on Ubuntu 14.04)
Last edited by Germanunkol on Tue Nov 04, 2014 9:41 pm, edited 1 time in total.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Oculus Rift DK2 Support - Extended mode only

Post by Kojack »

Cool!
User avatar
cybereality
Hobgoblin
Posts: 563
Joined: Wed Jul 12, 2006 5:40 pm
x 12

Re: Oculus Rift DK2 Support - Extended mode only

Post by cybereality »

Nice job.
Germanunkol
Halfling
Posts: 87
Joined: Mon Oct 11, 2010 6:39 pm
x 12

Re: Oculus Rift DK2 Support - Extended mode only

Post by Germanunkol »

Thanks guys!

Update: Added vignette effect and license. Should now be ready for use, as long as you don't need the time warp effekt. It works well in my project.
asdfqwertz
Gnoblar
Posts: 2
Joined: Fri Oct 31, 2014 3:25 pm

Re: Oculus Rift DK2 Support - Extended mode only

Post by asdfqwertz »

Hi,

first thanks for your work on Ogre DK2 support.

I have a project which works fine on DK1 but now i want to use DK2. So I took code from you and applied it to mine.

Everything works without errors, but the result looks weird, as you can see in the screenshot attached.
There are some image errors occuring at the image's borders. For example (marked with the red arrows) parts of the picture are reflected to the top border and vice versa...
Maybe some shader problems?

I am working a couple of days on this topic now and I have no idea how to fix it. So if you some ideas what the problem could be I would be really thankful!
Cheers!
Attachments
screenshot.JPG
Germanunkol
Halfling
Posts: 87
Joined: Mon Oct 11, 2010 6:39 pm
x 12

Re: Oculus Rift DK2 Support - Extended mode only

Post by Germanunkol »

Hi,

I suddenly had the same problem, but only when working on Linux with SDK 0.4.3 (on windows, it worked fine with SDK 0.4.2).

I will have a look in the next few days (no time today), but it might be that the SDK 0.4.3 gives me different coordinates for the mesh... at least that's what it looks like.
Could you test on windows with SDK 0.4.2?
asdfqwertz
Gnoblar
Posts: 2
Joined: Fri Oct 31, 2014 3:25 pm

Re: Oculus Rift DK2 Support - Extended mode only

Post by asdfqwertz »

Hi,

it works fine with SDK 0.4.2. on Windows!

Thank you!
Germanunkol
Halfling
Posts: 87
Joined: Mon Oct 11, 2010 6:39 pm
x 12

Re: Oculus Rift DK2 Support - Extended mode only

Post by Germanunkol »

You're welcome!
I fixed it for SDK 0.4.3. The vignette is now displayed correct. It seems that Oculus has introduced a bug there... the vignette in 0.4.3 is wrong (too large).
Anyway, the github repo has been updated. This new commit should work with 0.4.3, and with Linux, too! :)

Edit: Yupp, tested with Ubuntu 14.04 - it works! :)
mschoeffler
Gnoblar
Posts: 3
Joined: Sun Nov 23, 2014 9:15 pm
Location: Germany
Contact:

Re: Oculus Rift DK2 Support - Extended mode only

Post by mschoeffler »

Germanunkol, thanks for sharing your code! Does your example smoothly run on your pc?

I'm currently facing the problem that I get a strong jitter effect when running your demo. My first thought was that I have one of the very common problems that, e.g., the Rift has the wrong refresh rate in extended mode or my graphics card does not deliver enough frames per second etc. However, I ran your demo on different systems (ranging from mobile graphics cards to high-end graphics cards etc.) and I never managed to get an acceptable "smoothness".

When I compare your demo with the "official" Demo Scene (the one shipped with the runtime executables), then the strong jitter effect becomes very obvious (before even I did not really notice).
Among other things, I also tried the OculusWorldDemo and the OculusRoomTiny (shipped with the SDK) in extended mode (with DirectX and OpenGL) which work also fine. That is why I'm thinking the current status of your demo must be the main reason for the jitter effects.

I'm fully aware that your demo does not target to be the very-low-latency and perfect solution since e.g. time-warping is missing. Nevertheless, I did not expect the jitter effect to turn out that annoying in comparison to the official samples ;) So I'm very interested whether someone has the same problems? :)
Germanunkol
Halfling
Posts: 87
Joined: Mon Oct 11, 2010 6:39 pm
x 12

Re: Oculus Rift DK2 Support - Extended mode only

Post by Germanunkol »

Hi, thanks for the feedback!

That's very interesting - I don't notice any strong jitter on the PCs I use. If you have a PC with multiple graphics chips, can you make sure you're running the demo with the dedicated one? (Although you mention it happens on multiple devices - so this will likely not be the issue).

Also, make sure to build in release mode, not in debug mode. Debug will be much slower.

I will try to add a framerate display towards the end of this week. Then we can compare framerates and rule that out as an issue.

Another thing you could try is is to animate one of the boxes - then see if just the head movement is slow or if the box update jitters as well, when you don't move the head.

What system are you running on? What OS, which hardware setups?
mschoeffler
Gnoblar
Posts: 3
Joined: Sun Nov 23, 2014 9:15 pm
Location: Germany
Contact:

Re: Oculus Rift DK2 Support - Extended mode only

Post by mschoeffler »

Germanunkol wrote: That's very interesting - I don't notice any strong jitter on the PCs I use.
ok, that's good to know and a good start! :) I will recheck my systems, tomorrow.
Germanunkol wrote: If you have a PC with multiple graphics chips, can you make sure you're running the demo with the dedicated one?
Yes, I can make sure of that. I tried different systems including systems with only one graphics card and I had also an eye on the graphics card which was used (in case of multiple graphics chips).
Germanunkol wrote: Also, make sure to build in release mode, not in debug mode. Debug will be much slower.
Yes, I took this into account. I tested also the release build on every system.

Germanunkol wrote: I will try to add a framerate display towards the end of this week. Then we can compare framerates and rule that out as an issue.
I added a framerate counter. With the system I'm currently using, I achieve a framerate of ~400fps (GeForce GTX 560 Ti) when running in release build.
Germanunkol wrote: Another thing you could try is is to animate one of the boxes - then see if just the head movement is slow or if the box update jitters as well, when you don't move the head.
Good idea, I just tried that and rotating the boxes looks fine... no jitter effect. Yesterday, I added some code to automatically move the camera and this looked also fine (in contrast to me... I felt a bit cybersick afterwards ;)).
Germanunkol wrote: What system are you running on? What OS, which hardware setups?
I tried only Windows 7.

Unfortunately, I did not have enough time today to test the different systems again. I will do some rechecks tomorrow and provide you with the detailed results (fps, gpu type,....). But thank you very much for your input!
mschoeffler
Gnoblar
Posts: 3
Joined: Sun Nov 23, 2014 9:15 pm
Location: Germany
Contact:

Re: Oculus Rift DK2 Support - Extended mode only

Post by mschoeffler »

Long story short, today, we rechecked everything and it turned out that we had a problem with the Windows monitor settings (refresh rate of the Rift display got messed up). Your demo works fine now :)
Germanunkol
Halfling
Posts: 87
Joined: Mon Oct 11, 2010 6:39 pm
x 12

Re: Oculus Rift DK2 Support - Extended mode only

Post by Germanunkol »

Haha, that's funny - I just came here to post that I now have a speed issue as well - on Linux, though.
But it doesn't really "jitter" here... I think somehow the orientation update is just a little slower on my Ubuntu, mabye because of the system setup.

Great to hear you got it solved!
Mozg90
Gnoblar
Posts: 4
Joined: Tue May 14, 2013 8:31 am

Re: Oculus Rift DK2 Support - Extended mode only

Post by Mozg90 »

Hi Germanunkol! I use your code sample in my project, but FSAA did not work. Do you know anything about that problem?
Germanunkol
Halfling
Posts: 87
Joined: Mon Oct 11, 2010 6:39 pm
x 12

Re: Oculus Rift DK2 Support - Extended mode only

Post by Germanunkol »

Hi,

Sorry, I haven't tried to use FSAA yet.
Can you tell me more about how you're trying to implement it? After rendering the entire scene?
Or when rendering to the textures? For that latter option, maybe this post helps: http://www.ogre3d.org/forums/viewtopic.php?f=2&t=38025 ?
Have you tried the texutre's setFSAA?
Mozg90
Gnoblar
Posts: 4
Joined: Tue May 14, 2013 8:31 am

Re: Oculus Rift DK2 Support - Extended mode only

Post by Mozg90 »

Yeah, i found solution - just add parametr to constructor RenderTexture:

Code: Select all

const int FSAALevel = 4;
mLeftEyeRenderTexture = Ogre::TextureManager::getSingleton().createManual(
	"RiftRenderTextureLeft", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
	Ogre::TEX_TYPE_2D, recommendedTex0Size.w, recommendedTex0Size.h, 0, Ogre::PF_R8G8B8,
	Ogre::TU_RENDERTARGET, NULL, false, FSAALevel);
mRightEyeRenderTexture = Ogre::TextureManager::getSingleton().createManual(
	"RiftRenderTextureRight", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
	Ogre::TEX_TYPE_2D, recommendedTex1Size.w, recommendedTex1Size.h, 0, Ogre::PF_R8G8B8,
	Ogre::TU_RENDERTARGET, NULL, false, FSAALevel);
it same

Code: Select all

setFSAA
This FSAA scene look better.
ChristophLGDV
Gnoblar
Posts: 18
Joined: Mon Jun 01, 2015 3:09 pm

Re: Oculus Rift DK2 Support - Extended mode only

Post by ChristophLGDV »

Hi and thank you for your Sample. It has been very educational in teaching Ogre and the Oculus SDK.

However I am currently stuck getting SDK distortion running and was wondering if you give me a hint:

Whenever I call endFrame, the system segfaults.
I work with Linux.

ovrHmd_ConfigureRendering
ovrHmd_AttachToWindow
are called using Ogres WindowHandle and Display handle.

The Ogre texturesIDs are put into ovrGLTextures and as soon as I call endFrame XQueryExtension crashes.

Thank you for reading, I am looking forward to an answer.

Edit: Solved, I had problems with the display. Without a proper _XDisplay* ovr will segfault. Obviously.
User avatar
Nishan
Gnoblar
Posts: 5
Joined: Fri Aug 28, 2015 4:46 am

Re: Oculus Rift DK2 Support - Extended mode only

Post by Nishan »

Hi Germanunkol,

Thanks for sharing your code. :) But I have a big problem :( . This is regarding CMake. (screenshot attached).

please help me figure this out :?

Thaks you.
Attachments
Capture.PNG
Germanunkol
Halfling
Posts: 87
Joined: Mon Oct 11, 2010 6:39 pm
x 12

Re: Oculus Rift DK2 Support - Extended mode only

Post by Germanunkol »

Hi,

Glad you find it useful!

The way I do it is to put the OculusSDK into the Source Folder (your Dektop/OgreOculusSample Folder). Make sure to run the makefile (or however else you build the samples on your machine - there might be a visual Studio solution included, I don't remember) in the OculusSDK Folder, and make sure to call it OculusSDK. Then the System should pick it up automatically.

P.S. Note that this was last tested with the older Oculus SDKs (I think up to Version 0.6) - the newest SDK Version won't work with this Code, since they dropped the Extended mode.
I'd like to try and update the Code to work with the direct mode, but this might take me a few months, and I can't make promises that it'll work. Kojack has tried, but hasn't entirely solved the Problem, believe.
User avatar
Nishan
Gnoblar
Posts: 5
Joined: Fri Aug 28, 2015 4:46 am

Re: Oculus Rift DK2 Support - Extended mode only

Post by Nishan »

Thank you very much for your quick reply :) But I'm still stuck in building the samples. What I have done so far:
  • 1. Cloned your project
    2. Put the OculusSDK into the Source Folder
    3. executed cmake-gui
But still get the same error.
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find OculusSDK (missing: OCULUS_SDK_LIBRARIES
OCULUS_SDK_INCLUDE_DIRS)
Call Stack (most recent call first):
C:/Program Files (x86)/CMake/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
cmake/FindOculusSDK.cmake:127 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:49 (find_package)
Please help me to build the project in visual studio.

Thank you
Germanunkol
Halfling
Posts: 87
Joined: Mon Oct 11, 2010 6:39 pm
x 12

Re: Oculus Rift DK2 Support - Extended mode only

Post by Germanunkol »

Hi,

Once you've copied the OculusSDK folder into the Source folder, go into the OculusSDK folder and find the Visual Studio project in there. Build that using Visual studio - this will generate the libraries needed by the Ogre Oculus Sample.

Then go back and run cmake.
User avatar
Nishan
Gnoblar
Posts: 5
Joined: Fri Aug 28, 2015 4:46 am

Re: Oculus Rift DK2 Support - Extended mode only

Post by Nishan »

Thank You very much

I have build it. What I did was I assigned the paths to OCULUS_SDK_LIBRARY , OCULUS_SDK_INCLUDE_DIRS, OCULUS_SDK_CAPI_DIR AND OCULUS_SDK_LIBRARY_DEBUG manually.

Thank you very much again. I built it using Oculus SDK 0.4.3. :D
User avatar
Nishan
Gnoblar
Posts: 5
Joined: Fri Aug 28, 2015 4:46 am

Re: Oculus Rift DK2 Support - Extended mode only

Post by Nishan »

Hey,

I have build it successfully using cmake. And there was a error called cannot open Kernel/OVR_Math.h. I have figured it. But there is another problem in Rift.cpp . (Screenshot attached) If you have time please put a reply.
Capture.PNG
:)
Thank you
Germanunkol
Halfling
Posts: 87
Joined: Mon Oct 11, 2010 6:39 pm
x 12

Re: Oculus Rift DK2 Support - Extended mode only

Post by Germanunkol »

Hey,

that's weird.
Are you using OpenGL? And are you using Ogre 1.9?

The GpuProgramParameters has the function I use there (see the Ogre 1.9 docs).

So I don't see what's going on there.
If you're using OpenGL and Ogre 1.9, maybe try searching the forums for this problem or post your own question somewhere?
User avatar
Nishan
Gnoblar
Posts: 5
Joined: Fri Aug 28, 2015 4:46 am

Re: Oculus Rift DK2 Support - Extended mode only

Post by Nishan »

Sorry I am using Ogre 1.8 and thank you for your quick reply. :)
Post Reply