Jump to content
  • Advertisement
Sign in to follow this  
brtnrdr

Building Cubemap lookup tables

This topic is 4186 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post


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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!