Mode 1 BG3 layer priority question

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.
Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
SNES AYE
Posts: 370
Joined: Mon Nov 07, 2022 11:28 am

Mode 1 BG3 layer priority question

Post by SNES AYE »

Might seem obvious, but I just want to check, if I presume the layers are numbered 3 to 1 with three being the backmost 2bpp layer normally I think, can you set the BG3 priority to high so it appears in front of BG2 and behind BG1?

I ask because I know there's some quirkiness with how high and low various layers can be set relative to others, particularly in Mode 0 where some of the lowest layers can technically not be set above some of the higher layers as far as I understand it, plus I know BG3 in Mode 1 has the unique ability to be set above all other layers, so I just want to check BG3 in Mode 1 has not got a quirk where it can only be set as either the very lowest layer or the very highest layer and that's it.
I am neurodivergent, so if any of my posts unintentionally upset you, I apologize.
Fiskbit
Site Admin
Posts: 1379
Joined: Sat Nov 18, 2017 9:15 pm

Re: Mode 1 BG3 layer priority question

Post by Fiskbit »

This table on the wiki shows the precise ordering of the various layers in the various different modes, with the left end being the frontmost and right end being backmost. S3-S0 are the 4 sprite priories, and there are 4 background layers 1-4, each with H (high) and L (low) priorities. For mode 1 (and only mode 1), there is the extra BG3 priority feature that changes the priority of 3H, which is why mode 1 has 2 rows.
User avatar
Bregalad
Posts: 8181
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: Mode 1 BG3 layer priority question

Post by Bregalad »

Note: The content of this post below is wrong, but kept nonetheless for archival purposes.

No, there is no way BG3 can ever be between BG1 and BG2.
The only 2 options for having a 2BP graphics to appear be between BG1 and BG2 are:
1) using sprite of priority level 2 (this means you have to manually expand the graphics to 4BP in software)
2) use the window clipping function.

The two sub-techniques, if using window clipping, would be :
1) You enable BG3 priority, and you clip it off, so that BG1 appears to be in front of it
2) You disable BG3 priority (or simply use the lowest tile priority), and clip off BG2 so that it appears to be behind BG3.

Depending on the shape of what you have on your BGs, either 1), 2) or non of them might be feasible.
Last edited by Bregalad on Fri Dec 13, 2024 8:33 am, edited 2 times in total.
Useless, lumbering half-wits don't scare us.
SNES AYE
Posts: 370
Joined: Mon Nov 07, 2022 11:28 am

Re: Mode 1 BG3 layer priority question

Post by SNES AYE »

Bregalad wrote: Fri Dec 13, 2024 6:17 am No, there is no way BG3 can ever be between BG1 and BG2.
The only 2 options for having a 2BP graphics to appear be between BG1 and BG2 are 1) using sprite of priority level 2 (this means you have to manually expand the graphics to 4BP in software), or 2) use the window clipping function.

The two techniques would be :
1) You enableclip BG3 priority, and you clip it off, so that BG1 appears to be in front of it
2) You disable BG3 priority (or simply use the lowest tile priority), and clip off BG2 so that it appears to be behind BG3.

Depending on the shape of what you have on your BGs, either 1), 2) or non of them might be feasible.
OK, I suspected that might be the case.

So, in the Super Aleste example below, does that mean the cloud layer is BG3 and the ground is actually the BG2 layer that's semi-transparent and it just creates a very convincing illusion that the clouds are above the ground:

https://youtu.be/EQhPjAiSKhI?t=209

Otherwise, I would say they've done an amazing job within the 2bpp colour limitations if the ground layer is BG3 there.

And if it is BG2 that's semi-transparent, how do you think they've still managed to keep all the normal ground colours so bold, when I would have expected using the semi-transparency to kind of wash them out, or at least that's what I typically see when the effect is used?
Last edited by SNES AYE on Fri Dec 13, 2024 6:50 am, edited 1 time in total.
I am neurodivergent, so if any of my posts unintentionally upset you, I apologize.
SNES AYE
Posts: 370
Joined: Mon Nov 07, 2022 11:28 am

Re: Mode 1 BG3 layer priority question

Post by SNES AYE »

Fiskbit wrote: Fri Dec 13, 2024 6:04 am This table on the wiki shows the precise ordering of the various layers in the various different modes, with the left end being the frontmost and right end being backmost. S3-S0 are the 4 sprite priories, and there are 4 background layers 1-4, each with H (high) and L (low) priorities. For mode 1 (and only mode 1), there is the extra BG3 priority feature that changes the priority of 3H, which is why mode 1 has 2 rows.
OK, thanks for that.
I am neurodivergent, so if any of my posts unintentionally upset you, I apologize.
User avatar
Bregalad
Posts: 8181
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: Mode 1 BG3 layer priority question

Post by Bregalad »

I cannot look at your linked Youtube video right now, but as soon as transparency is involved, everything is different (and a bit more complicated). It does not matter if BG X is "above" or "below" BG Y. The most commonly used colour math (and the only one which produces actual transparency) is to average the main screen and sub screen. For areas not included in the transparency, you'd set the same layers in main and sub screen so that the average of two times the same colour result in that unaffected colour. If the main and sub screen are different however, the output is the average of both, as if they were transparent to eachother. This effect is applied after the BG and SPR priorities are used in both main and sub-screen, separately.

In that case, if you want BG 3 to be between BG1 and BG2, but appear transparent in front of BG2, you'll be doing the following setup :
Main Screen : BG1, BG2, Sprites
Sub-screen : BG1, BG3, Sprites

That way BG2 and BG3 will blend together, behind BG1 which will be unaffected by the colour math. There is some more subtilities going on which sprites will participate in the transparency, but hopefully you get the idea.
Useless, lumbering half-wits don't scare us.
Oziphantom
Posts: 1980
Joined: Tue Feb 07, 2017 2:03 am

Re: Mode 1 BG3 layer priority question

Post by Oziphantom »

haha ninja'd

so BG1 is the orange building
BG2 is the trees and water
BG3 is the clouds

So how does it do it.. we the magic here is Colour Maths.

So BG3 is Sub Screen, while BG1,2 and Sprites are Main Screen
Then Colour Math is set to Add Subscreen, and then BG2 and Background is enabled for the Maths Targets.

This way the SNES shows BG3 over BG2 by colour mathing the sub to it and background, BG1 and sprites still show on top of BG3+2 as the colour maths does not affect them.

So you can't put BG3 above BG2. But you can color maths Sub on parts of Main. So if the clouds where not "mathed" it wouldn't work.
User avatar
creaothceann
Posts: 862
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany

Re: Mode 1 BG3 layer priority question

Post by creaothceann »

EDIT: took a bit too long to write a reply

---

You can have BG3 between BG1 and BG2 by using color math.

register $2105: %xxxx0001 = enable BG Mode 1, disable BG3 high priority on top
register $212C: %xxx1x101 = enable BG1, BG3, sprites on mainscreen
register $212D: %xxx1x010 = enable BG2, sprites on the subscreen
register $2130: %xxxxxx10 = combine subscreen with mainscreen
register $2131: %00100000 = add subscreen only to mainscreen backdrop pixels

$2105.3 = 0 means that BG1 will cover BG3.
BG2 appears only on the subscreen, which is only added to any mainscreen pixels that are not filled with a BG or sprite pixel.

Note that this might need to be adjusted depending on where you want sprites to appear. With the registers set as above, any sprite pixel will cover BG3.
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
SNES AYE
Posts: 370
Joined: Mon Nov 07, 2022 11:28 am

Re: Mode 1 BG3 layer priority question

Post by SNES AYE »

Bregalad wrote: Fri Dec 13, 2024 7:03 am I cannot look at your linked Youtube video right now, but as soon as transparency is involved, everything is different (and a bit more complicated). It does not matter if BG X is "above" or "below" BG Y. The most commonly used colour math (and the only one which produces actual transparency) is to average the main screen and sub screen. For areas not included in the transparency, you'd set the same layers in main and sub screen so that the average of two times the same colour result in that unaffected colour. If the main and sub screen are different however, the output is the average of both, as if they were transparent to eachother. This effect is applied after the BG and SPR priorities are used in both main and sub-screen, separately.

