Sign in to follow this  
casty

How is the spherical environment mappping theory?

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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this