PDA

View Full Version : Pixel-perfect accuracy


soniCron
04-10-2007, 04:29 PM
To anyone that uses a hardware accelerated 2D engine: does it sport pixel-perfect display accuracy in every circumstance? I'm having trouble getting sprites of odd width or height to display perfectly in my home-spun engine. I pack sprites onto shared textures, so the textures themselves are square and power-of-2. I suspect the problem lies in the UV coordinates. Is this just how 3D cards work?

UPDATE: I've solved the problem (http://forums.indiegamer.com/showthread.php?p=128770#post128770). Thanks! :)

ggambett
04-10-2007, 04:46 PM
Short answer : yes.
Long answer : please define "every circumstance" :)

Your UV coordinates are probably 0.5 pixels off. I don't remember the specifics but it's a common problem so you'll find plenty of info around.

MikeVitt
04-10-2007, 04:56 PM
You probably need to add a 1 pixel gap between your packed sprites to work with floating-point accuracy issues. If you are using DirectX, then you should subtract 0.5 from the texture location, not the UV coordinates. There is a DirectX article that explains the reasons. Those were 2 issues that at one point caused accuracy problems for my engine.

soniCron
04-10-2007, 04:58 PM
@Gabriel: Any way one could store and display a 2D sprite on a texture on 3D hardware: Stretching it to fill, splitting among smaller textures, using non-power-of-2 textures, etc.

The problem isn't a half-pixel misalignment. I have tested and manually adjusted the UV coordinates, and the problem is apparently more subdued. (My even-sided sprites are pixel-perfect, for example.) With odd-sided sprites, the texture is either perfectly aligned on the edges and gradually becomes misaligned toward the center of the quad, or vice versa. A simple half-pixel misalignment doesn't display this kind of error.

After I eat dinner, I'll post some screenshots.

soniCron
04-10-2007, 06:48 PM
The problem was in the way I was reconstructing the texture-split sprites. Everything is kosher and looks great! Thanks for your help! :)

Indiepath
04-10-2007, 11:45 PM
You could use a polygon hull (an outline) to serve as your collision detector, checking for poly-poly collision is a lot quicker than per-pixel.