Jump to content
  • Advertisement
Sign in to follow this  

Accessing cubemaps on the CPU

This topic is 2782 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

Currently I am looking at inequality tests to see which component has the gretest magnitude then using the sign to determine the

Is there an efficient with no branches, way of selecting the correct face of a cubemap in software from a normalized vector?

Share this post

Link to post
Share on other sites
Off the top of my head, finding the component of the normal with the largest magnitude and then select between the two faces along that axis based on the sign sounds correct.

Not tested://assuming: enum FaceIndex { PosX, NegX, PosY, NegY, PosZ, NegZ }

//if your CPU is more int friendly
int GetFaceIndex( float x, float y, float z )
int xGtY = (int)(x > y);
int xGtZ = (int)(x > z);
int yGtz = (int)(y > z);
int xNeg = (int)(x < 0);
int yNeg = (int)(y < 0);
int zNeg = (int)(z < 0);
int xIsMax = xGtY & xGtZ;
int xIsntMax = ~xIsMax;
int yIsMax = xIsntMax & yGtz;
int yIsntMax = ~yIsMax;
int zIsMax = xIsntMax & yIsntMax;
int index = (xIsMax * xNeg) + (yIsMax * (2+yNeg)) + (zIsMax * (4+zNeg));
return index;

//if your CPU has fsel and is more float friendly
float GetFaceIndex( float x, float y, float z )
float xGtY = fsel(x - y, 0, 1);
float xGtZ = fsel(x - z, 0, 1);
float yGtz = fsel(y - z, 0, 1);
float xNeg = fsel(x, 1, 0);
float yNeg = fsel(y, 1, 0);
float zNeg = fsel(z, 1, 0);
float xIsMax = xGtY * xGtZ;
float xIsntMax = 1-xIsMax;
float yIsMax = xIsntMax * yGtz;
float yIsntMax = 1-yIsMax;
float zIsMax = xIsntMax * yIsntMax;
float index = (xIsMax * xNeg) + (yIsMax * (2+yNeg)) + (zIsMax * (4+zNeg));
return index;

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!