Oculus Rift in Ogre

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7133
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia

Re: Oculus Rift in Ogre

Post by Kojack » Sun May 05, 2013 2:14 am

Good point. I've never actually bothered with that before, I usually avoid cg. Or use it, get pissed off at it doing freaky stuff then go back to hlsl. I'm only using it now so opengl is supported for the rift and I don't know glsl.

Installing the cg sdk...

Ok, got the code. Damn, compiler is outputting wrong code.

From my examples above
Wrong result:

Code: Select all

texld r0, r3, s0
texld r0, r1, s0
texld r0, r2, s0
mov r0.w, c5.x
mov oC0, r0
Correct result:

Code: Select all

texld r1, r1, s0
texld r2, r2, s0
texld r0, r3, s0
mul r0.x, r1, c5
mul r0.y, r2, c5.x
mov r0.w, c5.y
mul r0.z, r0, c5.x
mov oC0, r0
In the first bit of code, all three texlds load into the same r0 register! They overwrite each other. In the second bit of code, they load into different registers, multiply by the 1.00001 (in constant c5) then get put into the individual components of r0.

Now to find a way around it that won't slow things down.
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7133
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia

Re: Oculus Rift in Ogre

Post by Kojack » Sun May 05, 2013 2:31 am

That was with profile ps_2_0. With ps_2_x it generates different but still broken code (now a different tex coord set is used for all three). With ps_3_0 I get what looks like correct code, but when I run it I get just a dark blue screen (probably due to mixing shader versions, I'm using a default ogre vertex shader that's probably sm1 or sm2). Guess I need to write a new vertex shader and target sm3 (I don't mind, anybody running on gfx cards older than a 2004 geforce 6 probably shouldn't be trying to run VR).
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7133
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia

Re: Oculus Rift in Ogre

Post by Kojack » Sun May 05, 2013 2:43 am

Oops, turns out I forgot to include the ogre stdquad vertex shader files. It was using fixed function for the vertices, which ps_3_0 doesn't like. Adding in a suitable vertex shader now has ps_3_0 running correctly without needing those *1.00001 hacks.
(the missing vertex shader had nothing to do with the ps_2_0 shader being broken)

Yay, back to coding.
0 x

TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin

Re: Oculus Rift in Ogre

Post by TheSHEEEP » Sun May 05, 2013 8:27 am

Why cg, btw?
Wouldn't it make more sense to use HLSL & GLSL, as cg simply doesn't work everywhere and afaik both are faster than cg?
0 x
My site! - Have a look :)
Also on Twitter - extra fluffy

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7133
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia

Re: Oculus Rift in Ogre

Post by Kojack » Sun May 05, 2013 10:41 am

Because I didn't feel like learning glsl and glsles but still wanted opengl and potential cross platform support. :)
But seeing it break like this makes me question that.

I need to get some performance numbers, see how cg compares to hlsl for optimised output.
0 x

User avatar
mkultra333
Gold Sponsor
Gold Sponsor
Posts: 1782
Joined: Sun Mar 08, 2009 5:25 am

Re: Oculus Rift in Ogre

Post by mkultra333 » Mon May 06, 2013 4:33 am

I used to use CG in my project and it threw up weird bugs just often enough to be irritating and confusing. I'd have to do things like the *1.00001 thing because it would mess up the channels otherwise. And sometimes it would just decide certain functions wouldn't work, like reflect or frac, even though another almost identical shader would work fine. I'd have to get around them by manually calculating the reflection or using fmod. Or changing the order of the code in a way that wouldn't make any logical difference.
0 x
"In theory there is no difference between practice and theory. In practice, there is." - Psychology Textbook.

TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin

Re: Oculus Rift in Ogre

Post by TheSHEEEP » Mon May 06, 2013 10:22 am

All shading languages are really similar in the code.
What tends to be rather different is stuff like defing samplers. But we have that covered in materials, so all is well.
So if you fell like it, porting hlsl -> glsl is easier than one might think. IMO.
0 x
My site! - Have a look :)
Also on Twitter - extra fluffy

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7133
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia

Re: Oculus Rift in Ogre

Post by Kojack » Mon May 06, 2013 11:27 am

I've done some GLSL to HLSL by hand, but not the other way (I generally dislike opengl, but with DX11 being the last DX I may have to move over eventually).
0 x

cullam
Kobold
Posts: 30
Joined: Wed Aug 15, 2012 7:19 pm

Re: Oculus Rift in Ogre

