Keengraph and masking

Tools, assembly, and file formats.
Post Reply

What should I do?

Colors on by default
1
25%
Colors off by default
3
75%
Colors totally removed
0
No votes
 
Total votes: 4

levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Keengraph and masking

Post by levellass »

Righto, not sure if this should go in this forum, so feel free to move the topic.


I'm pretty advanced on my KeenGraph reboot, the first release will do Keen 1-3, then I'll work on 4-6. KeenGraph exports unmasked graphics as 16 color bitmaps, and sprites as 256 color bitmaps so the mask can be combined with the image.

Now of course some people will want to make 'ghost' sprites with color, but no mask, at least in places. which is a neat effect. Currently KeenGraph solves this by making bitmaps with 32 useable colors. (The half masked 16 being tinged versions of the normal 16.) This allows half-masking to be done, but can cause problems if someone doesn't notice they've accidentally used the wrong color. (You can of course change the tint if you wish.)

So I'm stuck with several options. What I've done is to make the half masked colors optional, if '-mask' is used KeenGraph can turn the extra colors on or off. The options are:

* The command turns the colors off, by default all sprites have the extra colors. This makes it easier to do half masking, but could trip up new users.

* The command turns the colors on, by default all sprites are 16 color. This makes half masking harder to do, but could save a lot of potential confusion for those unused to how I do things.

* I could eliminate the colors all together, making half masking impossible. This removes one problem, but also removes what can be a nifty and interesting feature of Keen (And other games.)

* Finally, i addition to this I could add a traditional image-mask-hitbox system, like Modkeen uses. I am loathe to do this as it is inefficient and requires more coding from me, but I'm interested in how many would like it. (Please note that due to the more logical way I make palettes, KeenGraph imports modkeen bitmaps with odd colors.)


So I ask you, the future users of KeenGraph v2 what I should do; what would people prefer, and also any features they'd like added. (Keep in mind I'm working with BASIC here, no no fancy interface. ;p)

On the up side, I improved my code so now import/export takes about a second each way. (And tiles are now tileinfo compatible!)
User avatar
CommanderSpleen
Posts: 1017
Joined: Sun Aug 31, 2003 12:11 pm
Location: The Land of Sparkly Things
Contact:

Post by CommanderSpleen »

IIRK, putting various colours in the mask affects things differently than just black or white, so I prefer Modkeen's approach than something that limits the options to opaque, translucent and transparent.
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

This is a strangely pervasive myth, especially that a mask color opposite of that of the transparency works best, even I believed it. However, if you look at it logically, where does the color information go? A mask is a simple yes/no, like the other EGA planes. Modkeen lets you use colored masks only because it has no choice, you cannot make half of a bitmap monochrome.

What modkeen sees is black or white, test it yourself. A colored mask is seen as no mask at all, what affects the color is what color is translucent, especially whether it is a light or a dark color.
User avatar
CommanderSpleen
Posts: 1017
Joined: Sun Aug 31, 2003 12:11 pm
Location: The Land of Sparkly Things
Contact:

Post by CommanderSpleen »

How does translucency work if there's nothing between black and white? Such as the pogoing sprite in OrbKeen.
User avatar
Tulip
Posts: 394
Joined: Mon Jun 16, 2008 2:40 pm
Location: Heidelberg, Germany
Contact:

Post by Tulip »

I noticed this. It doesn't matter if you make your mask blue or red, the sprite'll look the same. The translucency of your sprite will still work if you just remove the mask. They only thing you can't make is a black translucent monster. Because black pixels are displayed as 100% transparent.
Sadly I don't know enough to tell you how it works exactly with the proper terms.
User avatar
CommanderSpleen
Posts: 1017
Joined: Sun Aug 31, 2003 12:11 pm
Location: The Land of Sparkly Things
Contact:

Post by CommanderSpleen »

Ah, so it's black, white and other?
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

Righto!

Pixel color is determined by values in four planes, RGB and intensity (Brightness) If a sprite pixel has a mask value (5th plane) it will 'overwrite' the pixel it covers. If it has no mask, then its colors will 'add' to that behind it. So for example, a black unmasked pixels adds nothing to the pixel behind it an is invisible (Value 0000) Red will turn blue purple, black red and not affect yellow. Blue will turn red purple, blue black and yellow white.

