Omnimaga

Calculator Community => TI Calculators => General Calculator Help => Topic started by: cooliojazz on June 01, 2010, 10:38:02 pm

Title: Masking
Post by: cooliojazz on June 01, 2010, 10:38:02 pm
I have a quick question; how can I do sprite masking without AND logic?
Title: Re: Masking
Post by: Builderboy 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.
Title: Re: Masking
Post by: DJ Omnimaga 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.
Title: Re: Masking
Post by: cooliojazz 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...
Title: Re: Masking
Post by: DJ Omnimaga 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
Title: Re: Masking
Post by: Builderboy 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
Title: Re: Masking
Post by: calcdude84se 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.
Title: Re: Masking
Post by: DJ Omnimaga 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.
Title: Re: Masking
Post by: Galandros 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. :(
Title: Re: Masking
Post by: calcdude84se 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.
Title: Re: Masking
Post by: Galandros on June 05, 2010, 03:42:43 am
Thanks, I got it. :)