News:

11 March 2016 - Forum Rules

Main Menu

SNES PPU Question

Started by Squall_FF8, May 30, 2019, 08:52:00 AM

Previous topic - Next topic

Squall_FF8

This might be a little long, but please bear with me to understand the settings.
I'm trying to render a FF5 scene - Map with an ID 63 - North Mountain Fifth Station. Here is part of the map that I try to reconstruct:

The scene is in Mode 1 with 3 layers (BGs):
- Layer 1 (BG1) - the green summit
- Layer 2 (BG2) - the background
- Layer 3 (BG3) - the white clouds
*Layer 3 is in front of all (PPU register $2105)

In order to compose that scene, the games uses 3 PPU registers:
$212C Main Screen: L1 & L2
$212D Sub Screen: L1 & L3
$2131 Colo Math: affects L1 & L2. The math itself is half of addition
* for now we don't care about the other layers - Sprites

According to that video: https://www.youtube.com/watch?v=zcoU6-9_fDM
If Main render to a pixel from L1 we can have the following output:
- L1 (math) L1 => (L1 + L1) : 2 = L1
- L1 (math) L3 => (L1 + L3) : 2
If Main render to a pixel from L2:
- L2 math L1 => (L2 + L1) : 2
- L2 math L3 => (L2 + L3) : 2

Let me paraphrase above 4 cases:
- L1 -> result is L1 unmodified (opaque) - OK
- (L1 + L3):2 -> result is 50% transparent L3 over L1 (a 50% transparent cloud over a summit) - OK
- (L2 + L3):2 -> result is 50% L3 over L2 (a 50% transparent cloud over the background) - OK
- (L2 + L1):2 -> result is 50% L1 over L2 (the summit 50% transparent over the background) - PROBLEM!!!

The last combination never occur on the picture. Actually what we see on the picture are cases where L2 is unmodified (opaque).
My question is WHY? What went wrong? Do I miss something?
Welcome to the FF5 Den: https://discord.gg/AUqDF85

Disch

It's been a while, but IIRC this is how it works:

If a MAIN screen pixel is marked to participate in color math, the matching SUB screen pixel will get added into it.

Ignoring layer 3 for now, your problem is where layer 1 and 2 overlap.  When that happens: main screen will show layer 2 (higher priority), subscreen will show layer 1 (layer 2 isn't rendered to subscreen).

Since layer 2 (on the main screen) participates in color math, this means you'll add layer 1's subscreen pixel to layer 2's main screen pixel, resulting in the blend.

To solve this, you can just put layer 2 on the subscreen as well. This way main and sub screens will be identical (half color math will have no effect) EXCEPT for when layer 3 is visible on the subscreen, in which case it will be appropriately blended.

Squall_FF8

Thank you Disch!

As usual it is a pleasure to hear from you!

Your words confirm my understanding about how PPU Color Math works. I'm writting an Windows application that tries to render FF5 maps as accurate as possible (no windowing so far). Unfortunatly that case is against what the game shows and what the logic dictate.

BTW thank you for the advice for how to achive desired effect. Unfortunatle I have to read that values from the ROM not implying my own.
Welcome to the FF5 Den: https://discord.gg/AUqDF85

Disch

#3
Wait... so the game has those settings and is displaying properly?


EDIT:  Aha!  I think I mixed up BG1 and BG2 before.  I was thinking BG1 was the background.  If BG2 is the background... that changes things.

When BG1 and BG2 overlap:

mainscreen = BG1  (BG1 has higher priority)
subscreen = BG1  (ditto, also BG2 not rendered to subscreen)

So color math will have no effect, since it'll add BG1+BG1



Now the weirdness happens when BG1 and BG2 don't overlap, and only BG2 is visible:

mainscreen = BG2
subscreen = backdrop color (palette entry 0)

So the color math will and up blending the background layer with the backdrop color.  Which would probably have some kind of "dulling" effect on the background.

Squall_FF8

Quote from: Disch on May 30, 2019, 02:40:48 PM
When BG1 and BG2 overlap:

mainscreen = BG1  (BG1 has higher priority)
That is it! So the problematic situation although possible - will never occur!

Thank you very much Disch!
Welcome to the FF5 Den: https://discord.gg/AUqDF85

Bregalad

Quote from: Disch on May 30, 2019, 02:40:48 PMSo the color math will and up blending the background layer with the backdrop color.  Which would probably have some kind of "dulling" effect on the background.
It's been a while since I've been dealing with this, but wasn't there an exeption with the backdrop color where it was not halved when participating in color math ? In that case it's fine, the BG1 adds with backdrop color (which is pitch black so this has no effect), and then it doesn't halve because it's the backdrop color.

Disch

Quote from: Bregalad on May 31, 2019, 07:45:57 AM
but wasn't there an exeption with the backdrop color where it was not halved when participating in color math ?

Ah!  Maybe!  That sounds right.  I forgot about that completely.  Nice catch.

Squall_FF8

Thank you Bregalad for the input!

Yes it seems that is the case and it work for the backdrop exactly as you described. Here is the extra description on $2131 I found recently:
Quoted6   "1/2 of color data" designation
         when the color constant addition/subtraction or the
         screen addition/subtraction is performed, designate
         whether the rgb result in the addition/subtraction
         area should be "1/2" or not. however, in the back
         color constant area on the sub screen, it does not
         become "1/2"
Welcome to the FF5 Den: https://discord.gg/AUqDF85