Question about 8 sprite per scanline limit

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

User avatar
mantanz
Posts: 31
Joined: Fri Jul 21, 2017 4:38 am

Question about 8 sprite per scanline limit

Post by mantanz »

Hey folks,

I'm just wondering, if I use 16x8 sprites do I still get 8 per scanline? Or because the sprites are double the width do I only get four?

The reason I ask is my ship is 3 sprites wide, bullet is 1 with max 2 bullets on screen so that only leaves me with two sprites for any enemies without having to code in some ugly flicker. If I get 8 bigger sprites that seems the way to go.

Sorry, I'd test it myself but not near my dev machine.
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: Question about 8 sprite per scanline limit

Post by FrankenGraphics »

You don't get double width (unless you turn your monitor 90 degrees), you get double height.

Even if one sprite is made of two tiles in this mode, it's still one sprite. You get 8 per scanline, since the special internal/indirect scanline memory in PPU can hold up to 8 sprites.

16x8 8x16 mode increases the likelyhood of sprites intersecting the same scanline geometrically (since they're bigger), but lessens the amount of sprites doing so. It varies a lot if it's beneficient or not, depending on game design.


Edit: 8x16
Last edited by FrankenGraphics on Tue Aug 08, 2017 8:20 am, edited 1 time in total.
User avatar
rainwarrior
Posts: 8735
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Question about 8 sprite per scanline limit

Post by rainwarrior »

mantanz wrote:Sorry, I'd test it myself but not near my dev machine.
Every NES emulator emulates the 8 sprite limit.
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Post by Bregalad »

There's no such thing as 16x8 mode, there's only 8x8 and 8x16.
(Convention for counting pixels is always Horizontal x Vertical)
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: Question about 8 sprite per scanline limit

Post by FrankenGraphics »

^ that too. But i always seem to mix them up.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Question about 8 sprite per scanline limit

Post by Pokun »

The PC Engine's sprite system (which allows for 16 sprites on a scanline) counts sprites with double width as two sprites when it comes to the scanline limit. On the other hand sprite size is set per individual sprite, so you can mix and match sprite sizes however you want.
In Nintendo's consoles, sprite size is usually a global setting but each sprite is always counted as one sprite towards the scanline limit I think (I mean for Game Boy, SNES etc).
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Question about 8 sprite per scanline limit

Post by tepples »

Like the NES, the Game Boy has only one sprite width. But it allows ten 8-pixel-wide sprites on a 160-pixel-wide picture, or 50% coverage. This is twice the effective coverage of the NES, which allows eight 8-pixel-wide sprites on a 256-pixel-wide picture, or 25% coverage.

Like the TurboGrafx-16 (aka PC Engine), the Sega Genesis and Super NES have a sprite coverage limit close to 100 percent of a scanline. But they also limit total sprite count per scanline regardless of size. And because they allow 8-pixel-wide sprites, sprite count can become the limiting factor on a scanline that contains mostly 8-pixel-wide sprites.
  • Genesis in 256px mode: 16 sprites or 32 8-pixel-wide slivers
    Coverage with 8x8 pixel sprites is 50%; coverage with larger sprites is 100%.
  • Genesis in 320px mode: 20 sprites or 40 8-pixel-wide slivers
    Coverage with 8x8 pixel sprites is 50%; coverage with larger sprites is 100%.
  • Super NES: 32 sprites or 34 8-pixel-wide slivers
    Coverage with 8x8 pixel sprites is 100%; coverage with larger sprites is 106%.
    But because all sprites are square, sprites often have to include more blank space at the top or bottom, reducing coverage on adjacent lines. TG16 suffers from this as well because of the 16x16 pixel minimum sprite size.
User avatar
mantanz
Posts: 31
Joined: Fri Jul 21, 2017 4:38 am

Re: Question about 8 sprite per scanline limit

Post by mantanz »

Ah sorry, I had my dimensions around the wrong way. Carry on, nothing to see here :P
User avatar
mantanz
Posts: 31
Joined: Fri Jul 21, 2017 4:38 am

Re: Question about 8 sprite per scanline limit

Post by mantanz »

FrankenGraphics wrote:You don't get double width (unless you turn your monitor 90 degrees), you get double height.

Even if one sprite is made of two tiles in this mode, it's still one sprite. You get 8 per scanline, since the special internal/indirect scanline memory in PPU can hold up to 8 sprites.

16x8 8x16 mode increases the likelyhood of sprites intersecting the same scanline geometrically (since they're bigger), but lessens the amount of sprites doing so. It varies a lot if it's beneficient or not, depending on game design.


Edit: 8x16
Ah you answered another question I had... whether sprites had to be at the exact same height or any part of them on the scanline would count.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Question about 8 sprite per scanline limit

Post by lidnariq »

(deliberately off-topic trolling) Unless you're decided to target the VT03. That's like an NES but has a toggle to switch sprites to either 16-pixel wide 2bpp or 8-pixel wide 4bpp.
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: Question about 8 sprite per scanline limit

Post by Bregalad »

Pokun wrote: In Nintendo's consoles, sprite size is usually a global setting but each sprite is always counted as one sprite towards the scanline limit I think (I mean for Game Boy, SNES etc).
I don't know for other Nintendo's consoles, but the SNES there is two limits, one for number of sprites (32 per line), and one for number of equivalent 8x8 sprites (34 per line). So it's effectively false to say each sprite is counted as one sprite towards the scanline limit. Using a size larger than 8x8 is basically hardware metasprites made of 8x8 sprites, and you only gets two extra 8x8 sprites per line doing that. Still better than nothing, considering 34 sprites allows to simulate for a horizontally scrolling background, wheras 32 sprites only allows to simulate a non-horizontally scrolling background.
This is twice the effective coverage of the NES, which allows eight 8-pixel-wide sprites on a 256-pixel-wide picture, or 25% coverage.
While this is true, the coverage doesn't indicate everything. For example if you know your metasprites are going to be 16x16, Gameboy only allows 5 objects, one more than the NES.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Question about 8 sprite per scanline limit

Post by Pokun »

Oh I see, it's not much different from PC Engine then which is also effectively using hardware metasprites to make bigger sprite sizes then the default one by combining neighbouring patterns in the pattern table into a metasprite. Although the PC Engine's smallest sprite size is 16x16 instead of 8x8 (which is both good and bad I guess).

Ah you answered another question I had... whether sprites had to be at the exact same height or any part of them on the scanline would count.
I remember wondering about this for the longest time too. Everyone said "you can only have 8 sprites on a scanline". On a scanline? A sprite is bigger than a scanline so what does it mean exactly? Then I learned it means that more than 8 sprites can't have any of their pixel lines sharing the same scanline at the same time.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Question about 8 sprite per scanline limit

Post by tokumaru »

As far as the PPU is concerned, sprites are only one scanline tall, because it draws the picture line by line. The PPU does a little math in order to know which lines of which sprites it has to show on each scanline (if scanline - sprite_y < sprite_height, that's the line to show), but it only has time to draw 8 sprite lines per scanline.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Question about 8 sprite per scanline limit

Post by Pokun »

Yeah that makes sense, thanks.
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: Question about 8 sprite per scanline limit

Post by Bregalad »

A nice trick is to have each sprite one pixel below its neighbour, and it becomes possible to have as many sprites as you want diagonally, as there will always be exactly 8 sprites per line. This effectively allows to write any arbitrary text with sprites only, at the only "cost" that is should have this weird diagonal lining.

On the other hands, sprites partially hidden by the 8-sprites per scanline limitation are useful to partially hide sprites, as seen in Castlevania II - Simon's Quest when simon enters a swamp and his feet are hidden, for example.
Post Reply