Jump to content
  • Advertisement

Archived

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

Christoph

Combine two sorts of Alpha Blending

This topic is 5279 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I have a texture showing a white circle with soft edges. The background is black. Now I want to blend this texture with my 3D-scene, so that white means to show everything and black to be transparent. The settings are d3dDev.RenderState.DestinationBlend = Blend.InvSourceColor d3dDev.RenderState.SourceBlend = Blend.SourceColor My problem is that I additionally want to blend the whole texture with let''s say a transparency of 50 % (The result should be a round lens flare). I can''t use the Blend Factor, because Alpha Blending is already busy... Should I use Texture State settings? Or Materials? How would you solve this problem? Thanks

Share this post


Link to post
Share on other sites
Advertisement
the easiest solution to this problem is to create your texture again in Adobe photoshop and save it as a PNG. A png will save the alpha component as well as the color componenet. D3DXCreateTextureFromFile will load the png.

Then just slap the texture on a quad and set your texturestage states as follows:


dev->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

dev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
dev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
dev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);

dev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
dev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
dev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);

this will mix the alpha from the texture with whatever alpha you send in. It will also take into account the color value you send in so you can change the color of the flare.

Good Luck

Share this post


Link to post
Share on other sites
Thanks.
But the alpha value changes steadily, the transparency has to change dynamically. Is this possible with your solution?

Share this post


Link to post
Share on other sites
You could use the .DDS format, I don''t know how to use it (check the DX SDK), but it stores two images, the original and a greyscale alpha. That should do what you want...

Share this post


Link to post
Share on other sites
yes, it is possible b/c my solution sets the alpha value from the vertex alpha value ( what you put in each vertex ) and the texture alpha value.

so you can change your opacity of the quad dynamically by changing the alpha component of the diffuse color sent in through your verticies.

It basically mixes the alpha from your texture with the alpha from the diffuse color of the quad.

Remember, the .png file will have an alpha component already loaded in it.



[edited by - joeman on June 7, 2004 11:47:06 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This setup uses alpha values in texture and takes an "global" alpha value in TEXTUREFACTOR to blend the whole thing.

SetTextureStageState(i,D3DTSS_ALPHAARG1, D3DTA_TEXTURE)
SetTextureStageState(i,D3DTSS_ALPHAARG2, D3DTA_TFACTOR)
SetTextureStageState(i,D3DTSS_ALPHAOP, D3DTOP_MODULATE)
SetRenderState(D3DRS_TEXTUREFACTOR, 0xAAFFFFFF) AA = alpha

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!