Post by cullam » Thu May 09, 2013 2:33 pm

Do I need to change any settings by hand to get this working properly? I've got the demo running, but the stereo settings are way off. I'm seeing two orcs, rather than a stereoscopic view of one. It seems like it's assuming my eyes are a meter or two apart.
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7133
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia

Re: Oculus Rift in Ogre

Post by Kojack » Fri May 10, 2013 10:46 am

Are you running the 0.5.1 demo? One of the earlier demos (either 0.5 or 0.4, can't remember) had that issue.
0 x

cullam
Kobold
Posts: 30
Joined: Wed Aug 15, 2012 7:19 pm

Re: Oculus Rift in Ogre

Post by cullam » Fri May 10, 2013 2:09 pm

Yeah, that was the issue, thanks. I missed that the last link pointed to a different file.
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7133
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia

Re: Oculus Rift in Ogre

Post by Kojack » Fri May 10, 2013 5:46 pm

Cool.
I still don't have a rift myself, so if I've done anything wrong it's hard to fix. :)
0 x

hedphelym
Halfling
Posts: 96
Joined: Tue Nov 25, 2008 10:58 am

Re: Oculus Rift in Ogre

Post by hedphelym » Mon May 27, 2013 5:18 pm

edited my post..

downloaded from:
https://bitbucket.org/rajetic/ogreoculus/downloads/

works perfectly! thanks!
It's VERY cool to see the ogre 'in real life', he's taller then me, and it's way different to view him in stereoscopic 3d in 'real' size, and the details really pops out.
It's very very cool to use the oculus with this.

I was able to compile your code from source too, I grabbed the latest ogre rc1 for vs 2012 x32.
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7133
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia

Re: Oculus Rift in Ogre

Post by Kojack » Tue May 28, 2013 3:27 am

Cool. :)

I'll try to get an update out soonish (very busy at work, we just started a new trimester and I'm teaching first and second year students) that adds in the new sdk features (chromatic aberation correction and yaw drift correction). I've already got the chromatic aberation shader working.
0 x

hedphelym
Halfling
Posts: 96
Joined: Tue Nov 25, 2008 10:58 am

Re: Oculus Rift in Ogre

Post by hedphelym » Tue May 28, 2013 5:59 am

great. no rush. and thanks for your efforts so far.
I understand you are busy, same for me :)
0 x

OpenGLPriest
Gnoblar
Posts: 8
Joined: Tue May 28, 2013 1:31 am

Re: Oculus Rift in Ogre

Post by OpenGLPriest » Thu May 30, 2013 6:40 am

Kojack, thanks for this development. (One thing I love about the internet is finding that people have already finished huge parts of a project that I want to do.) My goal is to use OGRE on a Raspberry Pi to drive an Oculus Rift; once the Raspberry Pi OGRE port is finished, we will see if the Pi hardware is up to the task of dewarping at 60fps.

Also, I'm not sure what's special about it, but this is the only Rift demo I have ever tried that hasn't given me motion sickness.
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7133
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia

Re: Oculus Rift in Ogre

Post by Kojack » Thu May 30, 2013 2:49 pm

OpenGLPriest wrote:Also, I'm not sure what's special about it, but this is the only Rift demo I have ever tried that hasn't given me motion sickness.
Hehe, awesome.

That could be a cool advertising idea.
"Ogre - it doesn't make you sick like Unity does"
:)

The pi's gpu is pretty fast. Not sure about the warping stuff at 60fps, but it will be interesting to see.
(I've got a pi too, but haven't done any coding for it yet)
0 x

MrLobo
Gnoblar
Posts: 1
Joined: Wed May 01, 2013 12:32 pm

Re: Oculus Rift in Ogre

Post by MrLobo » Sat Jun 01, 2013 11:52 am

Awesome work kojack. I got my Rift a couple days ago, I also get less simulator sickness with your demo than with the Unity Tuscany one. Your source code has been very instructive for me, I will try to incorporate it to my Ogre based student videogame project and will report back when I get it done. Thanks a lot for sharing.
0 x

FultonX
Gnoblar
Posts: 3
Joined: Tue Jun 11, 2013 5:55 pm

Re: Oculus Rift in Ogre

Post by FultonX » Tue Jun 11, 2013 7:41 pm

I simply threw the .cg, .material, and .compositor files into my already stereoscopic project, and called addCompositor() and setCompositorEnabled() on my viewports.

