Post subject: What are subpixels?
Eszik
He/Him
Joined: 2/9/2014
Posts: 163
I read some discussions and submissions about Super Mario Bros. and Mega Man 1, and noticed that "subpixels" or "subpixel value" are really important to optimize a TAS of platformer game. What are actually these subpixels?
I problably made mistakes, sorry for my bad English, I'm French :v
Editor, Skilled player (1536)
Joined: 7/9/2010
Posts: 1319
Knowing about subpixels is absolutely important for making a optimized TAS. Subpixels are fractions of a pixel. They're normally 1/256th of a pixel, sometimes 1/16th. To understand how subpixels are calculated, imagine a clock. A clock has 24 hours, 60 minutes and 60 seconds. Each time the 60 seconds are over the minutes will increase by 1. The same counts for subpixels, instead of 60, the subpixel value need to get 256 to make the pixel value increase by one. The amount of subpixels, which are calcuated depends on the speed value. Let's say the speed value is 120, you have 256 subpixels and the starting subpixel is 0. This means every frame the subpixel value increases by 120 each frame (0, 120, 240, 104). Where does the 104 value come from? The subpixel value only goes from 0 to 255, so if the value is greater than 255, it starts counting from 0 on again. You can calcualte the subpixel with a simple formula: subpix_new = (suppix + speed) MOD number_of_subpixs
Favorite animal: STOCK Gt(ROSA)26Sortm1.1(rtTA,EGFP)Nagy Grm7Tg(SMN2)89Ahmb Smn1tm1Msd Tg(SMN2*delta7)4299Ahmb Tg(tetO-SMN2,-luc)#aAhmb/J YouTube Twitch
Masterjun
He/Him
Site Developer, Skilled player (1987)
Joined: 10/12/2010
Posts: 1185
Location: Germany
Subpixels are important because they are not obvious. Say you are comparing your TAS to another TAS, there you can see that you are maybe faster because you are further to the right (when comparing the screen, so the pixels). But the problem with subpixels is that you can't see a difference on the screen. Say you have a clock that only shows minutes and hours. You can't see the seconds so you don't know if the minute will advance in the next second, in 5 seconds or in 50 seconds. But since we have tools such as RAM Watch we can see these subpixels and use them to optimize the TAS.
TASeditor wrote:
Let's say the speed value is 120, you have 256 subpixels and the starting subpixel is 0. This means every frame the subpixel value increases by 120 each frame (0, 120, 240, 104). Where does the 104 value come from? The subpixel value only goes from 0 to 255, so if the value is greater than 255, it starts counting from 0 on again.
You could have compared that to the clock again: Say the "speed" value is 25 and you start at 0 seconds, the seconds will go 25, 50, 15, 40, 5...
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)
Editor, Skilled player (1439)
Joined: 3/31/2010
Posts: 2108
Subpixels are important for games where the character moves at variable speeds and/or speeds that aren't whole numbers (e.g. 1.25 px/frame.) Your goal when TASing is to not only optimize your regular pixels, but also get as good of a subpixel value as possible. Some games have glitches that are only possible at the right amount of subpixels. A few games also exhibit something called "Subpixel carryover", where your subpixel value is not claered between levels. Getting as high of a subpixel value as possible before exiting the levels allows you get a small head start for the next one.
Site Admin, Skilled player (1254)
Joined: 4/17/2010
Posts: 11475
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
Subpixels are important.
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
Skilled player (1651)
Joined: 7/25/2007
Posts: 299
Location: UK
I notice people are explaining their use without saying what the hell they actually are. Well here's my understanding: Pixels are obviously the coloured dots which your monitor/TV etc uses to display the image. However, games are not nicely programmed using pixels as their foundation for distances/speeds. A character may not necessarily move at exactly 1 pixel per frame, or 2 pixels per frame, but instead may have a speed which moves him 4 pixels every 3 frames, or approx 1.33 p/f. That would give x positions {0, 1.33, 2.66, 4}. But obviously, how do you display that speed on screen? You cannot draw a graphic with a displacement of one and a bit pixels can you? You can only display them at the nearest pixel, and thus games will simply round up/down to the nearest pixel and draw the char there. This would result in the actual locations on screen being drawn as {0,1,3,4} for example. That's not because his speed is 1, then 2, then 1; it's not that our character inexplicably goes twice as fast in the middle, it's just that we can only draw him in the nearest pixel, and thus those strange patterns emerge. This means that when TASing a game, there may be two or more different routes/strategies which appear to give the same result. However, upon closer inspection, it may reveal that one of them gives an x position of 6.0, where as the other gives 6.4. Again, visually these both get drawn at x=6, despite the fact that one is ever so slightly better. Knowing this helps to squeeze out just a tiny bit more optimisation, because by getting larger subpixel values on each section, they will eventually keep adding up, and being enough to push your char 1 more pixel to the right. For example doing the 6 strat three times would give positions {6,12,18}, where as the 6.4 strat would give (6,13,19}; making our character a bit closer to the goal, and thus saving time.
Masterjun
He/Him
Site Developer, Skilled player (1987)
Joined: 10/12/2010
Posts: 1185
Location: Germany
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)
Active player (309)
Joined: 8/21/2012
Posts: 429
Location: France
Subpixels can also explain why a movie desynchs after being hex edited, it's most of the time about subpixel carryover or something similar. If your game doesn't clear the subpixel value after each level and you redo level 1, then you want to hex edit it while not redoing the rest of the run, you can end up with a desync on level 2 (or later) if you didn't finish level 1 with the same subpixel values than last time. What it means is that having a different subpixel value at the end of the first level makes you start the next one at a slightly different position. Subpixel carryover is something to have in mind, you want to know if the game you're TASing is doing it or not. On the other hand, some actions in games can sometimes reset your subpixel values to 0 (and maybe also put your whole position to a set value). I'm thinking about using a door, going into some kind of transportation mechanism... These are good places to hex edit if you don't want to redo everything. But be careful about other stuff like the RNG while hex editing :P So, to sum up what has been said, subpixels are a more precise measure of a position, they can be abused if the game doesn't reset the value at a transition (such as the end of a level), and they can get in the way of your hex editing if you don't watch their value closely (and know how the game handles them).
Eszik
He/Him
Joined: 2/9/2014
Posts: 163
Thanks everyone forme your answers! I understand better now :D
I problably made mistakes, sorry for my bad English, I'm French :v
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
Short version: The coordinates of a sprite on the screen may be internally stored with more accuracy than the pixel resolution of the screen. If this is so, then it's said to be stored at sub-pixel accuracy. (The reason why many games do this is because it allows for more fluid acceleration and deceleration, and other reasons.)