I'm trying to map a completly normal texture into a sphere.
I can't change my texture to a wrapped one, so I need to find some mapping function.
This is my vertex shader code:
vec3 north = vec3(0.0, 0.0, 1.0);
vec3 equator = vec3(0.0, 1.0, 0.0);
vec3 northEquatorCross = cross(equator, north);
vec3 vertexRay = normalize(gl_Vertex.xyz);
float phi = acos(vertexRay.z);
float tv = (phi / (PI*tiling));
float tu = 0.0;
if (vertexRay.z == 1.0 || vertexRay.z == -1.0) {
tu = 0.5;
} else {
float ang_hor = acos(max(min(vertexRay.y / sin(phi), 1.0), -1.0));
float temp = ang_hor / ((2.0*tiling) * PI);
tu = (vertexRay.x >= 0.0) ? temp : 1.0 - temp;
}
texPosition = vec2(tu, tv);
its straight from here: http://blogs.msdn.com/coding4fun/archive/2006/10/31/912562.aspx
This is my fragment shader:
color = texture2D(debugTex, texPosition);
As you can see in this screenshot: http://img189.imageshack.us/img189/4695/sphereproblem.png, it shows a crack in the sphere... and this is what I'm trying to fix. (the texture used: http://img197.imageshack.us/img197/56/debug.jpg)
The first comment in the XNA website really fixes the problems using: device.RenderState.Wrap0 = WrapCoordinates.Zero;
But because I don't understand enough about XNA internals, I can't understand what this solves in this particular problem.
Around the web, some have experienced the same, and reported to be about interpolation errors, but because I'm implementing this directly as a fragment shaders (per-pixel/frag), I shouldn't have this problem (no interpolation in the texture uv).
Any info/solution on this?