Can I mix opaque and transparent on a single background?

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
iNCEPTIONAL

Can I mix opaque and transparent on a single background?

Post by iNCEPTIONAL »

As per the title: Can I have both opaque and transparent parts on the same background layer (even if it involves switching a some point down the screen as the graphics are drawn)?

And, if so, what are the limits to this? Is it just doing the switching on the next scanline as I mentioned (so it can only be done in horizontal rows), or is it based on selected palettes so you can make certain tiles drawn in one palette transparent and others opaque (similar to how it works with the sprites).

Is that what is happening in this game where the HUD is opaque and then it looks like the transparent fog lower down the screen is in fact using the same layer 3: https://youtu.be/pxJpOA36-4g?t=270 and https://youtu.be/pxJpOA36-4g?t=388 And here in this game too: https://youtu.be/ihHW4f6k-DI?t=1132
lidnariq
Posts: 11430
Joined: Sun Apr 13, 2008 11:12 am

Re: Can I mix opaque and transparent on a single background?

Post by lidnariq »

In this case the SNES calls this "color math", not "transparency" - on most older consoles, transparency is a yes/no property. Color math allows you to combine two layers via simple addition, simple average, or simple subtraction.

You can change how layers are mixed on a scanline-by-scanline basis, so it could well be the same as the HUD layer.
iNCEPTIONAL

Re: Can I mix opaque and transparent on a single background?

Post by iNCEPTIONAL »

lidnariq wrote: Fri Apr 29, 2022 3:04 pm In this case the SNES calls this "color math", not "transparency" - on most older consoles, transparency is a yes/no property. Color math allows you to combine two layers via simple addition, simple average, or simple subtraction.

You can change how layers are mixed on a scanline-by-scanline basis, so it could well be the same as the HUD layer.
Good stuff.

The more I learn, the more I think about all the amazing things I can do with this awesome console.

It boggles my mind how little it was ever truly pushed to its absolute limits--and just what might be possible. . . .

And who's gonna work with me on doing it!
Last edited by iNCEPTIONAL on Fri Apr 29, 2022 3:33 pm, edited 2 times in total.
User avatar
NovaSquirrel
Posts: 483
Joined: Fri Feb 27, 2009 2:35 pm
Location: Fort Wayne, Indiana
Contact:

Re: Can I mix opaque and transparent on a single background?

Post by NovaSquirrel »

