Stereoscopic (3DVision) rendering with CUDA sample source code included (Visual Studio 2008)

Hello,

This sample code fills two textures using CUDA (like the simpleD3D9Texture sample code), assembles these into a DirectX surface containing the nVidia stereo tag, and finally StretchRects the surface to the DirectX back buffer. All this with high frame rates.

This basic sample code simply displays two distinct 256x256 float textures on both eyes.

This is source code and driver compatible with CUDA SDK 2.3 - and hopefully also 3.0/3.1. Tested with driver 190.38 in 3DVision discover mode on my nVidia 9600M GT equipped laptop. It uses DirectX9 and should thus be backwards compatible to windows XP - except nVidia does not offer 3DVision in current XP drivers ;)

The CUDA Texture, Surface and Screen resolution can be different (e.g. to perform higher resolution renders and display a size-reduced version on screen). In my sample the screen size is 1280x800 (16:10), the surface is in full HD (16:9) and the CUDA textures are 256x256.

Now why would you want to use CUDA for rendering in 3D? Think …

  • make Optix raytrace in 3DVision without the need for expensive Quadro cards
  • Implement your own custom renderer in CUDA (data visualization, voxels etc)
  • Perform image processing on stereoscopic source data, etc…
  • Upconvert video material from 2D to 3D with CUDA
  • and other possibilities I cannot imagine now…

Download now and thank me later. Took me 3 days to puzzle all this together. Maybe it could be done a little simpler (CUDA interoperability with surface instead of textures?) - but hey it works.

I will be rendering Buddhabrot fractals with this in 3D and maybe I will try attaching Optix to this code. Cheers.

Christian

Hi,

I am using your code to render stereoscopic images in my project. Unfortunately I got some weird issues once the pictures are displayed on the screen. You can see my other thread here: http://forums.nvidia.com/index.php?showtopic=191879
Do you know where the problem may come from ?

Thank you and thanks for your code. It is very helpful.

Have you looked at still images of the source material? I suspect that that this could be artifacts of the digital camera that was used for recording (possibly DV video or some digital MPEG 4 AVC video camera)

To create the textures for my two images I proceed like this :

g_stereo_texture_2d.width  = iWidth ;

g_stereo_texture_2d.height = iHeight ;

hr = g_pD3DDevice->CreateTexture(g_stereo_texture_2d.width, g_stereo_texture_2d.height, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &g_stereo_texture_2d.pTexture[0], NULL);

if(hr != S_OK) return E_FAIL ; 

hr = g_pD3DDevice->CreateTexture(g_stereo_texture_2d.width, g_stereo_texture_2d.height, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &g_stereo_texture_2d.pTexture[1], NULL);

if(hr != S_OK) return E_FAIL ;

iWidth and iHeight are respectively the width and height of my images (dimension 720x480). I was wondering if my problem come from the fact that my textures have non-power of two dimensions ?