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: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Oculus Rift in Ogre

Post by Kojack »

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.
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 in Ogre

Post by Kojack »

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).
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 in Ogre

Post by Kojack »

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.
TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin
x 65

Re: Oculus Rift in Ogre

Post by TheSHEEEP »

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?
My site! - Have a look :)
Also on Twitter - extra fluffy
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 in Ogre

Post by Kojack »

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.
User avatar
mkultra333
Gold Sponsor
Gold Sponsor
Posts: 1894
Joined: Sun Mar 08, 2009 5:25 am
x 114

Re: Oculus Rift in Ogre

Post by mkultra333 »

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.
"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
x 65

Re: Oculus Rift in Ogre

Post by TheSHEEEP »

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.
My site! - Have a look :)
Also on Twitter - extra fluffy
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 in Ogre

Post by Kojack »

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).
cullam
Kobold
Posts: 30
Joined: Wed Aug 15, 2012 7:19 pm

Re: Oculus Rift in Ogre

Post by cullam »

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.
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 in Ogre

Post by Kojack »

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.
cullam
Kobold
Posts: 30
Joined: Wed Aug 15, 2012 7:19 pm

Re: Oculus Rift in Ogre

Post by cullam »

Yeah, that was the issue, thanks. I missed that the last link pointed to a different file.
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 in Ogre

Post by Kojack »

Cool.
I still don't have a rift myself, so if I've done anything wrong it's hard to fix. :)
hedphelym
Gremlin
Posts: 180
Joined: Tue Nov 25, 2008 10:58 am
Location: Kristiansand, Norway
x 23
Contact:

Re: Oculus Rift in Ogre

Post by hedphelym »

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.
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 in Ogre

Post by Kojack »

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.
hedphelym
Gremlin
Posts: 180
Joined: Tue Nov 25, 2008 10:58 am
Location: Kristiansand, Norway
x 23
Contact:

Re: Oculus Rift in Ogre

Post by hedphelym »

great. no rush. and thanks for your efforts so far.
I understand you are busy, same for me :)
OpenGLPriest
Gnoblar
Posts: 8
Joined: Tue May 28, 2013 1:31 am

Re: Oculus Rift in Ogre

Post by OpenGLPriest »

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.
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 in Ogre

Post by Kojack »

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)
MrLobo
Gnoblar
Posts: 1
Joined: Wed May 01, 2013 12:32 pm

Re: Oculus Rift in Ogre

Post by MrLobo »

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.
FultonX
Gnoblar
Posts: 3
Joined: Tue Jun 11, 2013 5:55 pm

Re: Oculus Rift in Ogre

Post by FultonX »

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?
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2703
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 51

Re: Oculus Rift in Ogre

Post by syedhs »

What is the Ogre.log full content?
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 »

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.
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 in Ogre

Post by Kojack »

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.
FultonX
Gnoblar
Posts: 3
Joined: Tue Jun 11, 2013 5:55 pm

Re: Oculus Rift in Ogre

Post by FultonX »

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() );
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 in Ogre

Post by Kojack »

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.
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: Oculus Rift in Ogre

Post by xrgo »

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
Post Reply