java - UV Coords include adjacent Sprite -


my sprites part of uniformed spritesheet, , each sprite drawn pixels on top , right side of quad. seem adjacent sprites. here's how defined uv coords:

ratio = spritecountx / spritecounty;  uvcoords.x = (float)(index % spritecountx) / (float)spritecountx; size.x = ratio / (float)spritecountx;  uvcoords.y = (float)(index / spritecountx) / (float)spritecounty; size.y = 1.0f / (float)spritecounty; 

and vertex data: (x,y,z positions plus uv coords each vertex)

vertexdata[] = {  -size.x / 2,    size.y / 2,   0,  uvcoords.x,                     uvcoords.y,                   -size.x / 2,    -size.y / 2,  0,  uvcoords.x,                     uvcoords.y + size.y,                   size.x / 2,     -size.y / 2,  0,  uvcoords.x + (size.x / ratio),  uvcoords.y + size.y,                   size.x / 2,     size.y / 2,   0,  uvcoords.x + (size.x / ratio),  uvcoords.y} 

the texture filters defined as:

gles20.gltexparameteri(gles20.gl_texture_2d, gles20.gl_texture_min_filter,                 gles20.gl_nearest); gles20.gltexparameteri(gles20.gl_texture_2d, gles20.gl_texture_mag_filter,                 gles20.gl_nearest); 

i've tried adding gl_clamp_to_edgewith no luck:

gles20.gltexparameteri(gles20.gl_texture_2d, gles20.gl_texture_wrap_s,                     gles20.gl_clamp_to_edge); gles20.gltexparameteri(gles20.gl_texture_2d, gles20.gl_texture_wrap_t,                     gles20.gl_clamp_to_edge); 

here's illustration of mean:

enter image description here

this known problem named "texture or pixel bleeding" or "texture atlas edge artifacts". due rounding of coordinates, floating values in interval [0..1].

the solution reduce drastically artifacts introduce pixel padding between sprites. suggest 2 alternative:

  • start here create utility modify existing texture atlas.
  • use sprite sheet editor this create sprite sheet texture padding between sprites of atlas.

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -