# 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.

## 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 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; }

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013596
×