Oculus Rift in Ogre

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.

Re: Oculus Rift in Ogre

Postby cybereality » Wed Sep 25, 2013 5:58 am

If you want to decrease the quality loss when doing the pre-warping, you can try increasing the render target size.

You can do this, for example, by setting the scale in the warping material to "2" or something like that. It will improve the quality a lot.
User avatar
cybereality
Hobgoblin
 
Posts: 561
Kudos: 11
Joined: 12 Jul 2006

Re: Oculus Rift in Ogre

Postby cullam » Tue Dec 03, 2013 8:44 pm

So, has anybody done any work at all to get CEGUI working with the Rift? If not, any helpful tips on where I should start? Our project uses CEGUI in many places, and rather than replacing it all with Gorilla, which I've got working in the rift, I'd really rather get CEGUI up and running in the Oculus. Although that might unrealistic in the first place. Basically, the project is large and complex enough that completely replacing CEGUI with Gorilla at this point seems like a HUGE undertaking. Would I be correct on that?
cullam
Kobold
 
Posts: 30
Kudos: 0
Joined: 15 Aug 2012

Re: Oculus Rift in Ogre

Postby scrawl » Tue Dec 03, 2013 8:49 pm

Try to render CEGUI onto a render texture and then show a 3D plane with that texture in the scene.
User avatar
scrawl
OGRE Expert User
OGRE Expert User
 
Posts: 1119
Kudos: 216
Joined: 01 Jan 2011
Location: Germany

Re: Oculus Rift in Ogre

Postby cullam » Wed Dec 04, 2013 4:06 pm

Do you mean something like the inverse of what is described in Tutorial 7? (http://www.ogre3d.org/tikiwiki/Basic+Tu ... to_Texture)
In that example, they turn a viewport into a texture, to be rendered in a CEGUI window. Are there functions built into CEGUI to do the opposite and render the menu (and in a perfect world, even things like floating drag and drop buttons) onto an arbitrary texture in the world?
cullam
Kobold
 
Posts: 30
Kudos: 0
Joined: 15 Aug 2012

Re: Oculus Rift in Ogre

Postby amartin » Wed Dec 04, 2013 8:26 pm

I would think you would need to change how your UI worked anyway to function on the rift but you will either need to draw the GUI in world space centred between the two cameras or draw it slightly offset to both viewports. I don't know how cegui works so I cant say which is more complicated. There is a 2d fov value I think you may need to keep your GUI within that for it to look good. Also do not use camera facing billboards to display things they don't work well with the wide fov and camera offsets.

Beyond that without running up cegui myself to see what is going wrong I can't help more.
amartin
Halfling
 
Posts: 87
Kudos: 13
Joined: 14 Aug 2013
Location: Norway

Re: Oculus Rift in Ogre

Postby cullam » Thu Dec 05, 2013 8:20 pm

Yes, the thing I'm trying to do is draw my gui onto a texture in the worldspace. As we have it set up now, before the notion of VR being a part of this project was hatched, they behave just like you would expect menus to. Which means that a menu will be drawn onto the center of the full screen, giving each eye a view of one side, hiding the middle between the eyes, and without any correction for lens distortion. If I can render the menus not onto the actual screen, like they normally would be, but onto a texture that I can place in the scene (floating in front of the player's face, fully transparent when there is no menu), then all those issues are immediately taken care of, by how I'm already dealing with rendering things from Ogre.

I want to make this modification as painless as possible, because more than just our menu system uses CEGUI - we also use it in mini maps, and other 2D information and interactions. However, the problem is easy to solve, IF I can switch the rendertarget from being a viewport, to a texture. However, I'm having some trouble finding good examples of this. Most examples of trying render to a texture do the opposite - they render a 3D Ogre scene to a texture, and display that texture in a CEGUI viewport. I want to render the 2D imagery that CEGUI creates, and render it onto a texture in Ogre. Anyone have any solid examples of how this is done?
cullam
Kobold
 
Posts: 30
Kudos: 0
Joined: 15 Aug 2012

Re: Oculus Rift in Ogre

Postby scrawl » Thu Dec 05, 2013 8:35 pm

I don't use CEGUI but this is what I gathered from looking at it's documentation.
1. Use the CEGUI::Renderer::createTextureTarget to create a render texture.
2. Supply this render target to the GUIContext constructor.

3. To get the name of the texture (to show it on a material), use renderTarget.getTexture().getName();
User avatar
scrawl
OGRE Expert User
OGRE Expert User
 
