Archived

This topic is now archived and is closed to further replies.

NotTaxes

Alpha channels on the fly

Recommended Posts

NotTaxes    122
Is there a way to create and assign an alpha-mask to a texture on the fly? If I load the texture using CreateTextureFromFileEx I can specify that I want to load Alpha, but is there a way I could do it just before I render? Ideally I would like to have, for example, two alpha patterns (one chequered and one just standard diagonal stripes). Then I want to render the polygon with the diagonal stripes transparent normally, but then with the chequered transparency when I move the mouse over it. Any ideas? ''Doing the impossible is kind of fun'' - Walt Disney

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
is this d3d or opengl?

i think the only(fast) way to do it would be to have two textures, and switch them, or two alpha textures and switch the one you are blending with it

Share this post


Link to post
Share on other sites
NotTaxes    122
Using D3D... but the problem with using multiple textures is the memory thingy. I want to use this technique to show high-lights when I move over the polygon. If I''ve got 50 textures, then with that method I''d need to actually have 100... bit of a memory concern.

''Doing the impossible is kind of fun'' - Walt Disney

Share this post


Link to post
Share on other sites
sflare    122
if each texture is going to have it''s own way of being highlighted,
then each texture will need it''s own highlighted texture as said before
but instead of using a texture to highlight why not just draw a wire frame thing(box) around the object to highlight
or
if you use the same texture to highlight everything just draw a primitive containing the highlight texture just in front of the polygon

Share this post


Link to post
Share on other sites
Moe    1256
Why not just use additive alpha blending on the selected object? It would set it apart nicely...

Share this post


Link to post
Share on other sites
PSioNiC    122
What Moe is talking about is drawing the triangle twice (overtop of itself), and adding the color values (set with certain render states), to produce a final triangle 2x as bright as the original

Share this post


Link to post
Share on other sites
NotTaxes    122
OIC. That''s interesting, but it doesn''t give the required effect. I''m really trying to apply an Alpha channel to a texture on demand. Thanks for the idea though.

''Doing the impossible is kind of fun'' - Walt Disney

Share this post


Link to post
Share on other sites
NotTaxes    122
Sorry, posted the last before finishing.

What I want to do is have, for example, two alpha-channeled bitmaps called AlphaA and AlphaB. Then if I have a normal texture (tex1) I would like to say

Draw Tex1 with AlphaA or
Draw Tex1 with no Alpha or
Draw Tex1 with AlphaB

I figure it must be possible using TextureStageState, but I just don''t know how... something like

SetTexture 0, AlphA
SetTexture 1,Tex1

DrawPrimitive xyz

and with the correct texturestagestates this should work. I have tried using this, but the Alpha thing gets messed up in the second texture stage and I end up with a texture that has big black blocks in it, instead of big transparent blocks.


''Doing the impossible is kind of fun'' - Walt Disney

Share this post


Link to post
Share on other sites
-X-Modena-X-    122
I am having a problem with alpha blending too. when I tried to change the alpha values using SetTextureStage, it was putting a blue effect over all the other objects, so what it was doing was placing my texture, partially transparent, over the other objects. This was fine, because the object was supposed to be glass and have much the same effect. My problem is I can''t get the actual sheet of glass to be semi-transparent. Can anyone point me in the right direction?

Share this post


Link to post
Share on other sites
WarAmp    750
Well, once you have blended the 2 textures, then just do an Alpha test to discard the pixels that have a 0 Alpha. I dont know how to do it in D3D, but in Opengl:

glAlphaFunc(GL_NOTEQUAL, 0);
glEnable(GL_ALPHA_TEST);


That should discard any pixel with an alpha value of 0.

Hope that helps.

Waramp.

Share this post


Link to post
Share on other sites
NotTaxes    122
hmmm.... the trouble is that the theory is sound, but the practice is not.

What about using ColorAdd, but having 0,0,0 as the color arguments on the first texture (i.e., only an alpha channel). Then, if you add

0,0,0,150 (from the first texture)

to

100,100,100,0 (from the actual texture)

you should get

100,100,100,150

or, in other words, a grey, half-transparent pixel

Any ideas?

''Doing the impossible is kind of fun'' - Walt Disney

Share this post


Link to post
Share on other sites