dynamic sprite size mode changing

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

dynamic sprite size mode changing

Post by psycopathicteen »

Today I decided to type out a document on a mathematical algorithm for a game to automatically determine which sprite size mode is best for a given frame based on the distribution of various sprite sizes.

Code: Select all

dynamic sprite sizes:

Since the SNES can only choose between 2 sprite sizes at one time, there is a compromise between screen coverage and flickering.  Bigger sprite sizes allow covering more of the screen, but small sprites are less prone to flickering when too many of them are on the same scanline.  In this document, we will only discuss 8x8, 16x16 and 32x32 sprites.

		small		large
mode A:	8x8		16x16
mode B:	8x8		32x32
mode C:	16x16		32x32


These are all the configurations for each "sprite" size in each mode:

mode A:

8x8		1 8x8
16x8		2 8x8s or 1 16x16
8x16		2 8x8s or 1 16x16
16x16		1 16x16
24x24		1 16x16 and 5 8x8s, or 2 16x16s and 2 8x8s
32x24		2 16x16s and 4 8x8s, or 3 16x16s and 2 8x8s, or 4 16x16s
24x32		2 16x16s and 4 8x8s, or 3 16x16s and 2 8x8s, or 4 16x16s
32x32		4 16x16

mode B:

8x8		1 8x8
16x8		2 8x8s
8x16		2 8x8s
16x16		4 8x8s
24x24		9 8x8s or 1 32x32
32x24		12 8x8s or 1 32x32
24x32		12 8x8s or 1 32x32
32x32		1 32x32

mode C
8x8			1 16x16
16x8			1 16x16
8x16			1 16x16
16x16			1 16x16
24x24			1 32x32
32x24			1 32x32
24x32			1 32x32
32x32			1 32x32

Using the following table, determine the number of sprites needed for each sprite size mode.  If mode A exceeds 128 sprites, use mode B, and if mode B exceeds 128, use mode C.


size		mode A	mode B	mode C

8x8		1		1		1
16x8		1		2		1
8x16		1		2		1
16x16		1		4		1
24x24		4		1		1
32x24		4		1		1
24x32		4		1		1
32x32		4		1		1


The next step is to calculate the number of sprites it will take for using the minimum amount of 8x8 cells.  If the number of sprites exceeds 128, make a compromise between sprites and cells.  Always do sprite sizes that save the biggest number of sprites for the smallest number of cells first, in the order of first to last sprite in OAM.

mode A
size		sprites	cells		trade-off

8x8		1		1		NA
16x8		2		2		1 sprite for 2 cells
8x16		2		2		1 sprite for 2 cells
16x16		1		4		NA
24x24		6		9		2 sprites for 1 cell
32x24		6		12		1 sprite for 2 cells (x2)
24x32		6		12		1 sprite for 2 cells (x2)
32x32		4		16		NA



mode B
size		sprites 	cells		trade-off

8x8		1		1		NA
16x8		2		2		NA
8x16		2		2		NA
16x16		4		4		NA
24x24		9		9		8 sprites for 7 cells
32x24		12		12		11 sprites for 4 cells
24x32		12		12		11 sprites for 4 cells
32x32		1		16		NA


VRAM alignment:

Sprites always take up the size of their mode C configuration in VRAM.  Sprites are always aligned to the left, except with h-flipped is set.  Sprites can choose between being aligned on top or on bottom, to minimize flicker in meta-sprites, which are reversed when v-flipped is set.
User avatar
jeffythedragonslayer
Posts: 344
Joined: Thu Dec 09, 2021 12:29 pm

Re: dynamic sprite size mode changing

Post by jeffythedragonslayer »

I haven't seen modes A, B, and C mentioned before. Is this your notation?
User avatar
Individualised
Posts: 310
Joined: Mon Sep 05, 2022 6:46 am

Re: dynamic sprite size mode changing

Post by Individualised »

jeffythedragonslayer wrote: Sat Mar 25, 2023 11:05 pm I haven't seen modes A, B, and C mentioned before. Is this your notation?
I believe the modes are referring to his algorithm and do not directly map to any hardware feature of the SNES.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: dynamic sprite size mode changing

Post by Oziphantom »

they clearly define it at the top

Code: Select all

	small		large
mode A:	8x8		16x16
mode B:	8x8		32x32
mode C:	16x16		32x32
but yes this is for the context of their post.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: dynamic sprite size mode changing

Post by psycopathicteen »

Individualised wrote: Sun Mar 26, 2023 5:20 am
jeffythedragonslayer wrote: Sat Mar 25, 2023 11:05 pm I haven't seen modes A, B, and C mentioned before. Is this your notation?
I believe the modes are referring to his algorithm and do not directly map to any hardware feature of the SNES.
Modes A, B and C were names I made up for the SNES sprite size modes.

"Mode A" is $2101 set to $00
"Mode B" is $2101 set to $01
"Mode C" is $2101 set to $03
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: dynamic sprite size mode changing

Post by tepples »

It looks like lately, I'm not the only member of this board to run into one of the two hard problems in computer science: cache invalidation and naming things. Would calling them "size 0, size 1, and size 3" be more palatable to other Super NES programmers?
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: dynamic sprite size mode changing

Post by Oziphantom »

combination A/B/C would probably be the most clear.
User avatar
jeffythedragonslayer
Posts: 344
Joined: Thu Dec 09, 2021 12:29 pm

Re: dynamic sprite size mode changing

Post by jeffythedragonslayer »

I like combination A, B, C. The sprites themselves already have sizes.
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: dynamic sprite size mode changing

Post by Fiskbit »

jeffy, this is how not to reply to cool new work that someone is showing off. Instead of talking about the work itself, we now have 7 replies that are all about an unimportant term used in the document. Replies are good, but when people make and share something, they don't want everyone focusing on trivial stuff about it that doesn't matter. There is meat here; discuss that and avoid bikeshedding.
Post Reply