Using window/shape mask directly on the background colour . . .

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.
iNCEPTIONAL

Using window/shape mask directly on the background colour . . .

Post by iNCEPTIONAL »

Can I use window/shape masking to draw a simple circle shape on the main background colour and in a different colour, so basically behind all the actual background layers?

I know HDMA can be used to change the background colour every scanline and also define the shape of a window/shape mask for example, but I kinda want to create the illusion of a simple circle planet behind all the other background layers rather than using any of them for that planet shape, and this I'm not sure if it can be done.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Using window/shape mask directly on the background colour . . .

Post by Pokun »

No you can't draw stuff with the Windows, they are for clipping holes into the backgrounds and won't work with the backdrop colour since it's not really a background. There is nothing that can be behind the backdrop.
iNCEPTIONAL

Re: Using window/shape mask directly on the background colour . . .

Post by iNCEPTIONAL »

Pokun wrote: Tue Jun 28, 2022 4:35 pm No you can't draw stuff with the Windows, they are for clipping holes into the backgrounds and won't work with the backdrop colour since it's not really a background. There is nothing that can be behind the backdrop.
OK.

One thing though: Although they're technically for "clipping holes" in backgrounds, I can use window/shape masks to at least draw what looks like an extra shape on top of all the background layers though, right?

Let's think of the beam in Super Metroid for example, where it looks like it's a semi-transparent coloured beam on top of the backgrounds rather than something cut out of either of the layers*. Or the expanding circle explosion effect in Contra III, which, again, is visibly shown on top of all the other graphics rather then looking like it's cut out of the backgrounds**. Or the disco light in Super Mario World, that once again appears to on top of the rest of the visuals rather than like it's cut out of the backgrounds***.

So, I could use the window/shape mask to effectively mark the shape of a similar beam in my game and then just use some colour math (I think the fixed colour) to make everything behind that beam shape a different colour (say with a bright green tint, so that it looks like some green alien beam), correct?

If I understand how this works properly, with creative use, I think you could even use the two window/shape masks to fake extra layer parallax too (on top of all the other layers), by having say two black shapes in front of everything else moving at a different speed so it looks like a silhouette of whatever thing moving past the in the foreground close to the camera. Let's imagine you have a crowd of people created using normal background layers for some nice depth and parallax, and then you could have two rather simple human silhouette shapes [working within the limits of what you can draw with the window/shape mask) also moving past the camera right in the foreground, so the crowd looks even more dense. I think this could effectively allow me to potential have six overlapping backgrounds layers in my shmup if used properly (four real ones and two [simple] fake ones using the two possible window/shape makes). That would be possible, right?

*https://youtu.be/Y9tufNHthJE?t=426
**https://youtu.be/i5JJlhThiY4?t=1251
***https://youtu.be/zcoU6-9_fDM?t=681
Last edited by iNCEPTIONAL on Tue Jul 19, 2022 10:51 am, edited 11 times in total.
User avatar
jeffythedragonslayer
Posts: 344
Joined: Thu Dec 09, 2021 12:29 pm

Re: Using window/shape mask directly on the background colour . . .

Post by jeffythedragonslayer »

I don't see anything in Chapter 6 Window (Window Mask) of the official documentation that indicates this is possible. I think you will have a much easier time drawing a planet in front of the 4 BG layers, like the spotlight effect here:

https://nesdoug.com/2020/06/16/color-math/

What I do not understand is why there are 6 layers being referred to here at 2:26:

https://youtu.be/zcoU6-9_fDM?t=138

If there are 6 versions of the flag, then it should be possible to clip the bottom layer called "color" independently, without also clipping any of the 4 BG layers nor the OBJ layer.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Using window/shape mask directly on the background colour . . .

Post by Dwedit »

Here is an example of a SNES game doing something interesting with the Window feature:

https://www.youtube.com/watch?v=H8-PqwzHho8&t=677s

It's a boxing game that shows a Mode 7 scaled opponent, and a flat colored boxing ring.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
iNCEPTIONAL

Re: Using window/shape mask directly on the background colour . . .

Post by iNCEPTIONAL »

Dwedit wrote: Tue Jun 28, 2022 5:42 pm Here is an example of a SNES game doing something interesting with the Window feature:

https://www.youtube.com/watch?v=H8-PqwzHho8&t=677s

It's a boxing game that shows a Mode 7 scaled opponent, and a flat colored boxing ring.
Yeah, I've seen that before and it's a very novel way of using both Mode 7 and window/shape masking. Pity they didn't have a slightly better artist creating the rest of the visuals--and I think they should have had the boxer normally zoomed to the level where the pixels are 1:1 most of the time, so maybe draw the closer version at the correct resolution and zoom him out slightly when he steps back, rather than draw him at the correct resolution when he's back from you and zoom in him when he gets close, which he is close more often than not so he always looks overly pixellated (a common mistake when using Mode 7 zooming imo)--because this could have been a very sweet looking game with cool graphical stuff to boot. Still very neat though.

Edit: Although, it may be they have to draw the fighter at a slightly smaller size in order to have all the animation frames on the Mode 7 layer too? Is it dynamically loading in a new Mode 7 image for every animation frame, or are they all spread out on the one Mode 7 layer and the view is just jumping between them, or something like that?

Note: And isn't this kinda doing exactly what I'm enquiring about regarding window/shape masking? Because if Mode 7 can only display a single background layer then surely the ring floor that's done with window/shape masking and some colour math [or whatever it is] here must be doing so on top of only the main background colour, no?
Last edited by iNCEPTIONAL on Tue Jun 28, 2022 6:42 pm, edited 2 times in total.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Using window/shape mask directly on the background colour . . .

