# Building Cubemap lookup tables

## Recommended Posts

brtnrdr    202
I'm trying to build lookup tables for each face of a cubemap. I loop over the texels of a 2D texture and have to determine the 3D vector that would index that texel in the cubemap (there is an index that determines what face is currently being worked on. I have looked at the directx documentation and what I have come up with is shown below. Can someone just confirm this makes sense as my program is not working. Here, face follows the directx convention, i.e. face = 0 == xpos, face = 1 == xneg, face = 2 == ypos, face = 3 == yneg, face = 4 == zpos and face = 5 == zneg.
void cubeCoord(D3DXVECTOR3* res, D3DXVECTOR2* tex, int face)
{
D3DXVECTOR3 temp;

switch(face) {
case 0:
temp = D3DXVECTOR3(1.f, -tex->y, -tex->x);
break;
case 1:
temp = D3DXVECTOR3(-1.f, -tex->y, tex->x);
break;
case 2:
temp = D3DXVECTOR3(tex->x, 1.f, tex->y);
break;
case 3:
temp = D3DXVECTOR3(tex->x, -1.f, -tex->y);
break;
case 4:
temp = D3DXVECTOR3(tex->x, -tex->y, 1.f);
break;
case 5:
temp = D3DXVECTOR3(-tex->x, -tex->y, -1.f);
break;
}

D3DXVec3Normalize(&temp, &temp);

res->x = temp.x;
res->y = temp.y;
res->z = temp.z;

}



##### Share on other sites
SimmerD    1210
Is it a fp16 or fp32 cubemap? If not, you will need to convert into d3d colors instead of outputting a d3dxvector3...

##### Share on other sites
brtnrdr    202
Hi,

Thanks for the reply, but I'm not storing vectors in the cubemap. I'm trying to store the spherical harmonic basis functions sampled at the texels of a cubemap. In order to evaluate the functions at a texel I need the 3-vector from the origin to the texel. In order to get this I am iterating over a 2D grid (corresponding to a face of the cubemap) and based on an index (corresponding to one of the six faces) I am calculating the vector used to sample the cubemap (this is the code above that I'm asking about).

I can post more of the code if people need to see more to understand what is going on.

Thank you.