interpolation woes!

http://www.cuteandcuddlypet.com.au/moogie/textureproblem.png

Woe is me :stuck_out_tongue:

I have been battling with implementing textures on to spheres but have hit problem in my implementation. There seems to be a ring on the sphere which is not part of the texture.

Originally I assumed that it is due the discontinuity of the arctan function which causes this artifact when texturing. however many hours later it was suggested that it could be an artifact of interpolation of the texture co-ordinates of the corners of a quad where texure wraps around to the start again.

This seems to have been the problem as soon as i removed interpolation the seam disappears.

I need to some how modify the texture coordinates of each corner such that they are in the same range.

How does one do that? I have code which can detect the edge of the texture and i have thought about adding 1.0 to the offending texture coordinate(s) however this can potentially lead to other corners now being out of the valid interoplation range…

I have attempted to detect when a seam is within a quad and modify the offending coordinates so that when interpolated they are vaild, however changing one corner texture coordinate can lead to other corners now being out of range and so forth.

So i have had to check each corner against each other corner modfiying the offending coordinates as i go. It works now… however this seems horribly inefficent. is there a better/ faster way?

here is my current code which detects and modifys the offending coordinates for interpolation:


// check for texture wrap around 

// check top left
temp=tx00-tx01;
if (temp>=0.5)
{
	++tx01;
}
else if (temp<=-0.5)
{
	++tx00;
}

temp=tx00-tx10;
if (temp>=0.5)
{
	++tx10;
}
else if (temp<=-0.5)
{
	++tx00;
}

temp=tx00-tx11;
if (temp>=0.5)
{
	++tx11;
}
else if (temp<=-0.5)
{
	++tx00;
}

// check bottom left
temp=tx01-tx00;
if (temp>=0.5)
{
	++tx00;
}
else if (temp<=-0.5)
{
	++tx01;
}

temp=tx01-tx10;
if (temp>=0.5)
{
	++tx10;
}
else if (temp<=-0.5)
{
	++tx01;
}

temp=tx01-tx11;
if (temp>=0.5)
{
	++tx11;
}
else if (temp<=-0.5)
{
	++tx01;
}


// check bottom right
temp=tx11-tx01;
if (temp>=0.5)
{
	++tx01;
}
else if (temp<=-0.5)
{
	++tx11;
}

temp=tx11-tx10;
if (temp>=0.5)
{
	++tx10;
}
else if (temp<=-0.5)
{
	++tx11;
}

temp=tx11-tx00;
if (temp>=0.5)
{
	++tx00;
}
else if (temp<=-0.5)
{
	++tx11;
}


// check top right
temp=tx10-tx01;
if (temp>=0.5)
{
	++tx01;
}
else if (temp<=-0.5)
{
	++tx10;
}

temp=tx10-tx00;
if (temp>=0.5)
{
	++tx00;
}
else if (temp<=-0.5)
{
	++tx10;
}

temp=tx10-tx11;
if (temp>=0.5)
{
	++tx11;
}
else if (temp<=-0.5)
{
	++tx10;
}


where:
tx00 is the U coordinate of the top left corner
tx10 is the U coordinate of the top right corner
tx01 is the U coordinate of the bottom left corner
tx11 is the U coordinate of the bottom right corner