pouët.net

Cutting holes in textures with ID3DXLine

category: general [glöplog]
 
Hey. I've been pondering this for a while:

Anyone know of a way to make ID3DXLine draw to a texture's alpha channel? I know it does antialiasing and all, but what I'm interested in is forcing the opacity on the texels covered by the line. So say I have a 100% opaque texture with an alpha channel, and I want to cut a 0% opaque line through it (preferably with correct antialiaing), is there a way to do that?

This is for sizecoding stuff, mind, so rendering to a separate alpha texture or some such is not brilliant. :(
added on the 2009-09-16 16:34:08 by doomdoom doomdoom
can you use the colormask renderstate to only render to alpha channel?
added on the 2009-09-16 16:38:23 by smash smash
I can't find any documentation for that? Hm.

But I don't think renderstates have any effect on ID3DXLine anyway, at least not by default. It seems to set up its own renderstates.
added on the 2009-09-16 17:52:34 by doomdoom doomdoom
How to make: subtract line alpha from rendertarget alpha using blending (mask off other channels writes). Alternatively you can multiply destination alpha by inverse source alpha (may save switching back and forth between add/sub blending op).

How to use it with ID3DXLine: set your renderstates after ID3DXLine::Begin and the line should draw happily without noticing whatever horrible things you may have done to renderstates.
added on the 2009-09-16 18:00:30 by KK KK
Oh! See I wasn't even using Begin/End (saving them bytes you see). But this sounds promising, I'll give it a go tonight. \o/
added on the 2009-09-16 18:05:33 by doomdoom doomdoom
If you weren't using Begin/End, then I doubt ID3DXLine should mess with your renderstates at all (but this may sadly include not setting antialiasing).
added on the 2009-09-16 18:07:44 by KK KK
I think it just calls Begin and End from the Draw method if it's not in a Begin/End frame already. And of course if all the states are set up in Begin then this should do what I want.
added on the 2009-09-16 18:16:35 by doomdoom doomdoom
Quote:
I can't find any documentation for that? Hm.


/* Flags to construct D3DRS_COLORWRITEENABLE
#define D3DCOLORWRITEENABLE_RED (1L<<0)
#define D3DCOLORWRITEENABLE_GREEN (1L<<1)
#define D3DCOLORWRITEENABLE_BLUE (1L<<2)
#define D3DCOLORWRITEENABLE_ALPHA (1L<<3)
*/ // taken from d3d9types.h
added on the 2009-09-16 18:20:44 by superplek superplek
doom: If it's so, then call ID3DXLine::Begin just before demo start and never call End. D3DX should be perfectly fooled.
added on the 2009-09-16 19:56:47 by KK KK
Hmm.. but even haxx0ring the renderstates doesn't seem to give me any way of rendering to the alpha channel at all. Can this be right? :?
added on the 2009-09-16 21:54:02 by doomdoom doomdoom
It can't be right (unless you've picked alphaless texture format or explicitly masked out alpha writes).
added on the 2009-09-16 22:34:49 by KK KK
Wee.

After some fiddling it seems to work. It's the antialiasing that fucks it up somehow, but without AA it does what it's supposed to. I guess with a little more fiddling I can get AA to work too. It just seems to behave very differently with AA enabled.

Anyway, thanks for teh help.
added on the 2009-09-17 00:39:39 by doomdoom doomdoom

login