# How is the spherical environment mappping theory?

This topic is 3794 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I was trying to implement an spherical environment mapping shader from scratch. The basic principle was to calculate the reflection vector and to use its x and y coordinates to index the reflection texture with this formula. coord.x = reflection.x * 0.5 + 0.5; coord.y = reflection.y * 0.5 + 0.5; * 0.5 because reflection.x is between -1 and 1 + 0.5 to center the texture. The problem was when z coordinate went negative, causing the reflection to be as reflecting an sphere with a planar projection instead of a cube map. Then, I followed this tutorial which worked great: http://www.ozone3d.net/tutorials/glsl_texturing_p04.php Which says you have to divide the coordinates by 'm' where 'm' is: float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) ); As I understand, m is the double of the module of the vector from the origin to the reflected point by translating the reflection sphere to (0,0,1). I suppose that the "2.0*" is the same than my "*0.5". But I don't know what the rest of the formula is based on. Is there any documentation available? Thanks!

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
15
5. 5

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

• Total Topics
633743
• Total Posts
3013644
×