In that case, if you want BG 3 to be between BG1 and BG2, but appear transparent in front of BG2, you'll be doing the following setup :
Main Screen : BG1, BG2, Sprites
Sub-screen : BG1, BG3, Sprites

That way BG2 and BG3 will blend together, behind BG1 which will be unaffected by the colour math. There is some more subtilities going on which sprites will participate in the transparency, but hopefully you get the idea.
Ah, okay, that makes more sense that it's not the actual layer itself that's being set to semi-transparent but rather the two being blended 50/50.

Now, since you mentioned the main screen and subscreen, would it be possible to trick the system slightly there by doing a variation of what you just said but with the BG3 layer on whichever out of the main/sub screen that would technically force it above the BG2 layer that would be on whichever of the main/sub screen that would force it below BG3, and just not activate transparency at all?

I hope you get what I mean there, but it's basically abusing the main screen and subscreen and not using any colour math transparency effects to force BG3 above BG2.
Last edited by SNES AYE on Fri Dec 13, 2024 7:22 am, edited 1 time in total.
I am neurodivergent, so if any of my posts unintentionally upset you, I apologize.
SNES AYE
Posts: 370
Joined: Mon Nov 07, 2022 11:28 am

Re: Mode 1 BG3 layer priority question

Post by SNES AYE »

creaothceann wrote: Fri Dec 13, 2024 7:16 am EDIT: took a bit too long to write a reply

---

You can have BG3 between BG1 and BG2 by using color math.

register $2105: %xxxx0001 = enable BG Mode 1, disable BG3 high priority on top
register $212C: %xxx1x101 = enable BG1, BG3, sprites on mainscreen
register $212D: %xxx1x010 = enable BG2, sprites on the subscreen
register $2130: %xxxxxx10 = combine subscreen with mainscreen
register $2131: %00100000 = add subscreen only to mainscreen backdrop pixels

$2105.3 = 0 means that BG1 will cover BG3.
BG2 appears only on the subscreen, which is only added to any mainscreen pixels that are not filled with a BG or sprite pixel.

Note that this might need to be adjusted depending on where you want sprites to appear. With the registers set as above, any sprite pixel will cover BG3.
Is this basically what I was just querying about above then regarding abusing the main screen and subscreens somewhat to force the BG3 layer higher than BG2? :)
I am neurodivergent, so if any of my posts unintentionally upset you, I apologize.
User avatar
Bregalad
Posts: 8181
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: Mode 1 BG3 layer priority question

Post by Bregalad »

Absolutely, I was wrong before thinking there was no trick to have BG3 between BG1 and BG2, sorry for that.

Strategy 1:
Main Screen : BG1, SPR
Sub-screen : BG3 (with priority bit set), BG2, SPR

Strategy 2:
Main Screen : BG1, BG3 (with priority bit clear), SPR
Sub-screen : BG2

You could also reverse the main and sub-screen above, for a total of 4 possible strategies, which could be more or less appropriate depending on what you want to do with your sprites.

Is there any known game who use the main and sub-screen to produce an alternate layer priority, rather than to have transparency ?
Useless, lumbering half-wits don't scare us.
User avatar
creaothceann
Posts: 862
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany

Re: Mode 1 BG3 layer priority question

Post by creaothceann »

Not off the top of my head. Might have come across one or several when I was writing vSNES, ages ago.
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
SNES AYE
Posts: 370
Joined: Mon Nov 07, 2022 11:28 am

Re: Mode 1 BG3 layer priority question

Post by SNES AYE »

Bregalad wrote: Fri Dec 13, 2024 8:32 am Is there any known game who use the main and sub-screen to produce an alternate layer priority, rather than to have transparency ?
Not that I'm immediately aware of, but I expect one or two developers in the past likely did use it somewhere.
I am neurodivergent, so if any of my posts unintentionally upset you, I apologize.