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. :(
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. :(
can you use the colormask renderstate to only render to alpha channel?
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.
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.
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.
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.
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/
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).
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.
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
doom: If it's so, then call ID3DXLine::Begin just before demo start and never call End. D3DX should be perfectly fooled.
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? :?
It can't be right (unless you've picked alphaless texture format or explicitly masked out alpha writes).
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.
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.