gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Odd sprite stripping on hardware (rated G)

#16414 - DiscoStew - Sun Feb 15, 2004 8:10 pm

I didn't realize what I put for the subject until I typed it up. Obviously everyone should realize what I mean by a sprite though.

My program currently allow a bunch of sprites to be shown on-screen, even all those that are rotating through my sprite handling technique. To point out, there are less than 128 sprites, and of those sprites, less than 32 rotating sprites using unique matrices. When I push a button, it adds another set of sprites to be displayed. Now onto the problem...

With an emulator, everything is displayed correctly, even the rotating sprites. However, on hardware, when a certain number of sprites are already on screen, and I add another set, those newly-added sprites have an odd cutting away on them, showing only part of them. One odd thing about this is that sometimes the next sprite groups I add may be stripped, or not. You may be thinking that it has something to do with my loading the sprite images to VRAM, but I can tell you, it isn't that, because the rotating sprites don't show that. The rotating sprites have that stripping too, but it doesn't go along with the rotating. It is as if parts of the background (in this case there is no background, just the back plane) are showing as strips on top of my sprite. An observation I made is that it is cutting away by rows, whether the left side of the sprite is showing, or the right side, or complete rows of the sprite are missing, usually blocks of rows. All in all, each sprite affected has its own unique defect stripping, but the stripping for each sprite stays constant and doesn't change. Could it be something with the scanlines? FYI, I am not using a single interrupt with my program, so the H_Blank could not be the problem. I know of the fact that only a certain number (I don't know how many) of sprites can be shown per scanline, but wouldn't affect all sprites on that scanline? Besides, when another sprite group is added on the same scanline as a bunch of others, for some reason it may or may not have the defect. This is one odd bug indeed.

I'd show you a actual picture so you could understand it visually, but not only do I not have a place on the internet to store the picture, but I don't even have a digital camera to take the picture with (since it is a problem with hardware). However, I'll try it with ASCII characters of what it would look like (not to scale)...
Code:

Note: "*" = the background

Image with face, and image rotated 90 degrees
***********   ***********
***_____***   ***_____***
**__O_O__**   **_O_____**
*___O_O___*   *_O___OO__*
*_________*   *_O_______*
*__O___O__*   *_O___OO__*
**__OOO__**   **_O_____**
***_____***   ***_____***
***********   ***********

Same image, also rotated, but with the stripping
***********   ***********
***_____***   ***_____***
******O__**   ******___**
*___O_O___*   *_O___OO__*
*_____*****   *_O___*****
******_O__*   ******OO__*
*****OO__**   *****__****
***_____***   ***_____***
***********   ***********


For those of you who understand the problem, I am asking for your help. I'd apreciate it a lot. thx
_________________
DS - It's all about DiscoStew

#16415 - torne - Sun Feb 15, 2004 8:33 pm

This sounds like something to do with the number of sprite rendering cycles available per line. Rotation/scaling sprites require many more cycles than normal sprites; gbatek says 26 cycles per 8 horizontal pixels, as opposed to 8 cycles (there are 954 if you have hblank free, 1210 if you don't). The effects you get when there are too many are pretty variable; not all sprites will be affected.

The maximum number of sprites on one scanline is 128, but only if they are all non-rotate/scale and 8x8. Bigger sprites or rotation/scaling sprites will bring the limit down. Check the sprite overview section of gbatek..

#16417 - DekuTree64 - Sun Feb 15, 2004 8:44 pm

That's caused by the hardware's sprite drawing limits. I don't remember the exact number of sprite pixels/line it can handle, but I do know that rot/scale sprites take more processing power per pixel than normal ones, and double-sized rot/scales take even more than that, plus they logically have twice as many pixels across each line, so you have to be careful when using large rotating sprites.
Still, GBA can handle a lot more than SNES could, as you can see in some games where you can get a whole bunch of enemies gathered onto the screen all on the same line, and they start breaking up like that.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#16418 - DiscoStew - Sun Feb 15, 2004 9:25 pm

thx for your help. Each of your answers are very logical in this case, but there is still something that the stripping is doing which makes it odd. I've tried my program, and I have started out with a bunch of sprites at the top of the screen, transformable or not, and a few below those. I add a sprite group to the groups below, and the problem occurs, yet with all those sprites at the top, all averaging around the same scanlines, aren't having this stripping problem. Heck, even the following sprite groups I add, no matter where they are placed, may or may not have this problem, but usually do, transformable or not. Could this problem also be related to how the sprites are ordered in OAM, that perhaps sprites that are further down the sprite order chain are having a harder time being drawn in that those higher up in the chain?

Since my program only adds sprites into the order chain if they are visible in relation to my camera function, perhaps I should re-include my camera-moving function, move the camera to make some sprites off-screen, and see if the problem persists. I usually have about 90 sprites on-screen before stripping occurs (though I don't expect to have that many sprites on-screen in any of my real projects).

I'll see what I can do, and perhaps this extra explanation of this problem will help you all figure out another solution. Again, thx for your help
_________________
DS - It's all about DiscoStew

#16429 - Miked0801 - Mon Feb 16, 2004 1:57 am

A little more info - Sprites that use the Affine params in normal mode will take as much time to render as 2 un-affined sprites. Double mode will make them render at about x4. Also, do you have HBlank/DMA routines running lower on the screen? If so, I believe (am not sure), that this will also steal time away from sprite rendering causing sprite dropout.

#16432 - torne - Mon Feb 16, 2004 4:08 am

Miked0801 wrote:
A little more info - Sprites that use the Affine params in normal mode will take as much time to render as 2 un-affined sprites. Double mode will make them render at about x4. Also, do you have HBlank/DMA routines running lower on the screen? If so, I believe (am not sure), that this will also steal time away from sprite rendering causing sprite dropout.


Sprites with affine use 26/8 times as much time as normal sprites; more than triple. Double size makes no difference, except that you might have twice as many pixels to draw (doubling the time again); but it depends exactly how many pixels intersect the line you are drawing (I think). Turning on HBlank Free gives you only 954/1210 of the time to draw. gbatek has all these timing parameters documented in the sprite overview section.