Slick Forums

Discuss the Slick 2D Library
It is currently Sat Feb 23, 2019 12:52 am

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Wed Mar 16, 2011 12:46 am 
Offline

Joined: Fri Mar 11, 2011 12:45 am
Posts: 8
Image

At certain non-whole-pixel translations, I'm seeing terrible seams in TiledMap. I believe the root cause is due to Image.getSubImage's texture coordinates being on texel borders, rather than in the centers of texels. This would also manifest itself in anything else using SpriteSheet, or subImages, but I see it quite glaringly in TiledMap.

The reason the seams are white for me is due to the texture wrapping, and the opposite edge of the texture being white.

Ultimately, all that should be solvable by putting a few half-texel offsets into the rendering code in Image.java... Maybe in drawEmbedded() ~line 523 or so...

Code:
  float texelHalfWidth = (1 / textureWidth) / 2;
  float texelHalfHeight = (1 / textureHeight) / 2;

  GL.glTexCoord2f(textureOffsetX + texelHalfWidth, textureOffsetY + texelHalfHeight);
  GL.glVertex3f(x, y, 0);
  GL.glTexCoord2f(textureOffsetX + texelHalfWidth, textureOffsetY + textureHeight - texelHalfHeight);
  GL.glVertex3f(x, y + height, 0);
  GL.glTexCoord2f(textureOffsetX + textureWidth - texelHalfWidth, textureOffsetY
    + textureHeight - texelHalfHeight);
  GL.glVertex3f(x + width, y + height, 0);
  GL.glTexCoord2f(textureOffsetX + textureWidth - texelHalfWidth, textureOffsetY + texelHalfHeight);
  GL.glVertex3f(x + width, y, 0);


I would try the change myself, but I'm extremely new to Java and especially Slick, so I'm completely clueless as to how to build Slick myself. :)

Thoughts? This would certainly fix my problem, though I can't be sure it wouldn't cause knock-ons for others. Integers and floating points never play well together. :roll:


Last edited by apocriva on Thu Mar 17, 2011 2:04 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2011 10:17 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
You need to change your filtering on the tileset image to use NEAREST.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2011 1:35 pm 
Offline

Joined: Fri Mar 11, 2011 12:45 am
Posts: 8
I can't check at the moment, but I thought that the TiledMap loader, when loading tilesets automatically, was already setting the filter to NEAREST. The tiles certainly appear to be using NEAREST to me, even if it's not evident from the little screengrab.

In any event, I'll give that a shot tonight.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2011 1:57 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
in my project the TiledMaps are correct...

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2011 6:33 pm 
Offline

Joined: Fri Mar 11, 2011 12:45 am
Posts: 8
I don't see the issue as long as all the pixel offsets are nice round numbers. If my matrix stack has a scale and translation in it that are non-integral, I see the seams. I don't see them all the time -- but as I slide through a floating point translation for map scrolling, the seams flicker on and off.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2011 1:45 am 
Offline

Joined: Fri Mar 11, 2011 12:45 am
Posts: 8
Well, I'm pretty sure that I just won't be able to use translation/scaling the way I wanted to.

This is really bad!

It appears to just be a texture rounding error, and I am totally at a loss for what to do about it. I can't really be rendering things pixel-perfect and still be able to scale nicely... I'm just using g.scale() right now to zoom in.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2011 2:04 am 
Offline

Joined: Fri Mar 11, 2011 12:45 am
Posts: 8
I'm getting around this issue by putting spacing between the sprites in my spritesheets. It feels gross, but it works.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 23, 2011 11:35 am 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
I declare this as a bug now too.
For something like "fading out" to a point of the map this gives you the seams.

I will try it with putting space between the tiles...

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 23, 2011 11:44 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Can you knock together a little example of the issue you're seeing. All the demos/tests work without seams.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 23, 2011 12:26 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Jepp, here we go:
http://npshare.de/files/e09fc0ae/Seam.zip

Use up and down to change the y translate. At 0.0499999 or soyou can se the seams.

It might help to use a round value for the translate...

EDIT:
It's ALWAYS at x.49999997.

EDIT:
okay it seems that it also happens with x.50000000000000 values.
Workarround:
Code:
g.translate(-round(pos.x), -round(pos.y));

...

public int round(float value) {
      if(value < 0)
         return (int)(value - 0.5f);
      else
         return (int)(value + 0.5f);
      
}


_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 25, 2011 11:44 pm 
Offline

Joined: Fri Mar 11, 2011 12:45 am
Posts: 8
My major issue has been since I scale up everything using a g.scale (doing things in a 16-bit style, so I likes me some chunky pixels!), even if I have whole-number g.translate values, I'm still getting rounding errors on certain resolutions. That's really the root of my problems -- everything'll look fine on my monitor, but when I try on another that has a different native resolution, I get seams.

Ultimately, putting a buffer around my tiles has solved the issue without a great deal of headache for me, so I've been concerning myself with other things. It could very well just be a rounding issue at the hardware level, and I refuse to stress myself out over hardware. :) hehe


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group