Punching holes!

Punching holes!

Post by Julian Onion » Tue, 01 Jul 2003 23:39:09



I have as part of an application a circular dial, behind which is visible
part of a bitmap. At least thats the impression intended to be presented to
the user. In actual fact there is a dashboard background over which I want
to overlay this circular portion of the bitmap.

My first idea is to have a texture with a circular part which has Alpha full
outside the circle, alpha 0 inside, and to multi-texture this with the
bitmap. Is there any other way to do this without multi texturing? (I guess
PS is another way).

I tried to experiment with this for a hour or two with the mfctex tool,
before it dawned on me this tool doesn't actually support alpha channels
(despite seeming from the UI that it does) - doh!

--
Julian.

 
 
 

Punching holes!

Post by Julian Onion » Wed, 02 Jul 2003 22:35:05


Quote:> I tried to experiment with this for a hour or two with the mfctex tool,
> before it dawned on me this tool doesn't actually support alpha channels
> (despite seeming from the UI that it does) - doh!

BTW - if anyone wants the simple fixes to mfctex so you can properly
experiment with alpha blending and to allow loading .dds surfaces (which you
can do currently if you force the issue!) I have updated the sample code.
However its only a 5 minute job to fix it yourself.

--
Julian.

 
 
 

Punching holes!

Post by Phil Taylo » Fri, 04 Jul 2003 01:27:38



sample.

thanks!

--


Quote:> > I tried to experiment with this for a hour or two with the mfctex tool,
> > before it dawned on me this tool doesn't actually support alpha channels
> > (despite seeming from the UI that it does) - doh!

> BTW - if anyone wants the simple fixes to mfctex so you can properly
> experiment with alpha blending and to allow loading .dds surfaces (which
you
> can do currently if you force the issue!) I have updated the sample code.
> However its only a 5 minute job to fix it yourself.

> --
> Julian.

 
 
 

Punching holes!

