Partial transparency on objects?

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

Partial transparency on objects?

Post by iNCEPTIONAL »

Can you have objects on SNES where only certain parts/colours of the object would have the colour math applied for semi-transparency while other parts/colours can remain fully opaque?

And I don't mean by using say two overlaid objects to achieve the affect, which would use up precious objects (especially in terms of the limits per scanline), but just on a single object.

This is technically possible on Genesis using the shadow/highlight feature, so if it's not possible on SNES using normal colour math, is there maybe some shadow/highlight-style trick on SNES that works similarly to that feature on Genesis?
creaothceann
Posts: 611
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: Partial transparency on objects?

Post by creaothceann »

iNCEPTIONAL wrote: Sat Jul 02, 2022 6:50 am Can you have objects on SNES where only certain parts/colours of the object would have the colour math applied for semi-transparency while other parts/colours can remain fully opaque? And I don't mean by using say two overlaid objects to achieve the effect
  • Color math can be enabled/disabled for BG1/BG2/BG3/BG4/sprite/backdrop pixels on the mainscreen.
  • When you have color math enabled for sprites, you can disable it for a sprite by setting its palette to 0..3.
  • You can prevent color math with the Color Window, if you don't use windowing for something else in that part of the screen. Note that the Color Window area has the usual horizontal window shape limitations.
regs.txt wrote:

Code: Select all

2130  wb+++- CGWSEL - Color Addition Select
        ccmm--sd

        cc = Clip colors to black before math
            00 => Never
            01 => Outside Color Window only
            10 =>  Inside Color Window only
            11 => Always

        mm = Prevent color math
            00 => Never
            01 => Outside Color Window only
            10 =>  Inside Color Window only
            11 => Always

        s  = Add subscreen (instead of fixed color)

        d  = Direct color mode for 256-color BGs

        See the sections "BACKGROUNDS", "WINDOWS", and "RENDERING THE
        SCREEN" below for details.
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Partial transparency on objects?

Post by dougeff »

And I don't mean by using say two overlaid objects to achieve the affect
Why would you exclude that? That's how you would do it.
nesdoug.com -- blog/tutorial on programming for the NES
iNCEPTIONAL

Re: Partial transparency on objects?

Post by iNCEPTIONAL »

dougeff wrote: Sat Jul 02, 2022 10:35 am
And I don't mean by using say two overlaid objects to achieve the affect
Why would you exclude that? That's how you would do it.
Well, if that's the only way to do it and I really wanted such an effect, I obviously wouldn't exclude it. But it would use extra objects, so ideally I'd like to avoid that if possible, hence why I mentioned how the Genesis can use the shadow/highlight mode even on individual pixels on a sprite while also leaving others opaque. And I was just wondering if there was any way the SNES could do the same thing without having to use the extra object(s) to cover up some parts of the sprite while also leaving others semi-transparent.
iNCEPTIONAL

Re: Partial transparency on objects?

Post by iNCEPTIONAL »

creaothceann wrote: Sat Jul 02, 2022 9:04 am
iNCEPTIONAL wrote: Sat Jul 02, 2022 6:50 am Can you have objects on SNES where only certain parts/colours of the object would have the colour math applied for semi-transparency while other parts/colours can remain fully opaque? And I don't mean by using say two overlaid objects to achieve the effect
  • Color math can be enabled/disabled for BG1/BG2/BG3/BG4/sprite/backdrop pixels on the mainscreen.
  • When you have color math enabled for sprites, you can disable it for a sprite by setting its palette to 0..3.
  • You can prevent color math with the Color Window, if you don't use windowing for something else in that part of the screen. Note that the Color Window area has the usual horizontal window shape limitations.
regs.txt wrote:

Code: Select all

2130  wb+++- CGWSEL - Color Addition Select
        ccmm--sd

        cc = Clip colors to black before math
            00 => Never
            01 => Outside Color Window only
            10 =>  Inside Color Window only
            11 => Always

        mm = Prevent color math
            00 => Never
            01 => Outside Color Window only
            10 =>  Inside Color Window only
            11 => Always

        s  = Add subscreen (instead of fixed color)

        d  = Direct color mode for 256-color BGs

        See the sections "BACKGROUNDS", "WINDOWS", and "RENDERING THE
        SCREEN" below for details.
Ah, okay, so it seems I can do a bunch of things with colour math but not the specific thing I was curious about. Shame, because to get the effect I was mentioning, it looks like I would have to basically use double the amount of objects. I was sure there was some way to set the values of the colours in a sprite using colour math so that some parts would basically be more transparent than others or something, maybe even so some parts would effectively be opaque and other semi-transparent.
Last edited by iNCEPTIONAL on Sat Jul 02, 2022 2:51 pm, edited 2 times in total.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Partial transparency on objects?

