Developing an OpenGL interlaced stereo 3D driver

Post Reply
tmulgrew
One Eyed Hopeful
Posts: 3
Joined: Sat Feb 12, 2011 6:18 pm

Developing an OpenGL interlaced stereo 3D driver

Post by tmulgrew »

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
User avatar
cybereality
3D Angel Eyes (Moderator)
Posts: 11406
Joined: Sat Apr 12, 2008 8:18 pm

Re: Developing an OpenGL interlaced stereo 3D driver

Post by cybereality »

Sounds cool bro. Don't know much about OpenGL myself, but I wish you the best of luck. Did you model that brain creature?
tmulgrew
One Eyed Hopeful
Posts: 3
Joined: Sat Feb 12, 2011 6:18 pm

Re: Developing an OpenGL interlaced stereo 3D driver

Post by tmulgrew »

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.
User avatar
Fredz
Petrif-Eyed
Posts: 2255
Joined: Sat Jan 09, 2010 2:06 pm
Location: Perpignan, France
Contact:

Re: Developing an OpenGL interlaced stereo 3D driver

Post by Fredz »

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" onclick="window.open(this.href);return false;
tmulgrew
One Eyed Hopeful
Posts: 3
Joined: Sat Feb 12, 2011 6:18 pm

Re: Developing an OpenGL interlaced stereo 3D driver

Post by tmulgrew »

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.
User avatar
Fredz
Petrif-Eyed
Posts: 2255
Joined: Sat Jan 09, 2010 2:06 pm
Location: Perpignan, France
Contact:

Re: Developing an OpenGL interlaced stereo 3D driver

Post by Fredz »

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" onclick="window.open(this.href);return false;
http://http.download.nvidia.com/develop ... Stereo.pdf" onclick="window.open(this.href);return false;
http://www.nvidia.com/content/GTC-2010/ ... TC2010.pdf" onclick="window.open(this.href);return false;

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" onclick="window.open(this.href);return false;
magestik
Two Eyed Hopeful
Posts: 79
Joined: Tue Dec 22, 2009 11:48 am

Re: Developing an OpenGL interlaced stereo 3D driver

Post by magestik »

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
Matthew
One Eyed Hopeful
Posts: 41
Joined: Tue Jun 25, 2013 11:45 pm

Re: Developing an OpenGL interlaced stereo 3D driver

Post by Matthew »

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

Return to “General Stereoscopic 3D Discussion”