Hi, I would like to mimic GL_SHPERE_MAP with GLSL but I cannot manage to have it right.

This is my shader:

[b][Vertex]

varying vec2 texCoord;

varying vec4 color;

void main()

{

gl_Position = ftransform();

```
vec3 u = normalize(gl_ModelViewMatrix * gl_Vertex);
vec3 n = gl_NormalMatrix * gl_Normal;
vec3 r = reflect(u, n);
//r.z += 1.0;
float m = 1.0 / 2.0 * sqrt(dot(r,r));
texCoord.s = r.x * m + 0.5;
texCoord.t = r.y * m + 0.5;
```

}

[Fragment]

uniform sampler2D EnvMap;

uniform vec4 ReflectionColor = {1,1,1,1};

varying vec2 texCoord;

void main()

{

gl_FragColor = ReflectionColor * texture2D(EnvMap, texCoord);

}[/b]

I read the glTexGen documentation, but the z+1 didnâ€™t help. Results are not the same as with the fixed pipeline.

Any help will be appreciated.