Transparency on the SNES

Discussion of development of software for any "obsolete" computer or video game system.
93143
Posts: 1104
Joined: Fri Jul 04, 2014 9:31 pm

Re: Transparency on the SNES

Post by 93143 » Thu Mar 14, 2019 1:41 pm

Okay, I've come up with a demo of the idea I detailed above. I used the graphics provided by Marscaleb in the other thread.
dungeon_mainscreen.png
dungeon_mainscreen.png (22.03 KiB) Viewed 5931 times
This is the main screen. It's mostly set up for shadowing, but the area around the torch isn't. No effects have been applied; those are the colours as read directly from the palette.

dungeon_subscreen.png
dungeon_subscreen.png (15.31 KiB) Viewed 5931 times
This is the subscreen. Areas to be shadowed are masked off, and the torch and staff are given halo highlights. Again, these are direct palette colours with no effects.

Note that it's not necessary to have full texture in the subscreen layer. The classic subtractive shadowing effect would actually be better reproduced by using a uniform boost colour on the subscreen, with all the detail on the main screen. But I figured this looked more realistic...


The result of adding together the previous two images:
dungeon_added.png
dungeon_added.png (25.45 KiB) Viewed 5931 times
Hopefully that helps clarify what I was getting at with my wall of text. Please excuse any incompatibility with what the game is actually trying to do or what the graphics are intended to represent in 3D space*; this is just a demonstration of a concept and should not be taken as a specific suggestion.

Also note that if you're going to attempt something like this, you should make sure you're very familiar with how transparency works on the SNES. There are tons of arcane gotchas that only make sense if you understand the system really well, and it's easy to trip over them when designing a "SNES-like" PC game. Bregalad's writeup is a good start, but you need to understand how backgrounds, windowing and HDMA work too.

Which reminds me - there's a great YouTube series on the SNES that explains the technical details of the console with visual illustrations. I've found it to be very accurate, although unfortunately it's not done yet and doesn't update quickly. This is the one on DMA and HDMA: https://www.youtube.com/watch?v=K7gWmdgXPgk


* For instance, I've assumed the rusty metal-looking things are solid doors rather than support columns, because otherwise the light cast by the torch would fall on the player character and I wouldn't get to demonstrate glow-in-shadow.

User avatar
koitsu
Posts: 4214
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Transparency on the SNES

Post by koitsu » Thu Mar 14, 2019 3:31 pm

Some of what's being depicted and discussed remind me of the effects used in Soul Blazer. See: ref 1 (note lighting effect around orb) and ref 2 (note "slight shift" in the area around the orb (hard to see on the low-quality recording), and the fact that things like stairways and chests become visible when within that area).

I forget exactly how these are implemented, but IIRC, it's a combination of add/sub screen effects + BG3 + priority bits + HDMA (for achieving the circular shape of the orb effects). The latter (use of HDMA) might not work well if you have, say, several torches on the screen at once, but should work if they all were sprites or tiles utilising BG3 in the manner Bregalad described.

Never forget that designing a game and then "trying to make the system comply with your demands" is not always the most feasible approach; the opposite (design a game with the limitations/design of the system in mind) is more practical, IMO. Just something to keep in mind when developing something. (93143 is the one guy who goes to great lengths to do the former, solely for the challenge. Haha :D )

I've seen the YT videos in question. They're "okay". Sometimes video is not the correct medium to use for training material, other times it's better than text; there's some stuff in there that is super helpful, other stuff that just makes my eyes gloss over. Everyone learns differently.

User avatar
Bregalad
Posts: 7750
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Re: Transparency on the SNES

Post by Bregalad » Sat Mar 16, 2019 4:22 pm

Hopefully that helps clarify what I was getting at with my wall of text. Please excuse any incompatibility with what the game is actually trying to do or what the graphics are intended to represent in 3D space*; this is just a demonstration of a concept and should not be taken as a specific suggestion.
To acomplish what is made on your mockups (light up two different circles), you don't even need any layers. Just use windows clipping (combined with HDMA) and constant colour math. It's possible to do 2 shapes, but not 3 as that's how window clipping works. Since you want to do 2, that's exactly what you want to do.

93143
Posts: 1104
Joined: Fri Jul 04, 2014 9:31 pm

Re: Transparency on the SNES

Post by 93143 » Sun Mar 17, 2019 1:18 am

My point is that the entire background (except for the square around the torch) can also be selectively shadowed at the same time. The shadow cast by the wooden platform, for instance, is achieved by using a window with HDMA to mask off the subscreen layer under it. I don't know if I was adequately clear about this - the "subscreen" I posted is before color math, but after windowing.


Nitpicking for the benefit of others less familiar with this topic:

You can do a more or less arbitrary number of glowy bits (notice that the flame, and not just the circle around it, is additive) as long as you use BG or sprite graphics for them. Except obviously that you can't use a sprite to cast a glow on another sprite.

You can certainly do more than two window shapes at a time. Just no more than two on the same line (barring edge cases). If they're scripted, as with certain types of full-screen effects, or locked to the BG layer, as with that torch, it's just a matter of planning.

...

This idea of mine might make more sense in a game where individual sprites can cast shadows, particularly a Mode 7 game where BG2 is so limited that you might as well use it for tricks like this. I originally came up with it when thinking of an F-Zero game in which the glowing exhaust trail has to show up over the car's shadow, but also over the glowing track edge and distant ground, neither of which should be shadowed by the car.

For a game like this, the method might be needlessly cute. If the torches are the only thing casting light, and sprites don't cast individual shadows, there's not much point in trying to combine glow effects with dynamic shadows, especially at such a cost in resources.

Post Reply