Post by Dwedit »

Using twice the physical sprites on the screen is fine, it only has a cost in total sprite pixels drawn per scanline. It doesn't cost significantly more CPU usage to use twice as many physical sprites for a game object.

Meanwhile, variable transparency isn't a thing. But there is an effect that's something like variable transparency through either color addition or subtraction. You add or subtract RGB values from the other one. Either make something brighter or darker.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
iNCEPTIONAL

Re: Partial transparency on objects?

Post by iNCEPTIONAL »

Dwedit wrote: Sat Jul 02, 2022 2:15 pm Using twice the physical sprites on the screen is fine, it only has a cost in total sprite pixels drawn per scanline. It doesn't cost significantly more CPU usage to use twice as many physical sprites for a game object.

Meanwhile, variable transparency isn't a thing. But there is an effect that's something like variable transparency through either color addition or subtraction. You add or subtract RGB values from the other one. Either make something brighter or darker.
The sprite pixels drawn per scanline is the cost I worry about. In my shmup I'm gonna have a lot of bullets and enemies in a row, so using two sprites to create one sprite with the effect would be a bit risky. In some situations it would be totally cool though. I guess I just need to think of the right time to use it.

On a side note, I was looking at the following level in Pugsley's Scavenger Hunt and couldn't figure out how they were showing the background glass objects that were part opaque and part semi-transparent (the beakers and stuff): https://youtu.be/tVg8m_BYqcw?t=1248 (when running the game yourself it will play a demo of the level after a few seconds and eventually show the level I'm talking about, and you can run Mesen-S in fast speed to get to it a bit quicker too)

I figured they were using two background layers, one with colour math for semi-transparency across the whole layer and the other for the details they wanted to remain opaque like the white highlights on the beakers and stuff (and they just overlaid the two background perfectly and scrolled them around together), but in Mesen-S it seems to suggest they are just using a single layer for all parts of the glass objects, both opaque and semi-transparent. Can someone explain to me if I am mistaken, and if not then how are they doing this with a single background layer? Is it using the method you suggested that's something like variable transparency via either colour addition or subtraction and changing the RGB values?

And, if it's done via the method you mentioned, does that mean I could technically use the same method to have a sprite that's similarly mostly semi-transparent but opaque on say white highlight areas (similar to the beakers)?

PS. Pugsley's Scavenger Hunt have some cool visual effects by the way. :)
Last edited by iNCEPTIONAL on Sat Jul 02, 2022 2:52 pm, edited 1 time in total.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Partial transparency on objects?

Post by rainwarrior »

iNCEPTIONAL wrote: Sat Jul 02, 2022 2:41 pmOn a side note, I was looking at the following level in Pugsley's Scavenger Hunt and couldn't figure out how they were showing the background glass objects that were part opaque and part semi-transparent
It's just two separate layers that are scrolled together.

It's mode 1. BG2 is the transparent one.

In this level, BG2 scrolling is locked to BG1, so they move together.

In the "bubbles" level BG2 is used similarly for transparency, but has its own free scrolling. In the castle level, BG2 is free scrolling for parallax but no transparency.


If you wanted to reserve half your sprite palettes, you could probably accomplish the same idea with sprites instead of a background layer.
iNCEPTIONAL

Re: Partial transparency on objects?

Post by iNCEPTIONAL »

rainwarrior wrote: Sat Jul 02, 2022 2:51 pm
iNCEPTIONAL wrote: Sat Jul 02, 2022 2:41 pmOn a side note, I was looking at the following level in Pugsley's Scavenger Hunt and couldn't figure out how they were showing the background glass objects that were part opaque and part semi-transparent
It's just two separate layers that are scrolled together.

It's mode 1. BG2 is the transparent one.

In this level, BG2 scrolling is locked to BG1, so they move together.

In the "bubbles" level BG2 is used similarly for transparency, but has its own free scrolling.
But I just checked again in Mesen-S and there aren't any parts of the beakers or glass pipes on BG1, just on BG2. BG1 is used for the wooden tables and solid metal pipes, BG2 is used for the semi-transparent beakers and semi-transparent pipes (which both have the white opaque highlights drawn directly into them), and BG3 is used for the low-colour far background layer. So BG2 still surely must be doing both opaque and semi-transparency at the same time, at least as it appears just to look at it, even if that's not technically what it's truly doing.
Last edited by iNCEPTIONAL on Sat Jul 02, 2022 3:01 pm, edited 1 time in total.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Partial transparency on objects?

Post by rainwarrior »