It's not hard to write up a color conversion table for all this, and you can see that a dark color (Lacking intensity) will be less 'affecting' than a light one. Interestingly, there appear to be small variations on how this work in some games.
User avatar
CommanderSpleen
Posts: 1017
Joined: Sun Aug 31, 2003 12:11 pm
Location: The Land of Sparkly Things
Contact:

Post by CommanderSpleen »

Right, so it's basically a boolean XOR operation that's being performed.

Code: Select all

0x0000FF (blue) XOR 0xFF0000 (red) = 0xFF00FF (purple)
0x000000 (black) XOR 0xFF000000 (red) = 0xFF0000 (red)
0xFFFF00 (yellow) XOR 0xFF0000 (red) = 0xFFFF00 (yellow)
0x0000FF (blue) XOR 0x0000FF (blue) = 0x000000 (black)
0x0000FF (blue) XOR 0xFFFF00(yellow) = 0xFFFFFF
Things get more complicated when you combine colours that have differing values for a given colour.

Code: Select all

0x00FF00 (green) XOR 0x008000 (dark green) = 0x007F00 (dark green)
0xFF8000 (orange) XOR 0x808080 (grey) = 0x7F0080 (purple)
0x4080C0 (dark cyan?) XOR 0xC02080 (almost magenta) = 0x80A040 (some horrible olive colour) 
Factor into this the existence of the palette patch, and a straight colour conversion table isn't going to cut it any more.
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

Close Spleen, so very close! But you are treating these as standard 8-bit colors, when they are really four plane EGA. Thus:

Code: Select all

BGRI = XXXX:

1001 (Blue) + 0011 (Red) = 1011 (Pink)
0000 (Black) + 0011 (Red) = 0011 (Red)
0111 (Yellow) + 0010 (Red) = 0111 (Yellow)
1001 (Blue) + 1001 (Blue) = 1001 (Blue)
1001 (Blue) + 0111 (Yellow) = 1111 (White)
The main difference is that this is an addition, not an averaging, and that EGA graphics are by plane, not by hue value. (Thus, unpatched Keen doesn't have a default palette, one can be patched in, but it is an addition, a rearrangement of standard EGA code.)

Thus, palette patches do nothing. White, (1111), with the special position of turning all other colors white (Acting as if masked, even when not.) will always do this, even if you palette patch it to be black. My 16x16 color table still stands then. (I can even post it if you'd like.)
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

Hmmmn, only two votes. Maybe I should just release my second version and not wait?
User avatar
CommanderSpleen
Posts: 1017
Joined: Sun Aug 31, 2003 12:11 pm
Location: The Land of Sparkly Things
Contact:

Post by CommanderSpleen »

Probably best to try one and let people complain if it's problematic.
gerstrong
Posts: 63
Joined: Sun Jan 25, 2009 3:21 pm

Post by gerstrong »

Hey, that effect is very nice. Why don't Keen 1-3 programs use this? I have enhanced the support for Commander Genius.

Thanks for the info!
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

It is an interesting question; several Apogee games use variations of it. (Notably when you shoot some enemies they flash, their masking plane sets all values behind it to white, and in Cosmo the invisible enemy's masking plane adds intensity to all values behind it.)

I think this may possibly be because of a mixture of ignorance (If I recall deluxe paint did the masks automatically.) and viewing it as a bug. (I've oft been annoyed by forgetting to mask something.) Either way it's a pity, and I'm using it a lot in my mod.
User avatar
adurdin
Site Founder
Posts: 549
Joined: Fri Aug 29, 2003 11:27 pm
Location: Edinburgh, Scotland
Contact:

Post by adurdin »

Combining a masked sprite with the background is actually two operations. The mask is first ANDed with the background; so where the mask is white (1) the resulting pixels will remain unchanged; and where the mask is black (0), the resulting pixels will be set to black.

Then the sprite image is ORed; where either the sprite or background pixels are black (0000), the other will be preserved unchanged; where one is white (1111), the result will be white; and where neither are black or white, then the result will be as per levellass's table.

So, yeah, levellass is correct, the bit values are what matters, not the colours in the palette.
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

Thankyou Andy, you are correct (And yet no comment on my limitations topic?) Should I now mention the process by which masked tiles in Keen 1-3 work? It's slightly different than that used for either masked tiles 4-6 and sprites 1-6.
Post Reply