Volume Rendering with 3D Textures

Hi All–I’m relatively new to OpenGL, and was hoping to get some feedback on my attempt to visualize a 3D medical image using 3D textures. I’ve managed to successfully render 2D images using 2D textures, but am having difficulty making the jump to 3D textures.

I’ve successfully rendered a 2D image using OpenGL, and it runs a bit differently using VAOs/VBOs and compiling shaders at runtime as opposed to the glBegin/glEnd combo used here.

Based off an online tutorial (google: CodeProject Volume Rendering)

I have a 1D RGBA array (“VolumeRGBA”) of size 256x256x256 that corresponds to a 3D volume in memory, and I want to visualize it. I’ve allocated the texture as follows:


#define MAP_3DTEXT( TexIndex, dOrthoSize ) \
            glTexCoord3f(0.0f, 0.0f, ((float)TexIndex+1.0f)/2.0f);  \
        glVertex3f(-dOrthoSize,-dOrthoSize,TexIndex);\
        glTexCoord3f(1.0f, 0.0f, ((float)TexIndex+1.0f)/2.0f);  \
        glVertex3f(dOrthoSize,-dOrthoSize,TexIndex);\
        glTexCoord3f(1.0f, 1.0f, ((float)TexIndex+1.0f)/2.0f);  \
        glVertex3f(dOrthoSize,dOrthoSize,TexIndex);\
        glTexCoord3f(0.0f, 1.0f, ((float)TexIndex+1.0f)/2.0f);  \
        glVertex3f(-dOrthoSize,dOrthoSize,TexIndex);

// Initialize GLFW
// Allocate RGBA array

// Create 3D texture
GLuint tex3D;
glGenTextures(1, &tex3D);
glBindTexture(GL_TEXTURE_3D, tex3D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 256, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, VolumeRGBA);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.1f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

for (float fIndx = -1.0f; fIndx <= 1.0; fIndx=fIndx+0.005)
{
	glBegin(GL_QUADS);
	MAP_3DTEXT(fIndx, 1.0f);
	glEnd();
}


I can get the window open, but perhaps unsurprisingly, it’s a blank screen. So in addition to the fact that I’m clearly missing some conceptual info:

  1. How does this situation change when the volume itself isn’t in dimensions of power of 2? How does 3D texture size compare to 3D volume size?
  2. If I want to eventually have 2D images overlayed on the volume itself (separate images, not just slices of the volume), do I need a uniform set of shaders to handle the two of them?

I know it’s a lot to ask, but any insight would be tremendously helpful to my research.

There can be a lot of reasons for you not seeing your volume rendering. What does your projection and modelview matrices contain? I would also suggest removing alpha testing and just get the plane composite rendering to work first.

For your questions

  1. Modern GPUs can safely handle power of two textures but it is generally preferred to keep the volume to the power of 2. We do so by adding zero padding to volume data.
  2. You will need to set up an additional orthographic projection to render slices of data on top of your volume rendering.

Generally, you can get a lot of useful information from the following references.

Books:

  1. Realtime Volume Graphics (The accompanying website http://www.real-time-volume-graphics.org/ contains a demo application for 3D volume rendering which is worth a look)
  2. OpenGL Development Cookbook (Chapter 7 - https://www.packtpub.com/game-development/opengl-development-cookbook) Contains a more modern implementation OpenGL v 3.3)

Blogs:
Peter Triers blog: http://cg.alexandra.dk/?p=107
Volume Rendering at the little grasshopper: prideout
Graphics Runners blog: Graphics Runner: Volume Rendering 101
My blog: An eye into my World -Tricks, Thoughts, Ideas, Solutions: GPU Volume Rendering

OpenSource Project:
Voreen: http://www.voreen.org/
ImageVis3D: http://www.sci.utah.edu/software/imagevis3d.html
OpenQVis: http://openqvis.sourceforge.net/

Hope this helps.