Graphics engine does Pixel jumping

A discussion area for general design issues that staff would like detailed feedback on.

Moderator: Staff

User avatar
ElonNarai
Developer
Posts: 207
Joined: Sat Apr 19, 2008 2:43 pm
Location: Netherlands
Contact:

Graphics engine does Pixel jumping

Postby ElonNarai » Mon Apr 28, 2008 2:23 pm

Ok, let me make it clear. there is HUGE problem with the graphical engine.

It was noticed by scibot on the irc-channel and I confirmed it.
Problem: When something moves over the screen it's rarely below one pixel a frame. This is bad since the delta time is not always the same which causes the graphics to jerk. What happens is that pixels jumps, instead of moving, because they move to fast. This is not bad when it happens to one object (like the player) since you wouldn't really notice it. However when the camera moves the entire screen jerks.

A solution would be that we don't let the camera track the player, but follow it. This will allow us to slow the camera down and speed up smoothly and this would prevent problems as well. The only time it becomes problematic is if the player runs too long in the same direction which causes the camera to track him again.

My second choice is to add animations so that the user can't see we are jumping pixels.

A few other ones which I wouldn't recommend unless the above won't work: One is to lower the resolution (making 2x2 pixels) or switching to 3D (think of Ragnarok Online) since 3D is never pixel precise. I have done the last one (can post a vs.net project as an example) and it looks nice.

but before we start discusinng what solustion would be good we should first check if more people have these problems.
Documenter and coder
Image
User avatar
Jetryl
Artist
Posts: 1485
Joined: Fri Aug 26, 2005 7:35 am
Location: Southern Minnesota, USA

Re: Graphics engine does Pixel jumping

Postby Jetryl » Mon Apr 28, 2008 6:27 pm

One is to lower the resolution (making 2x2 pixels)


I would recommend doing this anyways, to the game-view.
Image
User avatar
ElonNarai
Developer
Posts: 207
Joined: Sat Apr 19, 2008 2:43 pm
Location: Netherlands
Contact:

Re: Graphics engine does Pixel jumping

Postby ElonNarai » Tue Apr 29, 2008 3:28 pm

I have justed tested RPG Maker to see if it happend there as well, and yes it does.
Documenter and coder
Image
User avatar
gorzuate
Developer
Posts: 2575
Joined: Thu Jun 17, 2004 3:03 am
Location: Hermosa Beach, CA
Contact:

Re: Graphics engine does Pixel jumping

Postby gorzuate » Tue Apr 29, 2008 5:45 pm

Jetryl, is this the same issue we're seeing on Macs with the double-pixel thingie or is it something else entirely?
Image
User avatar
Jetryl
Artist
Posts: 1485
Joined: Fri Aug 26, 2005 7:35 am
Location: Southern Minnesota, USA

Re: Graphics engine does Pixel jumping

Postby Jetryl » Tue Apr 29, 2008 8:43 pm

gorzuate wrote:Jetryl, is this the same issue we're seeing on Macs with the double-pixel thingie or is it something else entirely?


No.. it's completely unrelated.

:huh: I think what he's saying is that ideally, we'd have a combination of "superfast fps" and "continuous camera/sprite movement" such that when anything in the game moved, it'd never move more than one pixel per frame. No matter how fast it was going, there'd be enough frames-per-second, that it'd have at least one frame per pixel crossed on the screen.

Obvious question - why does he care? Basically, animation is a big damn act of "smoke and mirrors"; it's a big case of fooling the eye into seeing something that's actually not there - fooling the eye into thinking that a series of still images presented to it are actually a single, moving object. And the catch is that there's a threshold below which this illusion breaks apart. The question is where; how low can we go before animations start falling apart (or vice versa)?

By having what he calls for, we'd have a guarantee that we were doing as well as our computer hardware could possibly deliver; that our animations were as continuous as our computers could deliver. But this, IMO, is a little unnecessary; I think we're already above that threshold.


I do think we could greatly improve things, though, by:
1] slowing down the NPCs so that they're closer to this
2] zooming in on the screen
Image
User avatar
ElonNarai
Developer
Posts: 207
Joined: Sat Apr 19, 2008 2:43 pm
Location: Netherlands
Contact:

Re: Graphics engine does Pixel jumping

Postby ElonNarai » Tue Apr 29, 2008 9:35 pm

Jetryl wrote:Basically, animation is a big damn act of "smoke and mirrors";

Completly true, however we are talking about visible problems with non-moving objects like buildings. In fact, but I will have to check this with a teacher of mine to see if it's a valid option, this might be related to sub-pixel rendering.

