Need advice on masking objects
by Steve George · in Torque Game Builder · 06/05/2006 (11:06 pm) · 11 replies
Lets start with an image from my project

I need to learn how to use masking with T2D so I can get this curved meter to work. Has anyone implemented something like this. General information on how to do masking would be mighty nice.
Any ideas are welcome :)
~SG
just for fun....here's a recent shot of the game with new backdrop. We'll be posting an alpha pretty soon.


I need to learn how to use masking with T2D so I can get this curved meter to work. Has anyone implemented something like this. General information on how to do masking would be mighty nice.
Any ideas are welcome :)
~SG
just for fun....here's a recent shot of the game with new backdrop. We'll be posting an alpha pretty soon.

#2
With regards to masking; could you elaborate on exactly what it is you're trying to achieve so I can offer some advice?
- Melv.
06/06/2006 (12:29 am)
Looks superb! Gimme now!With regards to masking; could you elaborate on exactly what it is you're trying to achieve so I can offer some advice?
- Melv.
#3
My goal is to have the meter grow and shrink just like any other meter. I also want to maintain the transparancey so ingame objects can be seen behind it. Normally , i would just make a straight bar and resize it as needed. In this case, it seems like I need to mask the bar with an opaque bitmap that only reveals the visible portion of the meter. The problem with this is, the bitmap also obstructs game objects. Maybe I'm just approaching this from the wrong angle?
BTW..thx for the kudos :)
~SG
06/06/2006 (9:02 am)
Melv,My goal is to have the meter grow and shrink just like any other meter. I also want to maintain the transparancey so ingame objects can be seen behind it. Normally , i would just make a straight bar and resize it as needed. In this case, it seems like I need to mask the bar with an opaque bitmap that only reveals the visible portion of the meter. The problem with this is, the bitmap also obstructs game objects. Maybe I'm just approaching this from the wrong angle?
BTW..thx for the kudos :)
~SG
#4
06/06/2006 (9:42 am)
If I am understand you right, you want the the meter to be transparency. You can use what I call Transparency layers with png. First layer is the alpha channel and next layer is transparency for the meter. I just test this in RC1 and does work. I create a fake meter and place it where ship would bypass it and I can see the ships. I only know how to this in Paint Shop Pro 8.
#5
The transparency isn't the part im stuck on. It's trying to mask the meter as it fills up or drains. I appreciate the help though.
06/07/2006 (9:14 am)
Michael, The transparency isn't the part im stuck on. It's trying to mask the meter as it fills up or drains. I appreciate the help though.
#6
06/07/2006 (9:42 am)
You welcome, when you say mask the meter when it fill up or drains do you mean transparency effect (you want to beable to see throw the green and red). if so and using images for the meter fills and drains you can set the transparency to them with in png so you can see throw them.
#7
Because it's a curved meter, it's not so simple. What Steve needs to be able to do is have a mask that will hide part of the meter, but allow anything else to show through it. As the meter fills, the mask can move to reveal more of the underlying meter. As the meter empties, the mask needs to move down to cover the meter but continue to show the planet and anything else that might be underneath it.
It's just a pity I don't have any solutions for you - apart from changing the meter so that it's always full, and using a pointer to indicate where the level is (think the sickbay displays from the original Star Trek)
06/07/2006 (10:01 am)
The problem that is that it's a big old curved image, so you need a different set of techniques to deal with it. If (as mentioned) it as a straight meter, then some images could be swapped in/scaled to show the bar increasing and decreasing.Because it's a curved meter, it's not so simple. What Steve needs to be able to do is have a mask that will hide part of the meter, but allow anything else to show through it. As the meter fills, the mask can move to reveal more of the underlying meter. As the meter empties, the mask needs to move down to cover the meter but continue to show the planet and anything else that might be underneath it.
It's just a pity I don't have any solutions for you - apart from changing the meter so that it's always full, and using a pointer to indicate where the level is (think the sickbay displays from the original Star Trek)
#8
06/07/2006 (1:49 pm)
Not really a "good" solution, but you could have a subset of smaller sprites sitting behind the graph positioned on the curve with transparency in the meter , then as you increase decrease, you could provide different alpha blends on the sprites sets to provide the effect you want.
#9
1. Assuming the "full" power bar is its own sprite (i.e. the meter outline is another sprite on top of it), you could load the sprite as CELL instead of FULL, and set the cell height to something fairly small, like 5 (setting the width to be the full width of the image). Then 'build' the meter by creating a master sceneobject and mounting to it each frame from the sliced-up meter bar, one above the other, each frame offset by the height you just sliced the sprite into. Then write a routine to setVisible on the sprites as necessary to display the bar at a given height. You could even fade them in over time to show the bar growing/shrinking instead of just snapping to a value.
2. You could render the bar in a dedicated scenewindow where the extents of the window change to mask the right amount of the bar. This is kind of ugly and may take some fiddling to get working, but the scenewindow's extents is the only real clipping mechanism that is part of the stock engine. Would probably be difficult to animate effectively too.
Probably the right way to do it is to modify the sprite rendering function in the engine to allow one sprite to mask another exclusively. So you'd have one sprite with a solid white copy in the shape of the bar, and you'd slide it up and down over the real bar sprite as the height changes. The render code would blend those two sprites to show only where the two sprites overlapped. This shouldn't be terribly difficult, as opengl masking routines are pretty well documented around the net. The hardest part is how you'd specify one sprite as the mask of another and keeping track of all that.
06/07/2006 (4:40 pm)
Off the top of my head I can think of two 'creative' ways to do this in script-only, both are pretty ugly however.1. Assuming the "full" power bar is its own sprite (i.e. the meter outline is another sprite on top of it), you could load the sprite as CELL instead of FULL, and set the cell height to something fairly small, like 5 (setting the width to be the full width of the image). Then 'build' the meter by creating a master sceneobject and mounting to it each frame from the sliced-up meter bar, one above the other, each frame offset by the height you just sliced the sprite into. Then write a routine to setVisible on the sprites as necessary to display the bar at a given height. You could even fade them in over time to show the bar growing/shrinking instead of just snapping to a value.
2. You could render the bar in a dedicated scenewindow where the extents of the window change to mask the right amount of the bar. This is kind of ugly and may take some fiddling to get working, but the scenewindow's extents is the only real clipping mechanism that is part of the stock engine. Would probably be difficult to animate effectively too.
Probably the right way to do it is to modify the sprite rendering function in the engine to allow one sprite to mask another exclusively. So you'd have one sprite with a solid white copy in the shape of the bar, and you'd slide it up and down over the real bar sprite as the height changes. The render code would blend those two sprites to show only where the two sprites overlapped. This shouldn't be terribly difficult, as opengl masking routines are pretty well documented around the net. The hardest part is how you'd specify one sprite as the mask of another and keeping track of all that.
#10
Something like :
mask(sourceImageMap,maskImageMap)
would be very handy on multiple levels.
06/07/2006 (6:23 pm)
Yea, it looks like getting into the source is the only robust solution at the moment. I'm just surprised that the issue of MASKING hasn't been brought up as a feature. Something like :
mask(sourceImageMap,maskImageMap)
would be very handy on multiple levels.
#11
06/07/2006 (8:21 pm)
Definitely, both masking via custom blending, and arbitrary per-sprite clipping areas would be absolutely swell things to have as advanced functionality, can do a lot of neat things with both.
Torque 3D Owner Jesse Liles