Game Development Community

Alpha masking of GUI Controls

by Konrad Kiss · in Torque Game Engine Advanced · 07/04/2008 (12:46 pm) · 11 replies

Hi all,

I would like to mask out certain parts of a scene rendered in a guiTSControl descendant control in PlayGui using an image file that is the same size as the control, and use either the alpha channel or any / all of the color layers to mark parts of the control visible and partially / totally transparent. I have looked all over the forums and I couldn't find what I was looking for.

Is there an easy way to do this? What direction should I take?
Any help is much appreciated.

#1
07/06/2008 (2:10 pm)
Anyone, please? This is all I need to publish my TGEA 1.7.1 MiniMap resource. :)
#2
07/08/2008 (12:30 pm)
Look up Gui Commander Hud
#3
07/08/2008 (1:18 pm)
That's exactly the resource I'm porting to TGEA 1.7.1 + spicing it up with stuff like map transformation and rotation based on the control object, circular edge compass overlay (N, W, S, E), rotated icons defined per shape type (ie. separate icons for every object type defined at the shape datablock) & colorblending added for having friend or foe (or neutral, corpse, etc..) variations. Plus it has tweaks to GuiCommanderHud: it handles volumetric fog, water clarity and visibility depth problems, cam height is offset from the z of the control object instead of having a static value, and has transformations that use the controlobject again instead of the playercam, which solves the dancing z issue. It also handles the mousewheel out of the box and plays nice with AFX.

The only thing I have no idea about is how to mask out certain parts of the GuiCommanderHud (guiTSCtrl descendant) control, because I really want it to be circular.

www.xenocell.com/dev/minimap.jpg
Edit: added screenshot, this probably says it better what I need to get done.
#4
07/10/2008 (1:52 am)
Bump. Last desperate call for help.
#5
07/10/2008 (2:43 am)
I guess you could go down multiple paths here. What you would want is to have the card discard certain pixels based on a pre-set criteria.

a) Render to a render target and render out a matching circle with a low constant z value before having Torque do the overhead render. Or use alphas and render with DESTALPHA (may clash with other Torque render code messing with the alpha, though). Or use a stencil.

b) Use a stencil buffer.

c) Do the alpha thing on the primary render buffer (again not sure whether rendering code will mess this up).

Of these, a) is probably the least resource-intensive and easiest-to-implement solution. Allocate the render target in the init code and then pre-fill the target's depth buffer and alphas (otherwise you'll see the same issue again) at render time before invoking the world render. Finally, just render out the control's rectangle using the render target texture.
#6
07/10/2008 (4:36 am)
Thank you Rene, I feel less lost.
The render target idea is a great one. I had to read up on that anyway, so it will be a nice excercise.
#7
07/22/2008 (12:17 am)
Have you managed to get masking done? I need masking with one of my GUI controls.
#8
07/22/2008 (2:44 am)
Not yet, I had to focus on something else to show progress, but the following 2-3 days I will be working on this.
#9
07/29/2009 (2:41 am)
I would also be interested in this. I would like to apply an alpha mask to make a segmented health bar.
#10
07/30/2009 (6:03 pm)
Yep, probably Alpha masking of GUI Controls would be a good resource in itself.
#11
09/06/2009 (12:47 pm)
Konrad did you ever complete this? This is something alot of us would kill to have!