Posts: 1119
Kudos: 216
Joined: 01 Jan 2011
Location: Germany

Re: Oculus Rift in Ogre

Postby AE86takumi » Sat Dec 14, 2013 7:00 am

I use the Gorilla UI library for my Oculus project and it works quite well. I simply render a 3D panel with the captions or buttons I need and attach it to a SceneNode. Then you can do position and orientation changes as needed.

It's a little tricky when you want to make a HUD (one that follows the camera and always faces you) because to move a panel off the center of the screen you need to:
- make a copy of the camera orientation quaternion.
- rotate it by some angle in the x-axis (if you want to move the panel up or down off center), or the y-axis (if you want to move it left or right off center).
- normalize the resulting quaternion.
- multiply it with the original camera orientation.
- create an offset vector for the position of the panel using ToRotationMatrix.
- make the length of the vector the distance you'd like the panel to be away from the camera (normalize, then *distance).
- finally set the orientation of the panel to the orientation of the camera, and position to the vector specified above + camera node derived position.

I'm sure there's a simpler way of making a HUD using 2D ui elements, but this to me seemed easier and didnt require using different compositors for 2D or 3D UI.
AE86takumi
Gnoblar
 
Posts: 8
Kudos: 0
Joined: 30 Nov 2013

Re: Oculus Rift in Ogre

Postby amartin » Mon Dec 16, 2013 2:47 am

If you setup your cameras so that they have a single parent node you can attach the HUD to that node in addition to the cameras. Then you just need to adjust the HUD position relative to the origin of the cameras rather than handling the orientations manually.

Something like
Code: Select all
Camera Position Node
-> Camera Rotation Node
    -> Left Camera Node
    -> Right Camera Node
    -> HUD root node
        -> HUD elements


This will handle the orientation for you so that when you turn or move the camera the UI moves with it. Just setup the intial rotation and position of the node so that it is facing the cameras in the position you want.

For this message the author amartin has received kudos
amartin
Halfling
 
Posts: 87
Kudos: 13
Joined: 14 Aug 2013
Location: Norway

Re: Oculus Rift in Ogre

Postby cullam » Mon Dec 16, 2013 4:51 pm

