Jump to content


Texture seams


10 replies to this topic

#1 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 05 December 2008 - 01:10 PM

Hi,
I'm trying to ask a strange question!
Ok, suppose that I've a model and I draw it, after drawing, I read the frame buffer and I save the data on a image, and suppose that, I write the projected vertices of each triangle on a text file.
Now I can load the originale model (without textures), and texture it with the precedent image, the texture coordinates are the values stored in the text file.
It's clear?
Now, suppose that I would reorganize this image in another image, for example map each triangle to a right angle triangle. I post some images, to be more clear.
The original image, in practice is a "photo" of my model:
Posted Image
If I use the values stored in the text file, and this image, I can texture the original model with this image. Obviously the camera is in the same position and with the same parameters.
Now I would reorganize this image, so I map each triangle on a right angle triangle. I.e. construct a set of 34 right angle triangle, and use as texture coordinates, the values stored in the text file.
The result is this:
Posted Image
At this step, another text file is wrote, with the coordinates of this image.
Suppose that we take the original model (without textures) and we want to texture this model with this last image.
The result is this:
Posted Image
The result is "correct". Why I've quoted correct? Because there is a black line between the two triangles. You can see that, in the original image, this line doesn't exist.
It's like an a black line of pixels that are read. But for me the values stored in the text file, are correct.
For you, where is the problem?
Thanks.

#2 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 05 December 2008 - 03:40 PM

hmm, well I'm not totally sure, but one thing I would try on the file that stores the texture is to fill in the black area with red or green, and then load it to see if you have a small offset or there is another, different, problem.

I don't remember %100 clearly, but I belive a while back I saw about 2 articles that stated the DirectX texture coordinates were one pixel off (they never explained why though). Also, are you using DX or GL? Because that could make a difference.

cool idea though.
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#3 imerso

    Senior Member

  • Members
  • PipPipPipPip
  • 428 posts
  • LocationBrasil

Posted 05 December 2008 - 05:02 PM

Yes, great suggestions above.

Also, if you are doing rasterization by yourself, try reading about rasterization "Fill Conventions", it may (or may not) be related to your problem.

If for instance it is related to fill conventions, you may wish to read this discussion here: http://www.devmaster...read.php?t=6629

#4 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 05 December 2008 - 06:07 PM

starstutter said:

hmm, well I'm not totally sure, but one thing I would try on the file that stores the texture is to fill in the black area with red or green, and then load it to see if you have a small offset or there is another, different, problem.
It's a great suggestion. I've modifyed the texture with two different colors:
Posted Image
and this is the result, after texturing:
Posted Image
You can see that there are two different lines, one red and one green

starstutter said:

Also, are you using DX or GL? Because that could make a difference.
I'm using OpenGL.
Thanks.

#5 Goz

    Senior Member

  • Members
  • PipPipPipPip
  • 574 posts

Posted 05 December 2008 - 11:03 PM

Are you using the half texel offset? ie adding 1.0f / texWidth to each u,v coord?

#6 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 06 December 2008 - 02:52 AM

Goz said:

Are you using the half texel offset? ie adding 1.0f / texWidth to each u,v coord?
AH! Yes! Can't belive I forgot about that. It's a common problem with seeminly any system. To fix, you should say:
UV += 1.0f / (textureSize * 2.0f);
before any textures are applied. This problem is quite frequent when trying to align things perfectly.
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#7 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 06 December 2008 - 09:27 AM

starstutter said:

AH! Yes! Can't belive I forgot about that. It's a common problem with seeminly any system. To fix, you should say:
UV += 1.0f / (textureSize * 2.0f);
before any textures are applied. This problem is quite frequent when trying to align things perfectly.
I've tried, and this is the result:
Posted Image
the red line is inverted. I don't understand.
I will spend two words on my code, to check if is correct.
The texture images is generated with the orthographic camera, with these parameters:

glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f);

and the projected vertices, of the triangles, are calculated in this manner:

PM; //Projection matrix from glGetDoublev(GL_PROJECTION_MATRIX, ...);

MM;//Modelview matrix from glGetDoublev(GL_MODELVIEW_MATRIX, ...);

double tm[16] = {(0.5 * 1.0), 0.0, 0.0, 0.0, 0.0, (0.5 * 1.0), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, (0.5 * 1.0), (0.5 * 1.0), 0.0, 1.0};


v1O; //Vertex in homogeneous coordinates


v1O = tm * PM * MM * v1O;

v1O.perspectiveDivision();


v1O.x; //Is the u value

v1O.y; //Is the v value

And following your suggestion, before texturing I've made this:

u += 1.0f/(1024 * 2.0f);

v += 1.0f/(1024 * 2.0f);

The result of this procedure is the image above, the two lines are already present, but the red line is inverted.
Thanks for help and for patience.

#8 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 06 December 2008 - 05:44 PM

hmmm, well the red line is no doubt inverted by the texture corrdinates wrapping around to one of the other sides of the texture where it would see red. To test this, you should set both texture addresses to "clamp" and see if you can still make the lines appear on both sides (and if you can then I'm stumped about what's going on).

If both lines should disappear after doing this, don't take this as a solution, because it may work for now, but I think you know it would come back to haunt you later. I think the core problem is the texture is simply too small for the coordinates. Try increasing the "photo's" size one or two pixels when you save it (preferably try one first).

Either that or you can do a quick test by downscaling the texture coordinates, thereby enlarging the image in the shader
UV *= (texsize - (1.0f / texsize)) / texsize;
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#9 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 07 December 2008 - 11:24 PM

starstutter said:

hmmm, well the red line is no doubt inverted by the texture corrdinates wrapping around to one of the other sides of the texture where it would see red. To test this, you should set both texture addresses to "clamp" and see if you can still make the lines appear on both sides (and if you can then I'm stumped about what's going on).

If both lines should disappear after doing this, don't take this as a solution, because it may work for now, but I think you know it would come back to haunt you later.
If I use "GL_CLAMP" parameter, the red line disappear, but the green diagonal line is present.

starstutter said:

I think the core problem is the texture is simply too small for the coordinates. Try increasing the "photo's" size one or two pixels when you save it (preferably try one first).
I don't understand this point, what do you mean?

starstutter said:

Either that or you can do a quick test by downscaling the texture coordinates, thereby enlarging the image in the shader
UV *= (texsize - (1.0f / texsize)) / texsize;
Tried this, but the result is the same, the two lines are present.
Thanks.

#10 Reedbeta

    DevMaster Staff

  • Administrators
  • 4968 posts
  • LocationBellevue, WA

Posted 07 December 2008 - 11:55 PM

What if you use clamp-to-edge? (GL_CLAMP_TO_EDGE or GL_CLAMP_TO_EDGE_EXT)
reedbeta.com - developer blog, OpenGL demos, and other projects

#11 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 08 December 2008 - 12:07 AM

Reedbeta said:

What if you use clamp-to-edge? (GL_CLAMP_TO_EDGE or GL_CLAMP_TO_EDGE_EXT)
I obtain the same result: only the green line is present.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users