I have some problems with sphere map texturing in webgl.
My texture:
Now I texturize a sphere. Everything is OK, if the sphere is in front of the camera:
The sphere is a unit-sphere (r = 1), defined with longitudes and latitudes.
But i get some artefacts, if i translate the sphere in x-direction -2.5 (without rotating the camera):
This image is without mipmapping. And the following image is with mipmapping:
Vertices and normals seems to be ok.
vertex-shader:
precision highp float;
uniform mat4 mvMatrix; // Matrix zum Transformieren des Verex vom model-space in den view-space
uniform mat4 mvpMatrix; // Matrix zum Transformieren des Vertex vom model-space in den clip-space
uniform mat3 mvNMatrix; // Matrix zum Transformieren der Vertex-Normale vom model-space in den view-space
attribute vec4 mV; // Vertex im model-space
attribute vec3 mVN; // Vertex-Normale im model-space
varying vec2 vN;
void main(void)
{
vec3 e = normalize( vec3( mvMatrix * mV ) );
vec3 n = normalize( mvNMatrix * mVN );
vec3 r = reflect( e, n );
//float d = dot(n, e);
//vec3 r = e - 2.0 * d * n;
float m = 2.0 * sqrt(
pow( r.x, 2.0 ) +
pow( r.y, 2.0 ) +
pow( r.z + 1.0, 2.0 )
);
vN.s = r.x / m + 0.5;
vN.t = r.y / m + 0.5;
gl_Position = mvpMatrix * mV;
}
And fragment shader:
precision highp float;
uniform sampler2D uSampler;
varying vec2 vN;
void main(void)
{
vec3 base = texture2D( uSampler, vN ).rgb;
gl_FragColor = vec4( base, 1.0 );
}
Does anybody know, why i get these artefacts? I am working with windows and firefox.