There's an example of reusing the HUD layer for translucent effects in Super Mario World, with translucent fish.
You can change color math settings on a scanline-by-scanline basis, and you can go a step further and use windows to pick two horizontal spans of pixels per scanline that should (or shouldn't) use color math.
iNCEPTIONAL

Re: Can I mix opaque and transparent on a single background?

Post by iNCEPTIONAL »

NovaSquirrel wrote: Fri Apr 29, 2022 3:32 pm There's an example of reusing the HUD layer for translucent effects in Super Mario World, with translucent fish.
You can change color math settings on a scanline-by-scanline basis, and you can go a step further and use windows to pick two horizontal spans of pixels per scanline that should (or shouldn't) use color math.
Ah, yeah, that's a nice and subtle use of it there.

Yeah, the two window masks plus colour math is how I plan to do the planet and the shadow on it in my shmup. It's how I get away with only using two main background layers for the rotating planet with shadow plus all the overlapping stars and asteroids (which alone the Genesis would struggle with because it doesn't really do window masking or colour math), and still have two entire background layers left to do whatever the hell I want with.
Last edited by iNCEPTIONAL on Fri Apr 29, 2022 5:29 pm, edited 1 time in total.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Can I mix opaque and transparent on a single background?

Post by rainwarrior »

Secret of Mana did interesting things with transparency.

For areas that had water and didn't need a parallax layer, there's a pretty complex interaction:
som_blend_example.png
som_blend_example.png (29.85 KiB) Viewed 390 times
Left column: from top to bottom you have BG1 high priority, BG2 high priority, BG1 low priority, BG2 low priority.

Right column 1: the main screen, just a stack of the left column.

Right column 2: the sub screen, just BG1, but both layers of it.

Right column 3: the final blend.

So you get a combination of effects:
  • Blending water with ground gives a lovely translucent water effect.
  • Blending tree with itself is a visual no-op, but allows an over-top layer the player can walk underneath.
  • Transparent sub-screen pixels don't participate in the blend allowing a bottom layer of grass underneath the tree.
  • (Not shown) The player sprite is split into two 16x16 pixel halves, allowing their bottom half to be occluded in the main screen, so it gets the underwater look too.
So they managed to pull off both a foreground layer above the player (ragged shape occlusion rather than just 8x8 tiles) and blending for water, both with the same setup. Of course, both of those can't happen in the same place. Anywhere it is wet, you can't go under a foreground layer.

In areas of the game that needed a parallax background (e.g. the Lofty Mountains), they similarly design the environment so you can't go under a ragged foreground layer. The misty forest on the way to the Witch's Castle similarly sacrifices the foreground layer for a free-scrolling mist blend.
User avatar
Dwedit
Posts: 4922
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Can I mix opaque and transparent on a single background?

Post by Dwedit »

One often-forgotten feature of the SNES is the ability to draw single color filled shapes by using the Window feature and HDMA. With two windows, the polygon can intersect a horizontal line up to twice.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
iNCEPTIONAL

Re: Can I mix opaque and transparent on a single background?

Post by iNCEPTIONAL »

rainwarrior wrote: Fri Apr 29, 2022 4:05 pm Secret of Mana did interesting things with transparency.

For areas that had water and didn't need a parallax layer, there's a pretty complex interaction:
som_blend_example.png

Left column: from top to bottom you have BG1 high priority, BG2 high priority, BG1 low priority, BG2 low priority.

Right column 1: the main screen, just a stack of the left column.

Right column 2: the sub screen, just BG1, but both layers of it.

Right column 3: the final blend.

So you get a combination of effects:
  • Blending water with ground gives a lovely translucent water effect.
  • Blending tree with itself is a visual no-op, but allows an over-top layer the player can walk underneath.
  • Transparent sub-screen pixels don't participate in the blend allowing a bottom layer of grass underneath the tree.
  • (Not shown) The player sprite is split into two 16x16 pixel halves, allowing their bottom half to be occluded in the main screen, so it gets the underwater look too.
So they managed to pull off both a foreground layer above the player (ragged shape occlusion rather than just 8x8 tiles) and blending for water, both with the same setup. Of course, both of those can't happen in the same place. Anywhere it is wet, you can't go under a foreground layer.

In areas of the game that needed a parallax background (e.g. the Lofty Mountains), they similarly design the environment so you can't go under a ragged foreground layer. The misty forest on the way to the Witch's Castle similarly sacrifices the foreground layer for a free-scrolling mist blend.
I learn something new every day.

When I think of all the ideas I've already had for ways to do cool stuff on SNES, most of which I have honestly never or very rarely seen on the system, and then ponder that this is what I've come up without even knowing every single thing it can technically do (and I can't even program a single line of code on the system)--but some of my ideas have been tested in a Super Mario ROM hack and they certainly work (at least there)--it's kinda crazy to ponder what could be achieved with a programmer who's got the talent to break out of the box too. . . .

Great ideas plus great execution could spell something very special, methinks.
iNCEPTIONAL

Re: Can I mix opaque and transparent on a single background?

Post by iNCEPTIONAL »

Dwedit wrote: Fri Apr 29, 2022 4:23 pm One often-forgotten feature of the SNES is the ability to draw single color filled shapes by using the Window feature and HDMA. With two windows, the polygon can intersect a horizontal line up to twice.
I'm not quite sure exactly what that means, but I'm def gonna use the window/shape masking as much as I can in any of my games (already doing it for my rotating planet with shadow, and it looks rather cool, if I do say so myself). :D

I have a whole bunch of ideas for how to use it in creative ways, some to really trick people into thinking the machine can do a lot more than it can (well, technically, it obviously can, albeit maybe not quite in the way it appears).

Note: When I say "doing it", I mean when the programmer [whoever they may be] actually gets around to programming it on SNES in the way I've designed it to work. LOL
Post Reply