PDA

View Full Version : cut 3d textures

arthas
12-18-2007, 02:15 AM
Hi! I have a 3d texture, i need to "cut" it into slices and render each slice on a quad, and then blend them. i know how to blend, but how can i cut the slices and pass them to the quads?

ZbuffeR
12-18-2007, 02:22 AM
Simply activate the 3d texture, and set the appropriate 3D texture coordinates to your quads.

arthas
12-18-2007, 02:53 AM
question: so for render 3 slices in 3 quads is it enough write something like:

glTexCoord3i(0,0,0); glVertex2f(0,0)
glTexCoord3i(0,1,0); glVertex2f(0,1)
glTexCoord3i(1,1,0); glVertex2f(1,1)
glTexCoord3i(1,0,0); glVertex2f(1,0)

glTexCoord3i(0,0,1); glVertex2f(0,0)
glTexCoord3i(0,1,1); glVertex2f(0,1)
glTexCoord3i(1,1,1); glVertex2f(1,1)
glTexCoord3i(1,0,1); glVertex2f(1,0)

glTexCoord3i(0,0,2); glVertex2f(0,0)
glTexCoord3i(0,1,2); glVertex2f(0,1)
glTexCoord3i(1,1,2); glVertex2f(1,1)
glTexCoord3i(1,0,2); glVertex2f(1,0)

glEnd()

ZbuffeR
12-18-2007, 03:28 AM
That is almost it.
Do not forget that texture coordinates are normalized, that means always in the [0..1] range, whatever the texture size, and even for the Z parameter. If you use linear filtering, a small shift is also needed to avoid sampling from texture borders and between slices.
So change the texcoord like this:

int SLICES = 3;
int i;
float shift = 1.0/SLICES *0.5
for (i=0;i<SLICES;i++) {
float z= shift+((float)i)/SLICES;
...
glTexCoord3f(x,y,z); glVextex x,y ...
...