Horde3D

Next-Generation Graphics Engine
It is currently 27.11.2024, 10:45

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Stereo rendering
PostPosted: 10.06.2009, 13:00 
Offline

Joined: 21.12.2008, 23:46
Posts: 23
How do I enable stereo-rendering?
I have discovered the CameraNode parameter "OutputBufferIndex" where I can
set for which eye I want to draw the scene, but what additional steps will
be necessary? Will stereo rendering work without any native OpenGL instructions?


Top
 Profile  
Reply with quote  
 Post subject: Re: Stereo rendering
PostPosted: 10.06.2009, 22:17 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
You need to create a quad-buffered OpenGL context, for example by using the GLFW_STEREO flag. But please note that only expensive workstation cards like the NVidia Quadros have quad buffer support, so if you have a consumer card you won't be able to use the quad-buffer (left buffer, right buffer) stereo.


Top
 Profile  
Reply with quote  
 Post subject: Re: Stereo rendering
PostPosted: 11.06.2009, 11:48 
Offline

Joined: 21.12.2008, 23:46
Posts: 23
Thanks for the hint.
I will report if I get this running with SDL.
Should be something like
Code:
SDL_GL_SetAttribute(SDL_GL_Stereo, 1);


Top
 Profile  
Reply with quote  
 Post subject: Re: Stereo rendering
PostPosted: 19.06.2009, 19:41 
Offline

Joined: 21.12.2008, 23:46
Posts: 23
According to http://www.gali-3d.com/archive/articles/StereoOpenGL/StereoscopicOpenGLTutorial.php
I have to do the following steps to achieve stereoscopic rendering:
Quote:
1) Set the geometry for the view from left human eye
2) Set the left eye rendering buffers
3) Render the left eye image
4) Clear Z-buffer (if the same Z-buffer for left and right image is used)
5) Set the geometry for the view from right human eye
6) Set the right eye rendering buffers
7) Render the right eye image
8) Swap buffers


To transfer this to Horde3D I will enable quad-buffering by setting the appropriate
flag for GLFW/SDL (e.g. SDL_GL_SetAttribute(SDL_GL_Stereo, 1); ) and then render my scene
from two different eye-positions as follows:
1. - 3.) This should be easy as I can render as usual:
Code:
        // left eye
        Horde3D::setNodeTransform( _cam, 0, 0, 0, 0 ,0, 0, 1, 1, 1 ); // fixed view only
        Horde3D::setNodeParami(_cam, CameraNodeParams::OutputBufferIndex, 0);
        Horde3D::render( _cam );

4.) Do I have to clear the Z-buffer manually? If yes, how do I do that? I think this would require
some native OpenGL calls.
5. - 8.) To render the scene for the right eye's position I think that I have to translate my
camera's position by my eye-distance to the right and then set the OutputBufferIndex to my
right eye's buffer. Do I have to translate the camera manually or does Horde3D automatically
adjust the eye-position when I set the buffer to the right eye?
Finally I would call Horde3D::render(_cam); again to get my right eye's view rendered
to the appropriate buffer and then swap buffers.
Code:
        /*
           clear Z-buffer here....
        */
        // right eye
        Horde3D::setNodeTransform( _cam, eyeDistance, 0, 0, 0 ,0, 0, 1, 1, 1 ); // fixed view only
        Horde3D::setNodeParami(_cam, CameraNodeParams::OutputBufferIndex, 1);
        Horde3D::render( _cam );
        SDL_GL_SwapBuffers();


Is anything wrong or missing in this approach? I am not quite sure about how to perform
the eye-offset and how to clear the Z-buffer.


Top
 Profile  
Reply with quote  
 Post subject: Re: Stereo rendering
PostPosted: 19.06.2009, 20:27 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Your steps are all right. Clearing the depth buffer is done in the pipeline scripts. If you use the sample pipelines, you don't have to take care of that yourself.
You need to set the transformations of the cameras yourself. Just translating the cameras is usually not enough, you should at least rotate them so that they focus a single point. But it is better (more correct) to use an asymmetric frustum instead. Here is a good article that shows the math.


Top
 Profile  
Reply with quote  
 Post subject: Re: Stereo rendering
PostPosted: 11.07.2009, 12:50 
Offline

Joined: 21.12.2008, 23:46
Posts: 23
I got it working and made a wiki article about this:
http://www.horde3d.org/wiki/index.php5?title=Tutorial_-_Stereo_rendering

Would be great if someone could review it.


Top
 Profile  
Reply with quote  
 Post subject: Re: Stereo rendering
PostPosted: 12.07.2009, 09:46 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Thanks for the article, adding such things to the wiki is the way to go :)
There are two things that I noticed: finalizeFrame should just be called once per frame. The other thing is that your camera matrix calculation is not very robust. For correct result, you should really use an asymmetric frustum, as described in the article I mentioned before. It is some basic math, nothing really complicated. Setting the frustum planes can be done with the CameraNodeParams in Horde.


Top
 Profile  
Reply with quote  
 Post subject: Re: Stereo rendering
PostPosted: 12.07.2009, 10:41 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
Thanks a lot for the article.
Additionally to the comment from marciano I would propose to use two camera nodes as a child of one group node. This way you can move around the camera using the group node without having to care about the parallax between the two cameras.


Top
 Profile  
Reply with quote  
 Post subject: Re: Stereo rendering
PostPosted: 12.07.2009, 12:44 
Offline

Joined: 21.12.2008, 23:46
Posts: 23
I have fixed the issue with calling finalizeFrame() too often but calculating the asymmetric frustum can still take some time.
Although the results with the symmetric frustum arent't too bad.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group