Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to extract the one pixel from a environment mapping (I already have the 6 textures) using the normal vector. How can I achieve this ?

I want something very similar to what texCUBE(link) does in GPU but in CPU.

I am using XNA and C#, but an example in any language may help.

share|improve this question

Someone answered in another forum - the original post is here:

The largest component of the normal vector tells you which face it intersects. Next divide the normal vector by the absolute value of the largest component. Then scale and shit the other two components into the usual range for uvs ([0, 1] on each axis).

For example if you had the vector <-3, -1, 2>.

First it intersects the negative x face. Then

<-3, -1, 2> / |-3| = <-1, -1/3, 2/3>.

Finally just scale the remaining two components from [-1, 1] to [0, 1], <-1/3, 2/3> * 0.5 + 0.5 = <2/3, 5/6>. And similarly for each other face.

share|improve this answer
Please mark this answer as correct when you're able, if it answered your question. – doppelgreener Apr 15 '12 at 12:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.