Jump to content
  • Advertisement
Sign in to follow this  
_WeirdCat_

Texturing problem - weird swap

This topic is 1525 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

mek.jpg

Image shows 9 slices of mesh when i try to texture each segment and i hit the boundary (x = dimension) or y = dimension

i get somehow a swap, you can clearly see this on the top right slice when at the bottom of it you see blue line of water (between land)

 

 

heres a sample of a texture (its not a texture form the image) but this faulty texturing occurs on every mesh (whatever texture i use) (i just cant remember where i was to obtain the texture in topright segment-)

SECTOR_0-21.jpg

 

 

as you can see theres no blue line at the bottom (dont mind for left right sides line its the same algorithm for that)

 

 

now the texture has a dimension 2x larger than a mesh (mesh has 120x120 pixels, texture has 240x240)

 

no when i create a mesh i do something like this:

 

for y to 120

for x to 120

{

create_4_vertices_from_the_mesh_heightmap (each (x y) (x+1,y), (x+1 y+1), (x, y+1) )

} so i basically make 4 verts out of every pixel

 

then i texture it by 







float fdim = 120.0f;
float fpy;
float fpx;
for (y=0; y < 120; y++)
for (x=0; x < 120; x++)
{

fpx = float(x);
fpy = float(y);

totalindex = totalindex + 1;
hmodel->VBO_T[totalindex] = float2textpoint(fpx/fdim,              (fdim-fpy) / fdim);

totalindex = totalindex + 1;
hmodel->VBO_T[totalindex] = float2textpoint((fpx+1.0f) / fdim,     (fdim-fpy) / fdim);

totalindex = totalindex + 1;
hmodel->VBO_T[totalindex] = float2textpoint((fpx+1.0f) / fdim,     (fdim-(fpy+1.0f)) / fdim);

totalindex = totalindex + 1;
hmodel->VBO_T[totalindex] = float2textpoint(fpx / fdim,            (fdim-(fpy+1.0f)) / fdim);
}

please help ;]

Edited by WiredCat

Share this post


Link to post
Share on other sites
Advertisement

I am sorry, I know this isn't relevant, but it is necessary...

LD73l2r.jpg

Edited by dsm1891

Share this post


Link to post
Share on other sites

It looks like you are either using repeating texture coordinates (with tri/bilinear interpolation), or you are simply reading outside your own texture (also because of interpolation).

 

Google keywords: texture bleeding

 

Some explanations:

http://hacksoflife.blogspot.no/2009/12/texture-coordinate-system-for-opengl.html

http://jfix.by/2013/02/23/opengl-filters/

 

And a zillion others :)

The "problem" itself is just a result of how linear interpolation samples nearby pixels.

 

Solutions include, but not limited to:

1. Using clamping (GL_CLAMP_TO_EDGE)

2. Have your texture coordinates well inside a sub-image on a texture atlas (watch out for mipmapping issues)

3. Use texture 2D arrays (need to be square sized)

4. Use shader magic to avoid sampling outside of image, or centroid sampling (centroid not recommended)

Share this post


Link to post
Share on other sites

indeed thanks for the info i solved it you pointed me to use gl_clamp_to_edge and that was the milestone in the research i just looked at 

 

https://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexParameter.xml

 

all i had to do was:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!