It is currently Sat Dec 14, 2019 10:07 pm



 [ 8 posts ] 
 Developing an OpenGL interlaced stereo 3D driver 
Author Message
One Eyed Hopeful

Joined: Sat Feb 12, 2011 6:18 pm
Posts: 3
I've had a bit of success adding interlaced stereo 3D support to my own OpenGL programs using this (somewhat crude) technique:
  • Clear the scene
  • Use the Z buffer to mask out the odd scan lines
  • Draw the scene from the left eye perspective
  • Use the Z buffer to mask out the even scan lines
  • Draw the scene from the right eye perspective
  • Show the scene

It has some obvious limitations (e.g. falls over if the program switches off Z testing) but so far the results have been promising. It's also easy to switch to anaglyph stereo by using glColorMask to mask out the colour channels instead of masking out scan lines. And it doesn't require any special buffers.

I reckon I could bundle it into a driver if I could intercept a handful of OpenGL functions. But I'm not sure how to do this.
Googling has lead me to "IAT patching" but most of the information is old and I don't want to use a hacky technique that antivirus or Windows UAC would block.

Is there a "right" way to go about this?

Image
Anaglyph Interlaced


Sat Feb 12, 2011 6:47 pm
3D Angel Eyes (Moderator)
User avatar

Joined: Sat Apr 12, 2008 8:18 pm
Posts: 11394
Sounds cool bro. Don't know much about OpenGL myself, but I wish you the best of luck. Did you model that brain creature?

_________________
check my blog - cybereality.com


Sun Feb 13, 2011 12:43 am
One Eyed Hopeful

Joined: Sat Feb 12, 2011 6:18 pm
Posts: 3
cybereality wrote:
Did you model that brain creature?

Nope :). It's from an OpenGL port of the Doom II source code that replaced the flat sprite objects with MD2 models. I don't know who modelled it but it's one of my favourites.


Sun Feb 13, 2011 2:00 am
Petrif-Eyed
User avatar

Joined: Sat Jan 09, 2010 2:06 pm
Posts: 2255
Location: Perpignan, France
It's quite easy to write an OpenGL interposer thanks to the "preload" feature of Linux/Unix systems, but it seems to be a little bit more difficult to do it correctly under Win32. Have a look at this paper titled "Intercepting OpenGL calls for rendering on 3D display" to get you started :
http://liu.diva-portal.org/smash/record ... iva2:21335


Sun Feb 13, 2011 7:35 am
One Eyed Hopeful

Joined: Sat Feb 12, 2011 6:18 pm
Posts: 3
Thanks for that. I feel I have some idea of what the different approaches are now.

I'm sticking with IAT patching for the moment. Although it doesn't work with a lot of programs when it does, the results are encouraging.
Image
FlightGear

I may try the function detour/trampolining approach too.


Thu Feb 17, 2011 5:02 am
Petrif-Eyed
User avatar

Joined: Sat Jan 09, 2010 2:06 pm
Posts: 2255
Location: Perpignan, France
You can also use a texture instead of the Z-buffer to mask the odd or even scanlines, that way you won't be dependant on the use of the Z-buffer. NVIDIA has also published several papers where they explain how they did implement their stereo driver, you can find useful informations there :
http://developer.download.nvidia.com/pr ... nd_Out.pdf
http://http.download.nvidia.com/develop ... Stereo.pdf
http://www.nvidia.com/content/GTC-2010/ ... TC2010.pdf

I also did implement a stereo 3D driver prototype for OpenGL under Linux some time ago, it did only work for anaglyphs but you may find interesting informations inside. You can find the code here :
http://frederic.lopez.free.fr/linux/glstereo-0.1.tar.gz


Thu Feb 17, 2011 6:14 am
Two Eyed Hopeful

Joined: Tue Dec 22, 2009 11:48 am
Posts: 79
tmulgrew> Any news ? Did you manage to do something working ?

I'm interested in your work because I want to continue Fredz' work on glstereo (for Linux) :P

If you have some problems or, if you have some codes to share, don't hesitate ;)

Thanks


Wed Mar 02, 2011 4:05 pm
One Eyed Hopeful

Joined: Tue Jun 25, 2013 11:45 pm
Posts: 41
You should not use "masking" -- that creates aliasing artifacts.



The proper way to implement a stereo wrapper in OpenGL is to do the following:

* Have two textures set up to store the left and right eye screen images, one for the left eye and one for the right eye. They should be "rectangle textures" -- GL_TEXTURE_RECTANGLE -- so that there is no filtering (GL_NEAREST) and the texels are fetched directly.

* Have two renderbuffers set up to store the depth buffers, one for the left eye and one for the right eye. You need separate depth buffers for the left and right eyes because the left and right eye images have to be rendered effectively at the same time.

* Have two framebuffer objects set up, one for the left eye and one for the right eye. Attach the left texture and left depth renderbuffer to the left framebuffer and the right texture and right depth renderbuffer to the right framebuffer. You need separate framebuffers for the left and right eyes because OpenGL only allows one depth buffer per framebuffer.

* Whenever the color buffer and/or depth buffer is cleared, clear the respective buffer(s) in both the left and right framebuffers. Whenever a set of primitives is rendered, render it to both the left and right framebuffers. Use a vertex buffer, even if it's streamed data, so each set of verticies is only transferred to the GPU once. Use a matrix to do the necessary stereo transformation.

* Whenever the front screen buffer is swapped with the back screen buffer, before doing the swap, display the left and right screen textures to the back buffer, using a separate shader program to display it in the proper format (such as interleaved). Have the left and right screen textures bound to separate texture units. If the format requires a lower resolution, use pixel averaging to downscale them. If quad buffering is being used, use multiple render targets to render to both back buffers in one rendering pass. The shader should also do screen shifting (shifting the left and right eye images in opposite directions by the set number of pixels). The scissor test should be used to clip out the parts of the screen images that are out of range after shifting.



Although this requires OpenGL 3 or later, it is the cleanest, most efficient, and most bug-free way of doing it. It also allows the left and right eye images to be rendered at full resolution, and downsampled if necessary with pixel averaging.


Sat Sep 21, 2013 6:46 pm
Display posts from previous:  Sort by  
   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 3 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

Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by STSoftware.