Max Overlapping Layers

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
User avatar
dougeff
Posts: 3047
Joined: Fri May 08, 2015 7:17 pm

Max Overlapping Layers

Post by dougeff »

I made a Mode 0 demo, using every possible layer priority. Actually, I made 2 versions because my first attempt at a fixed color window didn't do what I expected, but it was an interesting result, so I included it.

Mode 0 Layers - y level

backdrop color - top of screen (furthest back)
BG4 tiles with priority 0 - 10
BG3 tiles with priority 0 - 20
Sprites with priority 0 - 30
BG4 tiles with priority 1 - 40
BG3 tiles with priority 1 - 50
Sprites with priority 1 - 60
BG2 tiles with priority 0 - 70
BG1 tiles with priority 0 - 80
Sprites with priority 2 - 90
BG2 tiles with priority 1 - a0
BG1 tiles with priority 1 - b0
Sprites with priority 3 - c0
Fixed color window on top (furthest forward)

Color Math with Window, clip to black, then add the fixed color

The demo is called Face0
Face0.png
Face0.png (8.66 KiB) Viewed 862 times
.

.

The 2nd one is the same except only enabling window 1 for color math... somehow sprites were not included in that (even though color math is enabled for OBJ). I checked it on hardware, and this is in fact the case.

FaceB is this... with black spots where the sprites were.
FaceB.png
FaceB.png (8.96 KiB) Viewed 862 times
in order to fix it, I had to have window 1 affect all layers (not just color math) and enable windows for everything on the main screen (212e)



Anyway, I guess this is 13 layers.
Attachments
LAYERDEMO.zip
(3.3 KiB) Downloaded 28 times
nesdoug.com -- blog/tutorial on programming for the NES
lidnariq
Posts: 11207
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Max Overlapping Layers

Post by lidnariq »

Whether sprites are included in color math should depend on which palette index they're using "(OBJ Palette 4-7 can use Color Math via CGADSUB)"

Since you bothered to color-code the layers but didn't state it explicitly:

orange=BG4
green=BG3
purple=sprites
red=BG2
blue=BG1
User avatar
dougeff
Posts: 3047
Joined: Fri May 08, 2015 7:17 pm

Re: Max Overlapping Layers

Post by dougeff »

Oh yeah. I remember now, from all the previous discussions about transparent Sprites (color math, add, divide half).
nesdoug.com -- blog/tutorial on programming for the NES
iNCEPTIONAL

Re: Max Overlapping Layers

Post by iNCEPTIONAL »

Very cool demo, dougeff.

So, from what I'm interpreting from all the previous comments I read above--sorry if I've gotten those wrong once again--you definitely couldn't have any semi-transparency effect applied on one of the background layers there with everything else that's going on, due to how you're doing the line shape right at the front with masks/colour math/Main-screen/Subs-screen (however it's precisely done), no matter how you try to wangle it, you can only have one of those effects going on at a time (either the semi-transparent layer or that shape in front of everything else), right?

Limits one idea I had for one of my levels a tiny bit, but, what is cool, is it seems you can definitely have at least an opaque shape on top of all those layers, including the "layer" that is really just the background/backdrop colour.

And, I can't tell if you did that here, but you could technically have two separate opaque shapes right at the front by using both of the available window/shape masks, correct?

Please, I'm sorry if I'm not using the exact correct terminology--I know everyone can't seem to figure out what I'm actually trying to say unless I do, and often not even then, it seems--when responding to my questions, try to interpret what I'm saying and asking the way I'm trying to say and ask it rather than the exact way I've written it if it is not 100% technically correct.

Note: This frustration that might be coming across is not aimed at you, but just a general appeal.
Last edited by iNCEPTIONAL on Wed Jul 20, 2022 12:24 pm, edited 5 times in total.
User avatar
dougeff
Posts: 3047
Joined: Fri May 08, 2015 7:17 pm

Re: Max Overlapping Layers

Post by dougeff »

Used the original code with Sprites all using palette 4... works fine.

Windows are only active for color math and don't affect anything else.

(picture would look the same as face0 above)
Attachments
LAYERDEMO2.zip
(1.67 KiB) Downloaded 18 times
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
dougeff
Posts: 3047
Joined: Fri May 08, 2015 7:17 pm

Re: Max Overlapping Layers

Post by dougeff »

again--you definitely couldn't have any semi-transparency effect applied on one of the background layers there with everything else that's going on
I'm using color math addition with the fixed color, using windows to limit where it goes.

You can only have one kind of color math going on... though, possibly you could have one effect for the top of the screen and a different effect lower on the screen
you could technically have two separate opaque shapes
Correct. There are 2 windows to use.
nesdoug.com -- blog/tutorial on programming for the NES
iNCEPTIONAL

Re: Max Overlapping Layers

Post by iNCEPTIONAL »

dougeff wrote: Wed Jul 20, 2022 12:23 pm
again--you definitely couldn't have any semi-transparency effect applied on one of the background layers there with everything else that's going on
I'm using color math addition with the fixed color, using windows to limit where it goes.

You can only have one kind of color math going on... though, possibly you could have one effect for the top of the screen and a different effect lower on the screen
you could technically have two separate opaque shapes
Correct. There are 2 windows to use.
Yeah, I was thinking about potentially switching things part way down the screen (I assume using HDMA), because then I could still have the semi-transparent water at the bottom half of the screen in my ice level while also drawing some large opaque shape at the top of the screen where I don't really have to use any semi-transparent effect (can turn it off for the couple small things that currently do use it in the top half if necessary).

OK, cool.
iNCEPTIONAL

Re: Max Overlapping Layers

Post by iNCEPTIONAL »

dougeff wrote: Wed Jul 20, 2022 12:23 pm
you could technically have two separate opaque shapes
Correct. There are 2 windows to use.
And, do both of them have to use the same colour in your example?

They could also technically pass across/over/on top of each other too, at least as an optical illusion, just by changing the "position" of them onscreen (by updating the left/right values of the window/shape mask every frame), so you could effectively make it look like two shapes moving across the screen in the very foreground closet to the "camera" at different speeds for another subtle effect of additional parallax (especially if you make one larger than the other so one appears even closer than the other), correct?
User avatar
dougeff
Posts: 3047
Joined: Fri May 08, 2015 7:17 pm

Re: Max Overlapping Layers

Post by dougeff »

You can change the fixed color with HDMA. If one object (made by color math windows using the fixed color) is higher on the screen than the other, they can be different colors.
nesdoug.com -- blog/tutorial on programming for the NES
93143
Posts: 1624
Joined: Fri Jul 04, 2014 9:31 pm

Re: Max Overlapping Layers

Post by 93143 »

You could also mix window types. If you used one window to mask off all the layers, and another to mask off all the layers and either the main or sub backdrop (either by blacking the main screen or by turning off colour math), the two shapes could be different colours on the same scanline.

Of course, you have to take into account colour sharing issues when doing this - if any main+sub backdrop blending happens outside the windows, it will be the same colour as the blended window. And unfortunately you can't have one window black the main screen and the other turn off colour math, because they'd both have to be Color windows and CGWSEL would apply to both.
User avatar
dougeff
Posts: 3047
Joined: Fri May 08, 2015 7:17 pm

Re: Max Overlapping Layers

Post by dougeff »

I redid it in MODE 1.

backdrop color
BG3 tiles with priority 0 - 10
Sprites with priority 0 - 20
BG3 tiles with priority 1 if bit 3 of $2105 is clear - 30
Sprites with priority 1 - 40
BG2 tiles with priority 0 - 50
BG1 tiles with priority 0 - 60
Sprites with priority 2 - 70
BG2 tiles with priority 1 - 80
BG1 tiles with priority 1 - 90
Sprites with priority 3 - a0
BG3 tiles with priority 1 if bit 3 of $2105 is set - b0

Using HDMA to flip the $2105 bit mid screen.

blue = BG3
red = BG2
green = BG1
purple = sprites
.
Face1.png
Face1.png (8.15 KiB) Viewed 700 times
LAYERDEMO3.zip
(1.89 KiB) Downloaded 14 times
nesdoug.com -- blog/tutorial on programming for the NES
iNCEPTIONAL

Re: Max Overlapping Layers

Post by iNCEPTIONAL »

"BG3 tiles with priority 1 if bit 3 of $2105 is set . . . Using HDMA to flip the $2105 bit mid screen."

I still don't think I've had a definitive answer from anyone why this can't also be done in Mode 0?

Again, I might not be quoting the exact part of the text that counts, but, basically, if you can bring BG3 to the front in Mode 1, why can't you do similarly in Mode 0?

The reason it can't be done in any of the other modes, at least as far as I understand it, is because they literally don't even have a BG3, but Mode 0 does.
User avatar
dougeff
Posts: 3047
Joined: Fri May 08, 2015 7:17 pm

Re: Max Overlapping Layers

Post by dougeff »

why this can't also be done in Mode 0?
You'd have to ask the engineer who designed the PPU

Unfortunately, I think he passed away recently

https://www.japantimes.co.jp/news/2021/ ... ator-dies/
nesdoug.com -- blog/tutorial on programming for the NES
iNCEPTIONAL

Re: Max Overlapping Layers

Post by iNCEPTIONAL »

dougeff wrote: Wed Jul 20, 2022 4:13 pm
why this can't also be done in Mode 0?
You'd have to ask the engineers who designed the PPU
Well, I guess I meant to ask it more like "Can this really not be done in Mode 0 too, for total and absolute sure, as tested first-hand by someone to confirm this beyond any reasonable doubt?"

The confusion in what I was actually asking in my previous post there is on me.
User avatar
dougeff
Posts: 3047
Joined: Fri May 08, 2015 7:17 pm

Re: Max Overlapping Layers

Post by dougeff »

Definitely doesn't work in Mode 0.

top blue is BG1 priority 0
lower blue is BG1 priority 1
both greens BG3 priority 1
$2105 has BG3 priority bit set

BG1 is always on top of BG 3 in Mode 0

(picture of real SNES on CRT)
Attachments
Screenshot_20220720-210436_Gallery.jpg
nesdoug.com -- blog/tutorial on programming for the NES
Post Reply