I do agree that this is a minor issue, however for presentation reasons I do think it has a big impact on the gameplay.
Documenter and coder
Image
User avatar
Roots
Dictator
Posts: 8643
Joined: Wed Jun 16, 2004 6:07 pm
Location: Austin TX
Contact:

Re: Graphics engine does Pixel jumping

Postby Roots » Tue May 20, 2008 10:55 pm

If I understand this correctly, the problem is that the game is updating too fast for the pixel resolution we have. In other words, if the player begins moving their character to the right, we may calculate the distance traveled to be less than one pixel. In fact, it may take as many as a dozen frame updates before the distance traveled is truly one pixel.


What about an option of just slowing down the frame rate? I didn't see that discussed. I know that some professional games do this, arbitrarily setting the frame rate for the game to 60FPS or so (I think the new Command and Conquer game does this?). Then we wouldn't have to change or worry about our game's perspective (remember we may choose to zoom in and out, so its still a problem even if our default zoom is not affected). We also get the added benefit of not having the game consume more CPU time than it needs. The problem with this approach though is timing. We can't say "wait for 2ms between each frame" and expect that to happen, because the OS decides how long the time slice for a process is, not the processes themselves.
Image
User avatar
ElonNarai
Developer
Posts: 207
Joined: Sat Apr 19, 2008 2:43 pm
Location: Netherlands
Contact:

Re: Graphics engine does Pixel jumping

Postby ElonNarai » Wed May 21, 2008 8:48 am

The problem is that objects move to fast between frames, if we would lower the frame rate (C&C has an option to cap it at 30 fps) the problem would not be solved but rather the opposite would happen and the problem would become worse. Another solustion would be to move the characters cover less distance between frames.

Ok, since the above might cause some confusion, I will try to explain it use pictures to show what happens.
Image Image
The first one runs at 60fps, the second at 30fps. Allacrost has the same problem as the second one.

In a 2D game we would prefer that sprites move less than a single pixel over the screen. However if they move more than single pixel over the screen, we can see it jump.

Also the game is fast enough and is not bound to GPU or CPU. The game is only halted by the refresh rate.
Documenter and coder
Image
Winter Knight
Contributor
Posts: 304
Joined: Fri Sep 21, 2007 12:35 pm
Contact:

Re: Graphics engine does Pixel jumping

Postby Winter Knight » Wed May 21, 2008 10:18 am

I'm not noticing what ElonNarai is noticing. The animation seems pretty smooth (except for an occasional stutter, which will occasionally get me stuck in a tree or a mountain. But that's another problem). Do we have a way to display the FPS, so that ElonNarai can tell us what he's getting?
User avatar
ElonNarai
Developer
Posts: 207
Joined: Sat Apr 19, 2008 2:43 pm
Location: Netherlands
Contact:

Re: Graphics engine does Pixel jumping

Postby ElonNarai » Wed May 21, 2008 11:42 am

Winter Knight wrote:I'm not noticing what ElonNarai is noticing. The animation seems pretty smooth (except for an occasional stutter, which will occasionally get me stuck in a tree or a mountain. But that's another problem). Do we have a way to display the FPS, so that ElonNarai can tell us what he's getting?

Try running and look at the background, there you notice it the most.

