   Manual cube texture sampling
  Im writing a simple image manipulation class, and at the moment I am writing various functions that allow one to sample a color from the image. Iv got the 2D image and 3D image cases working just fine, but Im stuck on cube images. Obviously in a shader, you can sample from a cube texture using a 3D vector.Now, im pretty sure that the hardware doesnt actually use this 3D vector directly. I figure that it probably figures out which face its pointing at, then figures out UV coordinates to sample from the face. How might this conversion from (3D sampling vector -> 2D UV coords. & face) work? Does hardware blend between two/three faces? (for example when the sampling vector is (1, 1, 1))Thanks,Chris   
  I believe it uses the largest component to determine which face to sample from, and then scales the other two components to the [0,1] range to come up with the 2D UV coordinates.  At least I *think* this is how it works.   ;  Ripped directly from my own code, this function returns the face index (matches OpenGL's enumeration of faces), and retunrs the s and t coordinates by reference (already scaled to the range [0,1]). This almost matches the OpenGL spec, except that my t coordinate may run the opposite way. The manual page for the OpenGL Cubemap extension provided the face orientations.int CubeCacheModule::GetCubeFace(const vector3f &v, float &s, float &t) const{float _c[6] = { v.x,-v.x, v.y,-v.y, v.z,-v.z,};float _s[6] = {-v.z, v.z, v.x, v.x, v.x,-v.x,};float _t[6] = {-v.y,-v.y, v.z,-v.z,-v.y,-v.y,};int max = 0;for (int i = 1; i < 6; i++) {if (_c > _c[max])max = i;}s = _s[max]/(_c[max]*2) + 0.5;t = _t[max]/(_c[max]*2) + 0.5;return max;};  thanks for the snippet swift, works perfectly :)   