The viewports were filled with a solid color that changed when the camera moved. I omitted the call to add and enable the compositor for the right eye viewport so I could perform side-by-side comparison against the compositor on the left eye viewport. I verified that the screen was being filled with a colors reflecting the textures in my scene. I reviewed Ogre.log and found that line 12:

param_named HmdWarpParam float4 1.0f, 0.22f, 0.24f, 0.0f

produced an error. I removed the f's and commas so that it reads:

param_named HmdWarpParam float4 1.0 0.22 0.24 0.0

The error went away but now the viewport with the compositor is solid black always. Any ideas what I'm doing wrong here?
0 x

User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2701
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia

Re: Oculus Rift in Ogre

Post by syedhs » Tue Jun 11, 2013 9:29 pm

What is the Ogre.log full content?
0 x
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me

FultonX
Gnoblar
Posts: 3
Joined: Tue Jun 11, 2013 5:55 pm

Re: Oculus Rift in Ogre

Post by FultonX » Tue Jun 11, 2013 10:47 pm

Ogre.log (relevant lines)
...
17:17:00: Parsing script oculus.material
17:17:00: Compiler error: number expected in oculus.material(12): incorrect float constant declaration
...
17:17:01: Parsing script oculus.compositor
...
________________________________________________
oculus.material (line 12)
...
param_named HmdWarpParam float4 1.0f, 0.22f, 0.24f, 0.0f
...


Thank you for looking.
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7133
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia

Re: Oculus Rift in Ogre

Post by Kojack » Wed Jun 12, 2013 9:14 am

FultonX wrote:Ogre.log (relevant lines)
...
17:17:00: Parsing script oculus.material
17:17:00: Compiler error: number expected in oculus.material(12): incorrect float constant declaration
...
17:17:01: Parsing script oculus.compositor
...
________________________________________________
oculus.material (line 12)
...
param_named HmdWarpParam float4 1.0f, 0.22f, 0.24f, 0.0f
...


Thank you for looking.
Hmm, strange. I don't get that error. It might be because I had commas in there while the other parameters don't use commas. Maybe your locale is making commas have a different meaning (some locales swap the meaning of commas and periods). Try changing the line to:
param_named HmdWarpParam float4 1.0f 0.22f 0.24f 0.0f
FultonX wrote:I simply threw the .cg, .material, and .compositor files into my already stereoscopic project, and called addCompositor() and setCompositorEnabled() on my viewports.
There's a bit more than that required. Take a look at my setupOgre, there's material cloning, shader paremeters being set and custom projection matrices being generated.
0 x

FultonX
Gnoblar
Posts: 3
Joined: Tue Jun 11, 2013 5:55 pm

Re: Oculus Rift in Ogre

Post by FultonX » Wed Jun 12, 2013 4:44 pm

Thank you very much for taking a look :)

I removed the commas and still had the same error message. Only removing both the f's and the comma's takes care of the error message (removes it).

I added the following code from SetupOgre(). Please note that I don't have the rift yet, and am merely trying to setup the visual warping/extended FOV effect in preparation. I am operating on Linux and not incorporating the SDK into this particular project yet.