I'm using Gorilla now for all of my VR HUD stuff that I'm adding. Took some mucking around, but I've got it working nicely. The problem with switching to it entirely is that this is a large project, and switching away from CEGUI for our menus involves changing at least 2,000 lines of code. And as the oculus support is an experimental side project, that isn't going to happen. But I'm slowly working my way towards getting things working. The fact that the version of CEUGI we're using isn't the one referred to in the online documentation didn't help (we're using 0.7.6). I've downloaded the documentation for that version, but it is far slower and more irritating to use. Oh well. I shall continue wading through!
cullam
Kobold
 
Posts: 30
Kudos: 0
Joined: 15 Aug 2012

Re: Oculus Rift in Ogre

Postby nickG » Thu Dec 19, 2013 2:00 pm

subscribed
nickG
Greenskin
 
Posts: 122
Kudos: 1
Joined: 20 Jan 2012
Location: Russia,Moscow

Re: Oculus Rift in Ogre

Postby AE86takumi » Sun Dec 22, 2013 4:01 am

Thanks amartin! I knew there had to be a simple way to do it lol.
At least it worked out as a good learning experience for working with quaternions.
AE86takumi
Gnoblar
 
Posts: 8
Kudos: 0
Joined: 30 Nov 2013

Re: Oculus Rift in Ogre

Postby Swdshchf » Fri Jan 10, 2014 11:40 pm

Assuming that the rajetic bitbucket repository still holds the latest version of the Ogre Oculus demo, the .7z file still doesn't have the StdQuad_vp program or shader files packaged up with it. That doesn't seem to be a problem. The code still runs fine, with just a small complaint in the .log file about a non-existent object. However, if I copy the appropriate files over, then the OpenGL version stops working. It loads the .glsl flavor of StdQuad while the DX9 version loads the .cg flavor. With the .glsl StdQuad shader, the demo just shows a black screen. If I go into the scripts and force it to use the .cg code with OpenGL, then everything works again.

I'm pretty naive about shader code. Could someone explain (1) what StdQuad is supposed to do, (2) why the code works fine without it, and (3) why the .glsl version seems to be broken?

Thanks,

sc
Swdshchf
Gnoblar
 
Posts: 1
Kudos: 0
Joined: 08 Jan 2014

Re: Oculus Rift in Ogre

Postby scrawl » Sat Jan 11, 2014 1:16 am

You cannot combine a CG fragment shader with a GLSL vertex shader (or vice versa). So either both in GLSL, or both in CG.
User avatar
scrawl
OGRE Expert User
OGRE Expert User
 
Posts: 1119
Kudos: 216
Joined: 01 Jan 2011
Location: Germany

Re: Oculus Rift in Ogre

Postby Crhonos » Thu Mar 13, 2014 10:36 pm

Did anyone got this to work without the distortion when you look up, or roll your head? Because I was trying OgreOculus 0.5.1 and it had these errors, I saw some posts about Y distortion, is it about this? Does anyone already fixed this issue?
Crhonos
Gnoblar
 
Posts: 14
Kudos: 0
Joined: 27 Jul 2011

Re: Oculus Rift in Ogre

Postby amartin » Fri Mar 14, 2014 10:15 am

I adjusted the setup and got rid of most of the distortion there is probably some more tweaking to do but it wasn't my main focus.
https://github.com/anthony-martin/RifTop/blob/master/WolfGame/CameraController.cpp
That code covers the camera setup so you can use the shader setup from there.
amartin
Halfling
 
Posts: 87
Kudos: 13
Joined: 14 Aug 2013
Location: Norway

Re: Oculus Rift in Ogre

Postby Crhonos » Fri Mar 14, 2014 9:27 pm

Thank you so much!! I was looking through Oculus forum and discovered that one of the distortion causes were the aspect ratio, even found the code to make the scaling, but I had no idea were to put it, your code is going to save me a week !!
Crhonos
Gnoblar
 
Posts: 14
Kudos: 0
Joined: 27 Jul 2011

Re: Oculus Rift in Ogre

Postby amartin » Sat Mar 15, 2014 7:29 am

You're welcome glad to save you some time sorting out the setup. I'll keep that repository updated with any changes I make but the current resolution of the rift means that I cannot actually use it for a virtual desktop yet. Since it looks like it will be over a year before the comercial version is released I'm currently deciding if I push on with finishing the functionality or just drop it and wait to see if the tech actually pans out. I am tempted to try make my own high def hackulus rift but that would be a serious investment of time to try do.
amartin
Halfling
 
Posts: 87
Kudos: 13
Joined: 14 Aug 2013
Location: Norway

Re: Oculus Rift in Ogre

Postby cullam » Mon Mar 24, 2014 4:32 pm

amartin,
I've been using the first version of Oculus.cpp, with a few modifications, but the distortion is slightly off. Looking through it, I think it's that Scale and ScaleIn aren't adjusted using the aspect ratio. I just went through your code, which seems to take care of the issue correctly (at least , it looks like it - I haven't tested). I started trying to use some of the things you're doing, and ran into one really dumb (on my end) issue. I'm sure I've just missed something obvious, but when I try to call
Code: Select all
pParamsLeft->setNamedConstant("Scale", scale);
I get told that there is no function with these arguments. Apparently I can take a Vector3 or Vector4, but not a Vector2. I'm using Ogre 1.8.0. Is there a version issue here, or am I just missing something unbelievably basic?
cullam
Kobold
 
Posts: 30
Kudos: 0
Joined: 15 Aug 2012

Re: Oculus Rift in Ogre

Postby cullam » Mon Mar 24, 2014 7:10 pm

Apparently it is indeed an issue with the version of Ogre I'm using. I tried passing them in as vector4s with extra 0s, which seems to work perfectly. The distortion I'm seeing in my project now looks MUCH better! I still think that the way the 3D stereo split is off, so I've got some more work to do there. The difference between what I see with each eye is tiny. My IPD is set correctly, and overemphasising it just makes it harder for the two images to come together. Anyway, I'll report back if I figure out why the 3D effect seems much weaker here than with other games I've played.
cullam
Kobold
 
Posts: 30
Kudos: 0
Joined: 15 Aug 2012

Re: Oculus Rift in Ogre

Postby amartin » Sat Apr 05, 2014 1:03 pm

I'm using a build of Ogre 1.9 so that would explain the difference with allowing Vector2 in shader paramaters. I made some changes but those are in the DX11 render system so not related to the shader setup.

I guess things that are going to affect how the cameras look are your world scale. The values I use are for 1 unit is ~1metre you'll need to adjust if you are using something different. It sounds like you have that sorted out.

