volume rendering and combiners

I already posted this in the beginner’s forums, but it didn’t seem like the right place for it.

So I’ve made a volume renderer that reads in raw 64x64x64 @ 1byte per voxel data. I store this data in a 3D texture with a GL_ALPHA8 format. I also create a 256x256 2D texture as a lookup table (the type is GL_FLOAT with a GL_RGBA format).

Since the 3D texture is nothing but Alpha values, I use GL_DEPENDENT_AR_TEXTURE_2D_NV as the shader operation for the lookup table. My understanding is that all I have to do after the lookup is combine the RGB and Alpha values in the final combiner. So I have something like this:

glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_D_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_G_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);

Unfortunately, my image looks really washed out:
bad image

After playing around with the combiners, I found something that looks half-way decent

glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glFinalCombinerInputNV(GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_G_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);

The results look pretty good:
good image

So my question is, why did my first attempt produce a lousy result? My next attempt looks nice, but I’m not entirely sure why it works. I’m guessing that it squares the alpha values. I’m also using the over operator for blending, btw. If I can understand what’s going on, it’ll help me when I try to add more advanced features like shading/lighting. I can always post more code if something needs further explaining.

Thanks much - Dave

In the 1st set of combiner code, you’re basically using the same value for A and R (your lookup value).

The final combiner equation is;

fcoc = [ min(ab[r] + iac[r] + D[r], 1.0),
min(ab[g] + iac[g] + D[g], 1.0),
min(ab[b] + iac[b] + D[b], 1.0),
G ]

Where AB is A x B, and IAC is (1-A) x C.

Variable G specifies the alpha. So you’re basically Setting AR to the red and alpha values of the texture.

In the 2nd combiner code the line;

glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_TEXTURE1_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
replicates the alpha value of texture1 across the RGB portion of variable B. From the spec;

When the <variable> parameter is not VARIABLE_G_NV, a
<componentUsage> parameter of RGB indicates that the RGB portion of
the indicated register should be assigned to the RGB portion of the
combiner input variable, while an ALPHA <componentUsage> parameter
indicates that the alpha portion of the indicated register should
be replicated across the RGB portion of the combiner input variable.
G is set the same.

So your AR dependant lookup looks like R = Red*Red, A = Alpha. Giving you a much different texture lookup curve. Of course it depends what your 2d texture data is made up off…

I may be wrong, its 2:15 am… but I think thats all correct;

  • Nutty

Hmmm… I messed around with the values in my color table some. It seems like multiplying the RGB values by A and using the first combiner method produces the same results I was getting with the second combiner method.

I’m starting to get this feeling that I’m not arranging the color table values correctly. Otherwise, this is implying that the second combiner method does (AR) instead of (RR). Now that I take a closer look at my code, it seems like I got my lookups backwards ( A,R to T,S instead of A,R to S,T).

-Dave