Two alpha blending sources?

Started by
7 comments, last by MtSMox 21 years, 11 months ago
Hi, I was wondering if you can use two sources for alpha blending? What I want to do is, have the vertex color control the first and another the second. This way I don''t have to update the vertexbuffer to change the general alpha value, I just change the second, which could be a material or the texturefactor. But I haven''t got this to work correctly. The material doesn''t change the alpha value and if I want to use the texturefactor I have to set it up whith setrenderstate which overrides the vertex (diffuse)color setting. Is there a way to do this? Or should I just change the vertexbuffer to change the alpha values? Thanks, Mox
Advertisement
I think you can use alpha from texturefactor without overriding diffuse color.

SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_BLENDFACTORALPHA );
SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

SetRenderState( D3DRS_TEXTUREFACTOR, RGBA_MAKE( 0, 0, 0, 128 ) );

<-- Those states mean that texturefactor will NOT be used for RGB but only for Alpha.

Alternative to try:
SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR );


Cheers!
Meduzza
Thanks for the reply, but it doesn''t give the desired effect. What I want is to have a basic setup for the alpha values in the vertex diffuse color. Then I want to be able to draw a polygon whith a general alpha value, which changes all the alpha values in the vertex data.

So an example:
Vertex1: alpha 1.0
Vertex2: alpha 0.5
Vertex3: alpha 0.0

draw it with alpha 0.5 gives:
Vertex1: alpha 0.5
Vertex2: alpha 0.25
Vertex3: alpha 0.0

If I use the D3DTOP_BLENDFACTORALPHA, it goes from
TFACTOR = 1.0 -> alpha is arg1
to
TFACTOR = 0.0 -> alpha is arg2

And if I try D3DTOP_MODULATE with D3DTA_TFACTOR the Diffuse color of the vertex isn''t used...

Does anybody has an idea how to do this?
Mox

SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
SetTextureStageState( 0, D3DTSS_ALPHAARG1,D3DTA_DIFFUSE );
SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR );

This will make the colour come from the texture entirely, and the alpha from the vertex modulated by the texture factor.

Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
Then I should probably have called this thread "Three alpha blending sources". Because I also want the texture alpha to be in the calculations, otherwise I can''t make transparent textures.
So I guess this isn''t possible, and I should make a saperate vertexbuffer (dynamic) or use DrawPrimitiveUP to draw the vertices to change the alpha values of the diffuse color?

Mox

I haven''t tested this, but at 4am it looks good.

Add:
SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_CURRENT );
SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
SetTextureStageState( 1, D3DTSS_ALPHAARG1,D3DTA_CURRENT );
SetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_TEXTURE );

This assumes your card can do multi-texturing. Otherwise you''ll have to pre-combine your TFACTOR with your vertex alpha by doing a Lock/modify/Unlock combo.

Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
THANKS!!!

I had to try some things, because this was my first try at multi-texturing, but it finally worked.
Can I assume a lot of cards have multi-texturing abilities? Cause it would make things much easier...
(I remember there was some page about D3D8 caps for a lot of cards, I''ll try to find that again...)

Mox

Most cards will support 2 stages. The best thing to do is check the CAPS at startup and if it doesn''t support 2 stages, you can either use another code path (pre-combining the TFACTOR into the diffuse alpha, which will be a lot slower) or you can gracefully exit and tell the user their card isn''t supported.

Obviously the seperate code path is the most friendly approach, but it will take more work from you. If this is something you want to release (especially for sale) then it''s prolly best to cover as many bases as you (reasonably) can since pro developers typically ignore this part of the market which makes it a good target for indie developers.

Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
To add to what DrunkenHyena said - checking the caps should always be the first line of tests in your program to determine the *rough* feature set of the chip.

With multitexturing setup, after you''ve determined *rough* support you should set up all the states and textures you intend using and call ValidateDevice() to check that the *combination* of states, textures etc will work together.

For (hypothetical) example a chip might expose D3DFMT_A8L8, but may have a restriction that you can''t have D3DTSS_COLOROP set to say D3DTOP_ADD while D3DRS_FOGTABLEMODE is set to D3DFOG_LINEAR.

The same chip may expose caps to say it can do all of the above - but due to it''s hardware design might not be able to do them together!.


What our engine does at startup time (after caps checking) is to set up the renderstates and texture stage states for each of the "shaders" (programmable and fixed function) the game uses and set dummy textures of each format we intend on using before calling ValidateDevice() - the return code from ValidateDevice determines how the engine decides to scale the effect down.


quote:If this is something you want to release (especially for sale) then it''s prolly best to cover as many bases as you (reasonably) can since pro developers typically ignore this part of the market which makes it a good target for indie developers.


Pac-Man:Adventures In Time (Creative Asylum/Hasbro/Infogrames) supports everything down to 2Mb graphics cards without hardware acceleration. I learnt a lot about writing scalable 3D engines doing that (some of it painfully ).
[It''s a shame Infogrames haven''t done anything with it since it''s release - I''d love to be able to release the ''enhanced'' version we were doing for nVidia - from 2mb in software up to bump mapping and envmapping]




--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

This topic is closed to new replies.

Advertisement