Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ways to counteract sprite glitches caused by upscaling / texture filtering?
10-26-2014, 08:24 PM (This post was last modified: 10-27-2014 02:35 AM by [Unknown].)
Post: #2
RE: Ways to counteract sprite glitches causes by upscaling / texture filtering?
One problem with linear filtering is rounding. We've had (and still have) issues because of not always matching the rounding on a PSP.

At 2x, though, you start to have "impossible" problems the PSP didn't have. Consider a 4x4 grid:

Code:
+---+---+---+---+
|   |   |   |   | 3
+---+---+---+---+
|   | X | X |   | 2
+---+---+---+---+
|   | X | X |   | 1
+---+---+---+---+
|   |   |   |   | 0
+---+---+---+---+
  0   1   2   3

Suppose I wanted to draw a texture in the area marked with X's. It'd be easy; I would just draw from (1, 1) to (3, 3). The last coordinate is "exclusive" (meaning, it draws UNTIL that.)

But, for various reasons my math might not be that accurate. Maybe I end up drawing from (1.3, 1.3) to (2.5, 2.5). It's all gravy. As a developer, I don't have to worry - it still looks picture perfect on the screen. No need to go back and spend countless more hours and tell my boss that the release date ain't gonna happen as planned.

But, things go to pieces when we start drawing at a higher resolution. Here's the same grid, double the resolution:

Code:
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   | 3.5
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   | 3
+---+---+---+---+---+---+---+---+
|   |   | X | X | X | X |   |   | 2.5
+---+---+---+---+---+---+---+---+
|   |   | X | X | X | X |   |   | 2
+---+---+---+---+---+---+---+---+
|   |   | X | X | X | X |   |   | 1.5
+---+---+---+---+---+---+---+---+
|   |   | X | X | X | X |   |   | 1
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   | 0.5
+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   | 0
+---+---+---+---+---+---+---+---+
  0  0.5  1  1.5  2  2.5  3  3.5

Now, if Mr. Smartypants who is good at math draws (1, 1) to (3, 3), everything is still okay (remember the last coordinate is exclusive.) Exactly the same pixels are filled in.

But, if you recall, I had a deadline. (1.3, 1.3) to (2.5, 2.5) worked before, but what happens now? Well, 1.3 rounds up, and 2.5 is exclusive, so my box is half the size it was supposed to be. Ack.

The "best" solution to this problem is an extra step that snaps the coordinates to what they would be at 1x. So, for example, 1.3 would get rounded down, and 2.5 would get rounded up. Then we would draw (1, 1) to (3, 3) and it'd look fine.

The reasons we haven't done this yet are:
* It's slower. Snapping would have to be done after transform, and probably in the GPU. We'd probably have to move the viewport transform into the shader as well, not sure.
* My example was positions, but the problem applies to texture coordinates as well, which increases perf hit / complexity.
* It would hurt visual quality of 3D models or games written by Mr. Smartypants above. Animation will look more fluid without the snapping.
* No one has written it yet.

The main problems should be solvable by making it an option. Possibly a separate option for depth as well (which I'm pretty sure not snapping there is causing problems in at least Phantasy Star Portable 1.)

That said, maybe there's some better way. It'd be nice to not have an option that needs to be customized per game. I don't know what PCSX2 does because I usually play games on most systems at 1x.

Another problem can be caused by increased sampling. When OpenGL is generating more pixels near the edge, it may want to sample more texels than before (especially depending on the texture size vs. drawing size.) In the case of a sprite sheet, this can cause texels of completely wrong colors to be filtered in (iirc this is a problem in FF4.) This is a major problem when alpha or color testing is used (e.g. when fuchsia is used as transparent.)

And then there's texture scaling, which brings even more problems to the table, since it is (somewhat necessarily) applied to entire textures, not just the sampled regions. This worsens the problems mentioned above.

So, it's definitely a complicated issue for which there's not a single silver bullet, at least not that I know of.

-[Unknown]
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Ways to counteract sprite glitches causes by upscaling / texture filtering? - [Unknown] - 10-26-2014 08:24 PM

Forum Jump: