+
+ /* Choose the cube face and compute new s/t coords for the 2D face.
+ *
+ * Use the same cube face for all four pixels in the quad.
+ *
+ * This isn't ideal, but if we want to use a different cube face
+ * per pixel in the quad, we'd have to also compute the per-face
+ * LOD here too. That's because the four post-face-selection
+ * texcoords are no longer related to each other (they're
+ * per-face!) so we can't use subtraction to compute the partial
+ * deriviates to compute the LOD. Doing so (near cube edges
+ * anyway) gives us pretty much random values.
+ */
+ {
+ /* use the average of the four pixel's texcoords to choose the face */
+ const float rx = 0.25 * (s[0] + s[1] + s[2] + s[3]);
+ const float ry = 0.25 * (t[0] + t[1] + t[2] + t[3]);
+ const float rz = 0.25 * (p[0] + p[1] + p[2] + p[3]);