Post by Robert Dunlop [MS MVP » Fri, 04 Jul 2003 16:23:40



Quote:> I have as part of an application a circular dial, behind which is
visible
> part of a bitmap. At least thats the impression intended to be
presented to
> the user. In actual fact there is a dashboard background over which I
want
> to overlay this circular portion of the bitmap.

> My first idea is to have a texture with a circular part which has
Alpha full
> outside the circle, alpha 0 inside, and to multi-texture this with the
> bitmap. Is there any other way to do this without multi texturing? (I
guess
> PS is another way).

Well, my first inclination would be to render the dial to a quad first,
with z-write enable off, then draw the dashboard overtop of it with a
cutout in the alpha channel.  Of course, this would mean alpha blending
the entire dashboard (or at least the area of the dial if you broke that
into a separate render), though if you just wanted a hard cutout (pixels
either fully opaque or transparent, no in between) you could use alpha
testing without blending.  The other shortcoming here would be that if
you had multiple dials you could not place them any closer than their
diagonal dimensions would allow, or their quads would overlap while they
rotate (I'm assuming you are rotating the dial behind that cutout?)

Drawing the dials after the dash could be done with a single texture,
containing an alpha channel mask, but with two texture stages.  Actually
it could be done with one texture stage, however as the mask rotates you
would likely see differences in the filtering of the mask, not to
mention if it was at all off center or asymmetrical the mask would
rotate eccentrically.  Also using two stages would allow for an
arbitrary mask to be applied rather than requiring a centered circular
mask.  Here's how you could set it up with two stages:

* Put the mask in the alpha channel of the texture (full alpha inside
the dial, transparent outside, opposite of what you described), and set
this texture for both stages.

* Set the quad up with one set of texture coordinates, fixed at
(0.0,0.0) -> (1.0,1.0) to map the entire texture to the quad, and set
the texture coordinate index of both stages to point to these
coordinates.

* Apply a texture coordinate transformation to the first stage to rotate
the bitmap.  Leave the second stage set to pass through the vertex
texture coordinates.

*  Set the first stage as:
    D3DTSS_COLOROP        D3DTOP_SELECTARG1
    D3DTSS_COLORARG1    D3DTA_TEXTURE

* and the second stage:
    D3DTSS_COLOROP        D3DTOP_SELECTARG1
    D3DTSS_COLORARG1    D3DTA_CURRENT
    D3DTSS_ALPHAOP        D3TOP_SELECTARG1
    D3DTSS_ALPHAARG1    D3DTA_TEXTURE

* After rendering the two stages, you'll have an output from the pixel
pipeline that has a color from the rotated texture and an alpha value
from the stationary mask.  Apply alpha blending with D3DRS_SRCBLEND set
to D3DBLEND_SRCALPHA and D3DRS_DESTBLEND set to D3DBLEND_INVSRCALPHA.

I think that should do the trick!  Hope that helps.

--
Robert Dunlop
The X-Zone
http://www.directxzone.org/
Microsoft DirectX MVP
-------------
The opinions expressed in this message are my own personal views and do
not reflect the official views of the Microsoft Corporation.
The MVP program does not constitute employment or contractual obligation
with Microsoft.

 
 
 

Punching holes!

Post by Julian Onion » Fri, 04 Jul 2003 17:00:23




> sample.

Done!
--
Julian
 
 
 

Punching holes!

Post by Julian Onion » Fri, 04 Jul 2003 17:27:16


Many thanks for the detailed reply.

Quote:> Well, my first inclination would be to render the dial to a quad first,
> with z-write enable off, then draw the dashboard overtop of it with a
> cutout in the alpha channel.  Of course, this would mean alpha blending
> the entire dashboard (or at least the area of the dial if you broke that
> into a separate render), though if you just wanted a hard cutout (pixels
> either fully opaque or transparent, no in between) you could use alpha
> testing without blending.  The other shortcoming here would be that if
> you had multiple dials you could not place them any closer than their
> diagonal dimensions would allow, or their quads would overlap while they
> rotate (I'm assuming you are rotating the dial behind that cutout?)

Yes - it rotates. In fact its actually a large rectangular texture of which
only part of which is ever visible at a time.

Quote:> Drawing the dials after the dash could be done with a single texture,
> containing an alpha channel mask, but with two texture stages.  Actually
> it could be done with one texture stage, however as the mask rotates you
> would likely see differences in the filtering of the mask, not to
> mention if it was at all off center or asymmetrical the mask would
> rotate eccentrically.  Also using two stages would allow for an
> arbitrary mask to be applied rather than requiring a centered circular
> mask.  Here's how you could set it up with two stages:

Could you outline the one texture stage method? I've tried to work out
something myself
but can't see how it can be done, except by rendering to an offscreen
surface (even then I'm not sure I can work out the details). I was wondering
how I might do this if 2 texture stages were not available - I presume there
are such older cards that don't support multi-texturing?

Quote:> * Put the mask in the alpha channel of the texture (full alpha inside
> the dial, transparent outside, opposite of what you described), and set
> this texture for both stages.

> * Set the quad up with one set of texture coordinates, fixed at
> (0.0,0.0) -> (1.0,1.0) to map the entire texture to the quad, and set
> the texture coordinate index of both stages to point to these
> coordinates.

OK - but actually its only part of the texture but I can handle that (I
think!).

Quote:> * Apply a texture coordinate transformation to the first stage to rotate
> the bitmap.  Leave the second stage set to pass through the vertex
> texture coordinates.

Texture coordinate transformations... they sound a bit scary!
I think i need to do some more reading.

Quote:> *  Set the first stage as:
>     D3DTSS_COLOROP        D3DTOP_SELECTARG1
>     D3DTSS_COLORARG1    D3DTA_TEXTURE

> * and the second stage:
>     D3DTSS_COLOROP        D3DTOP_SELECTARG1
>     D3DTSS_COLORARG1    D3DTA_CURRENT
>     D3DTSS_ALPHAOP        D3TOP_SELECTARG1
>     D3DTSS_ALPHAARG1    D3DTA_TEXTURE

> * After rendering the two stages, you'll have an output from the pixel
> pipeline that has a color from the rotated texture and an alpha value
> from the stationary mask.  Apply alpha blending with D3DRS_SRCBLEND set
> to D3DBLEND_SRCALPHA and D3DRS_DESTBLEND set to D3DBLEND_INVSRCALPHA.

> I think that should do the trick!  Hope that helps.

Very much, thanks
Julian.
 
 
 

Punching holes!

Post by Julian Onion » Fri, 04 Jul 2003 22:52:44


Quote:> > * Put the mask in the alpha channel of the texture (full alpha inside
> > the dial, transparent outside, opposite of what you described), and set
> > this texture for both stages....

Yeah - works a treat. Wrapped it up in a class with some StateBlocks like
CD3DFont does and it solves the issue.

Quote:> > * Apply a texture coordinate transformation to the first stage to rotate
> > the bitmap.  Leave the second stage set to pass through the vertex
> > texture coordinates.

> Texture coordinate transformations... they sound a bit scary!
> I think i need to do some more reading.

Read up on them, they would have been ideal, except they only work for
non-T&L coordinates which is a shame.
Naturally it took a few iterations before I came across this caveat!
But a little matrix maths on the screen coords seems to work, and luckily
circular textures are unaffected by rotation!

Thanks again.
Julian.

 
 
 

1. Fill punch holes from scan with CS?

Hello, I could use some advice please. I scanned a brochure which has punch
holes for a three-ring binger and I'd like to fill them in. At the least I'd
like to just put a white circle over the holes, and maybe black circle on
the dark pages.  What tool do I use in CS?  In the old MS-Paint program I'd
draw a circle and fill it in using the paint-can tool!

Thanks!

2. ANNOUNCE: Leveller 1.1 demo available

3. Punching Holes in NURB Objects?

4. Help! I've got holes in my rendered object?!?!?!

5. punching holes in a polygon

6. Question...

7. punching multiple holes into an object

8. WANTED 3D animators JOBS available

9. finding a used registration hole punch

10. "punching a hole" in an image

11. "punching a hole" in an image...

12. OBJ file format: howto specify holes within holes within holes ...

13. what's "punch"?