Post by Dwedit »

Having a single color used for the window is not color math. Color math means that colors are getting blended with each other.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
iNCEPTIONAL

Re: Using window/shape mask directly on the background colour . . .

Post by iNCEPTIONAL »

Dwedit wrote: Tue Jun 28, 2022 6:19 pm Having a single color used for the window is not color math. Color math means that colors are getting blended with each other.
Well, as per usual, the exact technical stuff is not the actual point of what I'm asking but more the end result. Whatever the name, it's the ultimate effect I'm interested in. I'm not a SNES programmer but I'm trying my best to call these things names that hopefully some people will understand what I'm trying to get at. So, be it colour math, fixed colour, whatever, I'm interested in using the whole window/shape masking with a colour to try and draw what would look like a planet behind all my background layers, and that boxing game example seems to suggest that what I'm thinking might in fact be possible. If so, that would give my game the illusion of even more depth and parallax.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Using window/shape mask directly on the background colour . . .

Post by dougeff »

Off subject, but I thought I would add unrelated information that I find interesting...

the "window" on the Sega Genesis and the Gameboy work like a static (non-scrolling) layer... and not at all like the SNES "windows" that just punch holes in real layers.
nesdoug.com -- blog/tutorial on programming for the NES
turboxray
Posts: 348
Joined: Thu Oct 31, 2019 12:56 am

Re: Using window/shape mask directly on the background colour . . .

Post by turboxray »

dougeff wrote: Tue Jun 28, 2022 7:01 pm Off subject, but I thought I would add unrelated information that I find interesting...

the "window" on the Sega Genesis and the Gameboy work like a static (non-scrolling) layer... and not at all like the SNES "windows" that just punch holes in real layers.
And the Supergrafx window layer is more like the snes..
https://www.youtube.com/watch?v=75IdGO1I1o4
https://www.youtube.com/watch?v=0dVFfrfvmeY
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Using window/shape mask directly on the background colour . . .

Post by rainwarrior »

I think you can do what is asked in the OP.

1. Put color math only on the backdrop. (CGADSUB)
2. Enable the windows for colormath only (WOBJSEL)

Then with HDMA:
1. Use the windows to create the shape you want to appear on the backdrop.
2. Use CGDATA with a color value that will blend against the backdrop color to produce the desired color.

With a single window you can create any convex shape. With both windows you can create a slightly more complicated shape.
User avatar
jeffythedragonslayer
Posts: 344
Joined: Thu Dec 09, 2021 12:29 pm

Re: Using window/shape mask directly on the background colour . . .

Post by jeffythedragonslayer »

Ok then, I think the bottom layer of the 6 referred to in the video as "color" is the same one refered to as "MATH" under the WOBJSEL section in fullsnes. Sounds encouraging.

I don't see why one window limits you to a convex shape though.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Using window/shape mask directly on the background colour . . .

Post by rainwarrior »

I didn't mean to imply that it only does convex shapes, but you can do any convex shape with just 1 window. OP was talking about a "planet" which seems like it'd probably be convex.

I don't have a name for a shape that matches exactly the capabilities of 1 window. Convex is a subset of that. Maybe "horizontally convex"? The shape can either have 2 edges on a scanline (1 window) or 4 (2 windows).
iNCEPTIONAL

Re: Using window/shape mask directly on the background colour . . .

Post by iNCEPTIONAL »

dougeff wrote: Tue Jun 28, 2022 7:01 pm Off subject, but I thought I would add unrelated information that I find interesting...

the "window" on the Sega Genesis and the Gameboy work like a static (non-scrolling) layer... and not at all like the SNES "windows" that just punch holes in real layers.
Although, it costs part of one of the two background layers available on Genesis rather than being something you can use on or in addition to the four background layers on SNES, such that wherever you use this "window" on Genesis, you have to sacrifice background visuals there on that layer. This is why, if you look at a game like Streets of Rage 2, you will find there's only ever a single background layer behind the HUD section. They do a real good job of hiding this limitation in that game but once you see it, it cannot be unseen: https://youtu.be/sg3nCR6NvWU?t=578

What it made me realise is that I could do everything seen in the backgrounds of a beat 'em up game like Streets of Rage 2 on SNES similarly using only two of the layers in Mode 1 (with far more colours and additional transparency to boot), including doing a full colour HUD (which developers often resort to using the low colour background on SNES), and still have the entire low colour layer to spare alongside those two window/shape masks for maybe some added little effects.
Last edited by iNCEPTIONAL on Tue Jul 19, 2022 10:05 am, edited 1 time in total.
User avatar
jeffythedragonslayer
Posts: 344
Joined: Thu Dec 09, 2021 12:29 pm

Re: Using window/shape mask directly on the background colour . . .

Post by jeffythedragonslayer »

rainwarrior wrote: Wed Jun 29, 2022 12:56 am I didn't mean to imply that it only does convex shapes, but you can do any convex shape with just 1 window. OP was talking about a "planet" which seems like it'd probably be convex.

I don't have a name for a shape that matches exactly the capabilities of 1 window. Convex is a subset of that. Maybe "horizontally convex"? The shape can either have 2 edges on a scanline (1 window) or 4 (2 windows).
Monotone polygon. With two windows you can draw the 5 pointed star and ninja star shapes as well:

https://en.m.wikipedia.org/wiki/Monotone_polygon
Post Reply