iNCEPTIONAL wrote: Sat Jul 02, 2022 2:56 pmBut I just checked again in Mesen-S and there aren't any parts of the beakers or glass pipes on BG1, just on BG2. BG1 is used for the wooden tables and solid metal pipes, BG2 is used for the semi-transparent beakers and semi-transparent pipes (which both have the white opaque highlights drawn directly into them), and BG3 is used for the low-colour far background layer.
Every part of the beaker is blending.

There are no partially-transparent beakers, but it's an additive blend against a dark background, so bright colours don't "look" very transparent. The transparency is more apparent on dim or strongly-coloured BG2 pixels.
iNCEPTIONAL

Re: Partial transparency on objects?

Post by iNCEPTIONAL »

rainwarrior wrote: Sat Jul 02, 2022 3:00 pm
iNCEPTIONAL wrote: Sat Jul 02, 2022 2:56 pmBut I just checked again in Mesen-S and there aren't any parts of the beakers or glass pipes on BG1, just on BG2. BG1 is used for the wooden tables and solid metal pipes, BG2 is used for the semi-transparent beakers and semi-transparent pipes (which both have the white opaque highlights drawn directly into them), and BG3 is used for the low-colour far background layer.
Every part of the beaker is blending.

There are no partially-transparent beakers, but it's an additive blend against a dark background, so bright colours don't "look" very transparent. The transparency is more apparent on dim or strongly-coloured BG2 pixels.
OK, but looking at it from the perspective of an artist, it's literally showing parts of objects that are on the one background layer that are both opaque and semi-transparent, correct? I mean, there is literally nothing showing through those fully white highlights that I can see (even if on some technically level it's actually showing both layers equally white in those exact spots or whatever). It's not using anything other than that single background layer and colour math to achieve the effect, as in, I do in fact not have to use two layers stuck together over each other to achieve it (one opaque and one semi-transparent), as in as in, I could technically still scroll all three layers completely independently for fully triple overlapping parallax and the objects on layer 2 would indeed still look opaque in some parts and semi-transparent in others as they move over the other layers, right?

And I can figure out with the programmer what I need to draw and what he needs to code to get that.

And, to the sprites, can I do similarly using the same method (pure white highlights being opaque with other parts being semi-transparent)?
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Partial transparency on objects?

Post by rainwarrior »

iNCEPTIONAL wrote: Sat Jul 02, 2022 3:08 pm...it's literally showing parts of objects that are on the one background layer that are both opaque and semi-transparent, correct? There is literally nothing showing through those fully white highlights that I can see.
It's additive blending. White + anything = white.

So, yes, white is fully opaque in additive blending. It's not generically "parts of objects", it's just the colour white specifically.

Anywhere they needed something opaque that's not pure white (e.g. a brown cork, a label on the jar), it's on BG1.

Similarly, colours that are "mostly" white might look "mostly" opaque when blended against a dark background. Just try out additive blending in any art program and it will give you an idea of what's possible.


The opposite also works for subtractive blending. With a negative palette, you can subtract anything to full black, and it works best against a bright background rather than a dark one.
creaothceann
Posts: 611
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: Partial transparency on objects?

Post by creaothceann »

I just took a look at this intro screen in vSNES...

Mainscreen has BG1, BG3 and sprites enabled.
- (BG3 priority 1 tiles will not be on top, which doesn't matter since all BG3 tiles are priority 0)
- BG1 is the furniture that the player is walking on
- BG3 is the cabinets and the window in the background
- sprites priority 2 are the player character
- sprites priority 3 are the HUD

Subscreen has BG2 enabled.
- BG2 contains only the beaker and the bottle

The subscreen is added, without halving the result, to the BG3 pixels and the backdrop pixels on the mainscreen.
Attachments
01 screen.png
02 info.png
03 BG1.png
04 BG2.png
05 BG3.png
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Partial transparency on objects?

Post by rainwarrior »

If you start the game, you can just run up the stairs and go in the door next to the stairs on the second floor (just jump off the stairs). That'll get you to the level we're looking at faster, plus you can play around and investigate.
iNCEPTIONAL

Re: Partial transparency on objects?

Post by iNCEPTIONAL »

Here's something else I just noticed; I'm not sure how they are doing the nice gradient on the window in this level plus the black used for the rest of the background colour behind layer 3?

https://youtu.be/tVg8m_BYqcw?t=1274

I would think the window's pink to blue gradient is done with HDMA on the background colour, but the rest of that background colour is plain black that's used as a forth colour for the other objects like shelves and stuff on layer 3, so how are they managing to HDMA gradient only one part of the background? I thought this HDMA gradient effect normally goes across a full scanline and then just changes on the next scanline or so down the screen. Are they maybe also using a window/shape mask around the window in the background to draw the black colour behind the rest of layer 3 or something along those lines?
Last edited by iNCEPTIONAL on Sat Jul 02, 2022 6:06 pm, edited 1 time in total.
Post Reply