I'm having Problems w/ my Normalizing Cube map..

I just recently started working w/ vertex & fragment programs for Per-pixel lighting, and have come across a curious problem: When using a cube map to normalize the vertex to light and vertex to eye vectors, the results I get are VERY wrong; however, when using math to normalize these vectors, the results are correct (and look a lot better, if I do say so myself :smiley: ).

Anyways, after doing the texture lookup for the normal map and the cube map, I scale both by 2 and add -1. I’ve tried not doing one, or the other, or both, with worse results, hoping that incorrect math was my problem, though w/o success. :confused:

Any help or insights is greatly appreaciated!


Posibly you have a wrong calculated norm cubemap. As I see, You dont’t understand very wel, why you should multiply by 2 and substract 1. A little explaination. Imagagine that texture color can be in range 0 - 1.0 but your normalized vector is in range from -1.0 - 1.0. So you must pack in your normcube creation function the values in range -1.0 - 1.0 to range 0.0 - 1.0. And ofcourse in your FP you must unpack the values in inverse way. The pack function: pack = (unpack + 1) /2 and unpack function: unpack = pack * 2 - 1