gunslinger

02-20-2004, 12:38 AM

hello,

i am studing a bit the problem of displacement texture mapping. I am looking at the "frustum DisplacementTexture" demo, and i am having hard time understandig how does the lookup cubemap actually works.

I understand that usually it is useful to have precomputted normals cranked into a cube map, just to make normalizations on the fly...

If you have a minute i'll show my questions http://www.opengl.org/discussion_boards/ubb/smile.gif

Now the displacement texture is somehow created as a 3D texture. First question: a 3D texture is just a texture with more than one layer, isn't it? 4 example, if i had a piece of wood cutted i should see the wood color even in the section, right?

More questions here: now the lookuptex is created like:

//looking how to map the vector into the x,y texel

vec3 DisplacementTexture::getCubeVector(int i,int size,int x,int y) {

//QUESTION1: NOW,HERE IN THE CUBE MAP AM I WORKING IN

//WORLD OR TEXTURE SPACE COORDS?

//QUESTION2: WHY DO I SUM .5 TO THE X AND Y COORDS?

float s = ((float)x + 0.5) / (float)size * 2.0 - 1.0;

float t = ((float)y + 0.5) / (float)size * 2.0 - 1.0;

vec3 v;

switch(i) {

//QUEST3: THIS IS JUST A USUAL NORMALIZATION CUBE MAP, ISN'T IT?

case 0: v = vec3(1.0,-t,-s); break;

case 1: v = vec3(-1.0,-t,s); break;

case 2: v = vec3(s,1.0,t); break;

case 3: v = vec3(s,-1.0,-t); break;

case 4: v = vec3(s,-t,1.0); break;

case 5: v = vec3(-s,-t,-1.0); break;

}

v.normalize();

return v;

}

//MAIN CREATION LOOP

for(int i = 0; i < 6; i++) {

unsigned char *d = data;

for(int y = 0; y < size; y++) {

for(int x = 0; x < size; x++) {

//QUESTION4: HERE AM I IN WORLD OR TEXTURE COORDS?

vec3 dir = getCubeVector(i,size,x,y);

//QUES5: WHY VEC HOLDS JUST X AND Y COORDS? I AM LOOKING INTO A CUBE MAP, SO I SHOULD HAVE DIFFERENT CASES -> CONSANT Z=0????

vec3 vec(dir.x,dir.y,0);

vec.normalize();

//QUEST6: THIS VEC3 (010) POINTS TO THE "UP" DIRECTION OF OGL OR IS JUST THE STANDARD NORMAL OF THE SURFACE??? IN THIS CASE ISN'T Z THE VALUE I NEED (X=S,Y=T,Z=NORMAL)? WHAT DOES H REPRESENTS?

float h = acos(vec3(0,1,0) * vec) / (2.0 * PI);

if(vec.x < 0) h = 1.0 - h;

//WHAT DOES V REPRESENTS?

float v = acos(dir * vec) / PI;

//I GUES 255 IS NEEDED JUST TO PACK THE VALUES CORRECTLY INTO A TEXTURE OBJECT...

*d++ = (unsigned char)((h / (float)vertical + (int)(v * vertical) * 1.0 / (float)vertical) * 255.0);

*d++ = (unsigned char)((h / (float)vertical + ((int)(v * vertical) + 1) * 1.0 / (float)vertical) * 255.0);

*d++ = (unsigned char)((v * (float)vertical - (int)(v * vertical)) * 255.0);

}

}

glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,0,GL_RGB,size,size,0,GL_RGB,GL_UNSIGNED_BYTE,dat a);

}

this is more or less all, sorry if my questions seems too lame, but i am really a bit stuck on this thing...

thanks 4 the help

the gunslinger

i am studing a bit the problem of displacement texture mapping. I am looking at the "frustum DisplacementTexture" demo, and i am having hard time understandig how does the lookup cubemap actually works.

I understand that usually it is useful to have precomputted normals cranked into a cube map, just to make normalizations on the fly...

If you have a minute i'll show my questions http://www.opengl.org/discussion_boards/ubb/smile.gif

Now the displacement texture is somehow created as a 3D texture. First question: a 3D texture is just a texture with more than one layer, isn't it? 4 example, if i had a piece of wood cutted i should see the wood color even in the section, right?

More questions here: now the lookuptex is created like:

//looking how to map the vector into the x,y texel

vec3 DisplacementTexture::getCubeVector(int i,int size,int x,int y) {

//QUESTION1: NOW,HERE IN THE CUBE MAP AM I WORKING IN

//WORLD OR TEXTURE SPACE COORDS?

//QUESTION2: WHY DO I SUM .5 TO THE X AND Y COORDS?

float s = ((float)x + 0.5) / (float)size * 2.0 - 1.0;

float t = ((float)y + 0.5) / (float)size * 2.0 - 1.0;

vec3 v;

switch(i) {

//QUEST3: THIS IS JUST A USUAL NORMALIZATION CUBE MAP, ISN'T IT?

case 0: v = vec3(1.0,-t,-s); break;

case 1: v = vec3(-1.0,-t,s); break;

case 2: v = vec3(s,1.0,t); break;

case 3: v = vec3(s,-1.0,-t); break;

case 4: v = vec3(s,-t,1.0); break;

case 5: v = vec3(-s,-t,-1.0); break;

}

v.normalize();

return v;

}

//MAIN CREATION LOOP

for(int i = 0; i < 6; i++) {

unsigned char *d = data;

for(int y = 0; y < size; y++) {

for(int x = 0; x < size; x++) {

//QUESTION4: HERE AM I IN WORLD OR TEXTURE COORDS?

vec3 dir = getCubeVector(i,size,x,y);

//QUES5: WHY VEC HOLDS JUST X AND Y COORDS? I AM LOOKING INTO A CUBE MAP, SO I SHOULD HAVE DIFFERENT CASES -> CONSANT Z=0????

vec3 vec(dir.x,dir.y,0);

vec.normalize();

//QUEST6: THIS VEC3 (010) POINTS TO THE "UP" DIRECTION OF OGL OR IS JUST THE STANDARD NORMAL OF THE SURFACE??? IN THIS CASE ISN'T Z THE VALUE I NEED (X=S,Y=T,Z=NORMAL)? WHAT DOES H REPRESENTS?

float h = acos(vec3(0,1,0) * vec) / (2.0 * PI);

if(vec.x < 0) h = 1.0 - h;

//WHAT DOES V REPRESENTS?

float v = acos(dir * vec) / PI;

//I GUES 255 IS NEEDED JUST TO PACK THE VALUES CORRECTLY INTO A TEXTURE OBJECT...

*d++ = (unsigned char)((h / (float)vertical + (int)(v * vertical) * 1.0 / (float)vertical) * 255.0);

*d++ = (unsigned char)((h / (float)vertical + ((int)(v * vertical) + 1) * 1.0 / (float)vertical) * 255.0);

*d++ = (unsigned char)((v * (float)vertical - (int)(v * vertical)) * 255.0);

}

}

glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,0,GL_RGB,size,size,0,GL_RGB,GL_UNSIGNED_BYTE,dat a);

}

this is more or less all, sorry if my questions seems too lame, but i am really a bit stuck on this thing...

thanks 4 the help

the gunslinger