Anyway I just checked with my own computer and I got around 30~45 fps, but it might be I have running a lot of programs in the background (that I haven't reboot windows for more than four weeks). However if it is the graphical engine I will take a look at the engine and see if I know or can find ways to

It might be that the graphics card solve it for you. With my first laptop when I was designing a website we were constantly bickering about gradient in the background. They said it didn't look smooth while I said it was. Only when we looked at what our laptops displayed we figured out what happend. My laptop detected gradients and made it smooth (the graphics card), while the otherone didn't.

I still have that laptop so I will check it at home if those kind of systems do or don't have the problem. Also I will have new laptop (my third one ^^) in this week so I will see if I can reproduce the same issue there.

Anway, if you would check it again with running and looking at the background, because maybe I'm off here. If you get a negative result I will triple check with my other systems and if I can't produce a positive on at least two systems I will create a bug report on the bug tracker and close it, to give it official funeral :devil:
Documenter and coder
Image
User avatar
Roots
Dictator
Posts: 8643
Joined: Wed Jun 16, 2004 6:07 pm
Location: Austin TX
Contact:

Re: Graphics engine does Pixel jumping

Postby Roots » Wed May 21, 2008 4:02 pm

How can you move a graphic object less than one pixel? That seems impossible to me. The monitor is composed of a fixed number of pixels, and that is the finest granularity on which these graphics are displayed.


You can view the FPS that the game is running at by hitting Ctrl+R while in game (http://allacrost.sourceforge.net/wiki/i ... e_Controls). 30-45 FPS is pretty dang low... my hardware is about 3-4 years old now and I usually get well over 100 FPS in map mode and battle mode (the two most "demanding" parts of the current game). Try running Allacrost when you can do it at 60 FPS or greater and see if you still have the same issue. I can't recall noticing anything like what you are describing, although yes there is an occasional jumpiness while on the map. I'm pretty sure this happens due to the pathfinding algorithm, which needs to be made more efficient so that we aren't calculating multiple paths on a single game loop, and instead spread those calculations out across multiple loops
Image
User avatar
ElonNarai
Developer
Posts: 207
Joined: Sat Apr 19, 2008 2:43 pm
Location: Netherlands
Contact:

Re: Graphics engine does Pixel jumping

Postby ElonNarai » Wed May 21, 2008 6:06 pm

How can you move a graphic object less than one pixel? That seems impossible to me. The monitor is composed of a fixed number of pixels, and that is the finest granularity on which these graphics are displayed.

It is called subpixel, it's used in texture filtering, but you can also implement in 2d
http://www.willmcgugan.com/2007/04/25/g ... th-pygame/

The first time I see it I always like the non subpixel but after I look for it an extend moment (30 seconds) I noticed that the sub pixel version feels so much better.


30-45 FPS is pretty dang low

Yes, I was suprised myself untill I noticed what was in the taskmanager. I think a few of my programs have caused memory leaks and I think one of my VS.Net (had two open) was even compiling. I don't want to reboot because that has 33% it crashes when I try to log in (the processor has trouble getting started).
Documenter and coder
Image
rujasu
Developer
Posts: 757
Joined: Sun Feb 25, 2007 5:40 am
Location: Maryland, USA

Re: Graphics engine does Pixel jumping

Postby rujasu » Wed May 21, 2008 7:33 pm

Roots wrote:You can view the FPS that the game is running at by hitting Ctrl+R while in game (http://allacrost.sourceforge.net/wiki/i ... e_Controls). 30-45 FPS is pretty dang low... my hardware is about 3-4 years old now and I usually get well over 100 FPS in map mode and battle mode (the two most "demanding" parts of the current game).


If you have a good 3D card from ATI or nVIDIA, and hardware acceleration is properly configured, then yeah, you should get 100+ FPS easily. However, my laptop (barely three years old) runs integrated Intel video. It has enough horsepower to run OpenGL, but can only manage 25-35 FPS for Allacrost. We should be able to, at the very least, support users at this level of hardware.

Also, if 3D drivers aren't set up properly (common problem in Linux,) Allacrost runs at about 2 FPS. That's the downside to using OpenGL.

Basically, I've never seen much issue with animation looking sloppy at 25 FPS. Of course, it looks horrible at 2 FPS and I don't expect people to actually play the game at that rate. But 25 FPS looks fine to my untrained eyes.
User avatar
ElonNarai
Developer
Posts: 207
Joined: Sat Apr 19, 2008 2:43 pm
Location: Netherlands
Contact:

Re: Graphics engine does Pixel jumping

Postby ElonNarai » Wed May 21, 2008 7:42 pm

rujasu wrote:But 25 FPS looks fine to my untrained eyes.
You can't see the difference between 60 fps and 100 fps but you will notice it. Why else do some people crank their refresh rate to 100 hertz? (personally I think 60 is way more than enough)

Could you post some more stats of your laptop? What Allacrost does is nothing special (as far as I have seen, the only problem is overdrawing) and it should run at 60 fps on hardware of 6 years ago.
Documenter and coder
Image
User avatar
Roots
Dictator
Posts: 8643
Joined: Wed Jun 16, 2004 6:07 pm
Location: Austin TX
Contact:

Re: Graphics engine does Pixel jumping

Postby Roots » Wed May 21, 2008 7:53 pm

ElonNarai wrote:
How can you move a graphic object less than one pixel? That seems impossible to me. The monitor is composed of a fixed number of pixels, and that is the finest granularity on which these graphics are displayed.

It is called subpixel, it's used in texture filtering, but you can also implement in 2d
http://www.willmcgugan.com/2007/04/25/g ... th-pygame/

The first time I see it I always like the non subpixel but after I look for it an extend moment (30 seconds) I noticed that the sub pixel version feels so much better.


Ah, now I understand. So, how do we get this into Allacrost? Is it a special option already built into the OpenGL API and requires simple configuration, or is this something that we are going to have to implement ourselves in the video engine? If its just an API config or engine change to make animation look smoother without requiring any modification of the game logic code (map mode, etc.), I'm all for it. :approve:
Image
User avatar
Jetryl
Artist
Posts: 1485
Joined: Fri Aug 26, 2005 7:35 am
Location: Southern Minnesota, USA

Re: Graphics engine does Pixel jumping

Postby Jetryl » Thu May 22, 2008 5:22 am

Roots wrote:
ElonNarai wrote:
How can you move a graphic object less than one pixel? That seems impossible to me. The monitor is composed of a fixed number of pixels, and that is the finest granularity on which these graphics are displayed.

It is called subpixel, it's used in texture filtering, but you can also implement in 2d
http://www.willmcgugan.com/2007/04/25/g ... th-pygame/

The first time I see it I always like the non subpixel but after I look for it an extend moment (30 seconds) I noticed that the sub pixel version feels so much better.


Ah, now I understand. So, how do we get this into Allacrost? Is it a special option already built into the OpenGL API and requires simple configuration, or is this something that we are going to have to implement ourselves in the video engine? If its just an API config or engine change to make animation look smoother without requiring any modification of the game logic code (map mode, etc.), I'm all for it. :approve:


Subpixel rendering isn't going to solve the problem ElonNarai is talking about., nor for that matter should we add it into our game, because it'd become blurry as hell. Subpixel rendering rapes pixel art. You can do it if you want, but - here's a preliminary "I told you so".

You'd do it by setting the opengl interpolation to linear, I think, and having map-mode store the x,y positions of the sprites as floating point values. Rather than saying "this sprite is at pixel 10,15", you'd say "this sprite is at pixel 10.5,15.3"

I know we don't store our sprites on a per-pixel basis; so we'd actually have to do some significant reworking of how our sprite engine works, because IIRC we store both a tile position and an offset.

In a 2D game we would prefer that sprites move less than a single pixel over the screen. However if they move more than single pixel over the screen, we can see it jump.


Yeah, though in our case for pixel-art, we don't want to actually render their subpixel positions. Store them? Yeah. We want to store all values of anything that can change in as minute of gradations as possible, because we have percentage shifts on things (such as bonuses to attack damage). 30 attacks at 7.4 hp damage each is notably different from 30 attacks at 7 damage each. (222 hp damage vs. 210). Wesnoth had this issue and never fixed it, and it makes percentage boosts basically not mean what they say they mean due to rounding errors.

Same applies to the movement of pixellated objects across the screen. Rounding errors are evil. Rounding off the -rendering- of each image is fine, but rounding off the actual stored value is evil.
Image
User avatar
ElonNarai
Developer
Posts: 207
Joined: Sat Apr 19, 2008 2:43 pm
Location: Netherlands
Contact:

Re: Graphics engine does Pixel jumping

Postby ElonNarai » Thu May 22, 2008 8:48 am

Well, that was I thought as well, but for some reason it didn't, I have never checked with pixel-art but I will see if I can write a demo in the weekend. I was expecting to pump everything over to my laptop, but that got delayed.
Documenter and coder
Image
User avatar
Roots
Dictator
Posts: 8643
Joined: Wed Jun 16, 2004 6:07 pm
Location: Austin TX
Contact:

Re: Graphics engine does Pixel jumping

Postby Roots » Thu May 22, 2008 7:55 pm

Jetryl wrote:You'd do it by setting the opengl interpolation to linear, I think, and having map-mode store the x,y positions of the sprites as floating point values. Rather than saying "this sprite is at pixel 10,15", you'd say "this sprite is at pixel 10.5,15.3"

I know we don't store our sprites on a per-pixel basis; so we'd actually have to do some significant reworking of how our sprite engine works, because IIRC we store both a tile position and an offset.


In a 2D game we would prefer that sprites move less than a single pixel over the screen. However if they move more than single pixel over the screen, we can see it jump.


- I don't know if our OpenGL interpolation is linear, but it might be. I'd have to check.

- We already store sprites using floating point coordinates. Every 1.0 represents 1 tile, and the speed/distance traveled formula takes that into account. So yes, we often have sprites sitting at an x, y position of (11.53, 5.94), for example.

- What do you mean store our sprites on a per-pixel basis? In the PNG files they are nearly stored that way (they aren't BMPs, but BMPs are an impractical image file format anyway). In the texture sheets loaded into the game they are stored in their native size. And if you have the default screen resolution set for the game, they are rendered on a per-pixel basis as well (in fact, the default screen resolution was actually chosen to take our image/sprite sizes into account so that we did not have to do any unnecessary re-sizing, scaling, stretching, etc.).
Image
User avatar
Jetryl
Artist
Posts: 1485
Joined: Fri Aug 26, 2005 7:35 am
Location: Southern Minnesota, USA

Re: Graphics engine does Pixel jumping

Postby Jetryl » Fri May 23, 2008 5:04 am

Roots wrote:- What do you mean store our sprites on a per-pixel basis? In the PNG files they are nearly stored that way (they aren't BMPs, but BMPs are an impractical image file format anyway). In the texture sheets loaded into the game they are stored in their native size. And if you have the default screen resolution set for the game, they are rendered on a per-pixel basis as well (in fact, the default screen resolution was actually chosen to take our image/sprite sizes into account so that we did not have to do any unnecessary re-sizing, scaling, stretching, etc.).


Storage as in "heap memory of the game"; subject of the sentence is "a sprite being displayed on the screen".

A sprite being displayed on the screen has data of it's position stored in memory. The ideal thing to do is to store the position as a float, and typecast it to an int when you're actually going to draw it. You don't want to do subpixel rendering, because it's blurry, but you also don't want to accrue cumulative rounding errors from rounding off object velocities to an integer every screen cycle. So storing it in ram as a float, but passing it to the graphics code as an int, gives you the best of both worlds.

Ironically, we actually don't intentionally do this, but we end up achieving it by accident on windows machines. We're set to GL_LINEAR, so it keeps us on the pixel boundaries. But our positions of the actual sprites are these floats, and they're (and this was generally rather clever, because it avoids an upper-limit for map size) based on units of tiles rather than units of pixels. The downside is that because of the way different platforms handle ... something (I don't know what it is; otherwise the bug would be fixed), macs (and probably linux) are rounding something up, differently; resulting in doubled pixel lines.




You don't actually want to do subpixel rendering in allacrost (or wesnoth), because they're sprite art, and very much unlike most other kinds of art, they're designed around having the boundaries between pixels explicit - we do not want to have the subpixel rendering that elonarai mentioned in passing because it would blur our sprites.

Subpixel rendering works as the name implies. A pixel is the smallest size you can display something at. If you were trying to render a single black pixel on a white screen, the finest-grained you can specify it's position is in terms of a single pixel to be turned on or off. You can't pick a spot inbetween two pixels, and light it up - nothing exists there but the plastic barrier between two pixel cells on your LCD. However, you can make a visual approximation of doing so - and you do this through the classic technique of "anti-aliasing". If you wanted to put a "black pixel on a white screen" at a position halfways between two pixels, you'd make both of them 50% gray. For a still image, this ... looks like shit; it's very blurry.

For an image where there's subtle motion going on that moves less than a pixel's width in a single frame, the motion looks smoother if you use subpixel rendering, because rather than only visually registering a change when the object being drawn moves a full pixel's worth of distance, and hops to the next pixel (which might be several frames of time if the object is moving slowly enough), you instead render a bit of visual difference on every single frame. However, this requires that you actually have stuff moving at less than a pixel-per-frame in order to see an improvement. A picture's worth a thousand words - this is a black pixel moving across four white pixels, in non-subpixel rendering on the top, and subpixel rendering on the bottom.
Image

The whole look and feel of pixel art is predicated on it being drawn on pixel boundaries. This is what allacrost would look like if the camera had nudged down half a pixel (which would be happening basical every other frame as claudius walks.

Image

:eyebrow:
Image
User avatar
Drakkoon
Developer
Posts: 173
Joined: Thu Jan 11, 2007 12:54 am
Location: Montréal, Qc

Re: Graphics engine does Pixel jumping

Postby Drakkoon » Fri May 23, 2008 12:16 pm

The rounding up or down to the closest bit representation of a float (remember that a float is an approximation of the real number) is not regulated by the standard. That is why different compilers round up or down differently. They all have the same representable numbers, but a division might not give the same results on two different compilers.

I had to deal with that in my school's final project. Our network code only sent the mouse/keyboard commands of each player, so the game had to be extremly deterministic. But cross-platform multiplayer was a pain because of the float rounding errors. I ended up starting a branch with fixed point arithmetics, but I lacked time so we just dropped the cross-platform multiplayer.

Return to “Design”

Who is online

Users browsing this forum: No registered users and 1 guest