Author Topic: Masking  (Read 7366 times)

0 Members and 1 Guest are viewing this topic.

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Masking
« on: June 01, 2010, 10:38:02 pm »
I have a quick question; how can I do sprite masking without AND logic?
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Masking
« Reply #1 on: June 01, 2010, 10:50:06 pm »
You have two sprites to make the final image, the transparency mask and the sprite mask we'll say.  The transparency mask is black where the image is solid and white where it is transparent.  The sprite mask is Black where the sprite is white (counterintuitive i know, thats why i want ANDing) a,d white where it is anything else.  To display, you OR the transparency mask, then XOR the sprite mask.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Masking
« Reply #2 on: June 01, 2010, 10:51:51 pm »
you need two copies of your sprite: a black mask and the sprite itself.

The black mask represents all areas of your sprite that you want transparent and the ones that aren't. The black areas are the ones that aren't. First, you display your mask using the OR logic (all black pixels from your sprite turns the screen pixels black, white ones won't change anything.) Then you display your mask again but using the XOR logic, which inverts the area that got turned black to white. Once done, display your regular sprite using the OR logic.

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Re: Masking
« Reply #3 on: June 01, 2010, 10:54:20 pm »
Wow...  thats complicated, glad others know how to do it, I never would have figured that out.  Thanks!  I wonder if Quigibo is planning on adding AND to axe parser sometime in the future...
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Masking
« Reply #4 on: June 01, 2010, 10:55:47 pm »
I don't think he will since it can already be done like me and BBoy posted. However, if you use masking a lot in your games, you can simply put both sprites near each others in your tile sheets and use sub-routines to prevent repetitive code

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Masking
« Reply #5 on: June 01, 2010, 10:57:59 pm »
Mmm thats a more intuitive way DJ :) Yeah with mine, you dont actualy get to store the actual sprite anywhere :P its all just messed up masks ;D

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Masking
« Reply #6 on: June 02, 2010, 07:46:48 am »
Efficiency or readability... hm... You could always just make a special hex editor that supports masked sprites and gives the hex for both masks.
Also, something that wasn't mentioned: you can also use such masking to invert areas, in addition to white, black, or untouched (transparent). With what builderboy mentioned, in the second mask you put black where in the first mask you put white, and, while it cannot be done with DJ's method as-is, replacing that final OR with an XOR and using black where there was white the first mask does the trick.
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Masking
« Reply #7 on: June 02, 2010, 12:46:00 pm »
Mhmm Builderboy method sounds more efficient indeed... would save some speed for sure when many sprites at once are shown.

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Masking
« Reply #8 on: June 04, 2010, 04:05:27 pm »
Sorry, but could you provide example code of BuilderBoy and DJ Omnimaga description?
I am having difficulties understanding the steps and it looks interesting. :(
Hobbing in calculator projects.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Masking
« Reply #9 on: June 04, 2010, 07:17:14 pm »
For each piece of code, the first mentioned sprite is Pic1 and the second mentioned one Pic2. The sprite location is given by X and Y
Code: [Select]
.This is Builderboy's
Pt-On(X,Y,Pic1
Pt-Change(X,Y,Pic2
Code: [Select]
.This is DJ's
Pt-On(X,Y,Pic1
Pt-Change(X,Y,Pic1
Pt-Change(X,Y,Pic2
.The last line for DJ's as given would be a Pt-On rather than a Pt-Change, but my variation works about the same and is more flexible
Note that Pt-On performs an OR, and Pt-Change performs an XOR operation.
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Masking
« Reply #10 on: June 05, 2010, 03:42:43 am »
Thanks, I got it. :)
Hobbing in calculator projects.