This code seems to merely clone the material for use in the compositor for the right eye, as well as set various parameters of the shader, which in my case looks like the defaults again (it looks like if I had the rift, I'd be porting in some kind of custom calibration settings from it here). There is also the camera initialization lines for aspect ratio, fov, and then the custom projection matrix. It seems to me though that without any of these things set, I should see some screen warping effect from the hmdwarp function of oculus.cg, am I wrong? Prior to fixing the Ogre.log error, the full screen color field changed when I moved the camera, so I suppose that could be considered a screen warping effect. Perhaps the result of values not being initialized properly (like with zeroes) but I hardly think there is a name mismatch since it works on your end. Also there is the fact that resolving the error produces only a solid black screen that never changes. Any ideas there?
FultonX wrote:The error went away but now the viewport with the compositor is solid black always
Results: Black screen (viewport bg color) just like before.
If I remove a compositor from one of the viewports, I see the FOV has changed. Any ideas what to try next?

Code: Select all

  Ogre::MaterialPtr matLeft = Ogre::MaterialManager::getSingleton().getByName( "Ogre/Compositor/Oculus" );
  Ogre::MaterialPtr matRight = matLeft->clone( "Ogre/Compositor/Oculus/Right" );

  Ogre::GpuProgramParametersSharedPtr pParamsLeft = matLeft->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
  Ogre::GpuProgramParametersSharedPtr pParamsRight = matRight->getTechnique(0)->getPass(0)->getFragmentProgramParameters();

  Ogre::Vector4 hmdwarp;
  const float g_defaultProjectionCentreOffset = 0.14529906f;
  const float g_defaultDistortion[4] = { 1.0f, 0.22f, 0.24f, 0 };
  hmdwarp = Ogre::Vector4( g_defaultDistortion[0],
                           g_defaultDistortion[1],
                           g_defaultDistortion[2],
                           g_defaultDistortion[3] );

  pParamsLeft->setNamedConstant( "HmdWarpParam", hmdwarp);
  pParamsRight->setNamedConstant("HmdWarpParam", hmdwarp);

  pParamsLeft->setNamedConstant( "LensCentre",   0.5f + ( g_defaultProjectionCentreOffset / 2.0f ) );
  pParamsRight->setNamedConstant("LensCentre",   0.5f - ( g_defaultProjectionCentreOffset / 2.0f ) );
  
  Ogre::CompositorPtr comp = Ogre::CompositorManager::getSingleton().getByName( "OculusRight" );
  comp->getTechnique(0)->getOutputTargetPass()->getPass(0)->setMaterialName( "Ogre/Compositor/Oculus/Right" );


  mCamera->setAspectRatio( 8.0 / 10.0 );
  mCamera->setFOVy( Ogre::Radian( Ogre::Degree( 110.0 ) ) );

  // Oculus requires offset projection, create a custom projection matrix
  Ogre::Matrix4 proj = Ogre::Matrix4::IDENTITY;
  float temp = g_defaultProjectionCentreOffset;
  int i = 0;  // using StereoManager for OGRE, and I only see one Ogre::Camera pointer... for now, setting to 0 thus affecting only the one camera
  proj.setTrans( Ogre::Vector3( -g_defaultProjectionCentreOffset * ( 2 * i - 1 ), 0, 0 ) );
  mCamera->setCustomProjectionMatrix( true, proj * mCamera->getProjectionMatrix() );
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7133
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia

Re: Oculus Rift in Ogre

Post by Kojack » Tue Jun 18, 2013 5:44 am

Two months after making this demo, I've finally gotten to try it on a real rift. :)
One of my students is a kickstarter of the rift, so he brought his in today. I brought in my razer hydra. My rift is still probably at least a month away from arriving.

Some initial opinions:
- I like lens set A with very minimal distance.
- No motion sickness. I don't feel any different when wearing it. Doing things like car racing with jumps and flips gives me no feeling, it's just a game to me. But other staff and students came in to try it (I'm in a classroom with final project students) and some of them can barely last a few minutes before they feel sick.
- The ogre sinbad demo I made looks sharper and clearer than the unity tuscany demo (might be their over exposing lightmap shader).
- The ogre sinbad demo's 3d looked a bit flat for distant stuff (as do all the other demos), but when I moved up really close to sinbad (like 30cm from him) I could actually feel him invading my personal space. It felt uncomfortablely awkward. That was probably the most immersed I felt, getting really close to stuff (plus sinbad is taller than the player, so he really towers over me).
- Ogre isn't picking up the rift's hdmi as a real display, I had to clone the desktop. That's odd. Ogre does pick up my vuzix headset as a display and let me select it in the config dialog. I'll have to look into that.
- Using a hydra with the oculus is great, but so many cables!
- oculus cable (headset to control box) is way too short.
- My uneven vision (my right eye is near sighted, left eye is normal) doesn't cause a problem (that was my main concern).

Turns out my college has ordered a rift too, so I won't have to bring in mine all the time. :)

Sadly in a couple of hours this rift will be going home with it's owner. So no coding progress until I get mine.
0 x

xrgo
OGRE Expert User
OGRE Expert User
Posts: 804
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile

Re: Oculus Rift in Ogre

Post by xrgo » Sun Jul 07, 2013 8:44 am

Hi! I am trying to make this work, only the setupOgre part for now... but I am getting black viewport when I "setEnabled(true)" the compositor
without enabling the compositor I can see the two viewports just fine.
If I set another compositor effect like Bloom, it works fine too.

I am on linux Ubuntu 12.04 x64 using ogre 1.9

please help me!
many thanks in advance!

EDIT: I make it work, it just doesnt work with "optirun" using my nvidia 540m, but it works with the integrate intel h3000. damn you nvidia for not having oficial support for optimus on linux
0 x

Post Reply