You can check to see if you have the left and right eye images are on the wrong side. I did that once and it works your brain puts the images together but it doesn't feel quite right.

I think the shader params are mosly ok but I was mostly focusing on other things. One thing to note is that my shader does not do any colour discarding so there will be some discolouration around the edge of the view.

If you need answers to stuff in a hurry you are better off PMing me as I only check in on the threads randomly. I've stopped all my VR work untill an acceptable comercial version is released.
amartin
Halfling
 
Posts: 87
Kudos: 13
Joined: 14 Aug 2013
Location: Norway

Re: Oculus Rift in Ogre

Postby TaaTT4 » Wed Apr 23, 2014 3:52 pm

Hi everybody,

I'm trying to integrate OGRE (1.9 version) with the latest Oculus Rift SDK (0.3.1 version).
In particular, I have to use the Direct3D9 render system and I'd like to use the SDK distortion rendering approach.

What I've done so far is:
  • Create a custom render loop where buffer swapping isn't called
  • Create two RTT texture where the scene is rendered from two different cameras (left and right eye)
  • Call ovrHmd_BeginFrame and ovrHmd_EndFrame in frameStarted and frameEnded callbacks
  • Call ovrHmd_BeginEyeRender and ovrHmd_EndEyeRender in preRenderTargetUpdate and postRenderTargetUpdate callbacks

I can see my scene rendered distorted for a moment, but after that the output is a mess.
Sometimes I see a completely black window, sometimes I see this: http://i.imgur.com/mALc04F.jpg (blue and white are the background colors of left and right eye viewports).

Digging in the Oculus Rift SDK sources, I've discovered that the DistortionRenderer::RenderBothDistortionMeshes (inside CAPI_D3D9_Util.cpp) method, which is invocated in the ovrHmd_EndFrame function, causes the issue.
In particular, I suspect all is related to the setting of pixel and vertex shaders which happens in that method.


[Edit]

Adding these two lines at the end of the DistortionRenderer::RenderBothDistortionMeshes method fixes the issue:

Code: Select all
...

device->SetPixelShader(NULL);
device->SetVertexShader(NULL);

//Revert render state
RevertAllStates();


Is it a bug?
User avatar
TaaTT4
Halfling
 
Posts: 89
Kudos: 5
Joined: 23 Apr 2014

Re: Oculus Rift in Ogre

Postby iblues1976 » Sat Apr 26, 2014 3:48 pm

Kojak,

Thank you for your amazing work. I was wondering how to do use OGRE with Oclus Rift.... I will keep an eye to this thread.

I'm actually not using the Oculus Rift by my collegue is.

For some reason, he tells me that when he is using it now, he gets facebook ads :)

Thanks,
Francisco
iblues1976
Gnome
 
Posts: 379
Kudos: 11
Joined: 16 Sep 2011

Re: Oculus Rift in Ogre

Postby Kojack » Sat Apr 26, 2014 5:48 pm

I've been meaning to get back to this stuff. Just not enough time.
I've started looking at ogre 1.9 with the new oculus 0.3.1 sdk. I'm going a different way to TaaTT4, I'm doing the distortion manually instead of the sdk method (both should be valid, I just don't like giving rendering control away from Ogre. But my way may make the timing stuff and timewarp harder. Not sure yet). But trying to get ogre's compositor to do non quad meshes looks messy, so I'm writing my own massively simplified mesh compositor.
But now I'm distracted with Dark Souls 2, marking assignments, etc. :)
User avatar
Kojack
OGRE Moderator
OGRE Moderator
 
Posts: 7126
Kudos: 516
Joined: 25 Jan 2004
Location: Brisbane, Australia

Re: Oculus Rift in Ogre

Postby amartin » Sun Apr 27, 2014 4:26 pm

Kojack for Non quad meshes wouldnt it be easier to render to texture then texture a new mesh in either a new render window or clear the window before rendering. I'm kinda guessing you are looking at doing the physical distortion method where you distort the image onto a mesh. I think that would achieve much the same goal and wouldn't require any changes really as materials already take shaders probably has an overhead but that is sorta what the compositors do anyway if I understand them correctly.

It's funny though out of the box distortion was a much requested feature for the Oculus and now that we have it I can't bring myself to trust them not to abuse it.
amartin
Halfling
 
Posts: 87
Kudos: 13
Joined: 14 Aug 2013
Location: Norway

PreviousNext

Return to Using OGRE in practice

Who is online

Users browsing this forum: No registered users and 7 guests