Sign in to follow this  
LeChuckIsBack

Alpha Blending

Recommended Posts

Maybe I should ask this in the DirectX section, but anyway... Until now I've only used alpha blending by setting these flags: pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); and make a whole texture (stored in a simple .BMP file) be transparent or opaque switching the pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); on and off. The problem is that I would realy like to use textures with alpha channels to achieve more complex transparency ([EDIT]: like only making tranparent some areas of that texture), but I never used this and I'm not sure exactly how: 1. I heard about that .dds format, but how can I make them? I'm trying to open any bitmap in that DirectX Texture Tool utility, but the texture is always black (with or without the alpha channel visible). Why's that? 2. Let's say I've made some .DDS files. How can I load them? I usualy load my .bmp files with the LoadBitmap Win32 API function, but I'm not sure that will work on DDS files... 3. When I'm using alpha textures, do I still have to set the above flags as before? [Edited by - LeChuckIsBack on October 24, 2005 7:38:49 AM]

Share this post


Link to post
Share on other sites
I am not sure exactly what you are trying to use your textures for.

However I have used the directX alpha blending functionality for particle effects.


The render flags I use are for enabling alpha blending are

pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );

pd3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA); //source blend factor


Now I am not sure what you are using these textures for, however you mentioned you wanted to get the alpha value from the texture


//pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE); //alpha from texture
pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_DIFFUSE); //alpha from alpha value


The first line should give you alpha from texture (I think).
The second line is the one I am actually using. This takes the alpha transparency value from the diffuse color of the material you are applying. Which if you are using this for particle effects you may want to use.

You also mentioned you wanted to use the .dds format.

I cant offer much help on it, as it never worked for me.
I did get it to load up with some of the .dds files packaged with the SDK, however the plugin for photoshop to export them seemed to be borked.
However, Loading up .tga files with alpha transparency layer saved out from photoshop works nicely using

D3DXCreateTextureFromFile( pd3dDevice, fileName, pTexture );

(pTexture is a LPDIRECT3DTEXTURE9 * where you want the texture stored)

On a side note, if you are using them for particle effects, making a material that is all black (even if it is 1.0f alpha value) seems to make point sprites alpha transparent, as well as any pixels of pure black in the texture. I think it is the default diretX color key and I am not sure how to change it.


Hope this helps.

Share this post


Link to post
Share on other sites
I want to know how to use alpha textures so I can display, for example, a sprite on the whole screen. That sprite will allow transparency ONLY in some areas, defined through the alpha channel. So, let's say, you could see through the left side of the sprite, but not through the right side.

Sorry if I wasn't too clear about his...

If I could do that with simple .bmp files that would be great, but I don't think that's possible... I think I'll have to use .dds files, but, as I said, never used them before, so I would apreciate a bit of help there...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

DDS-files can be made with Adobe PhotoShop with DDS plugin from NVidia. Probably there is a way with DX SDK to convert bitmaps to DDS files.

DDS file is just a dump of "DirectDrawSurface" and it can contain mipmaps (the plugin is able to generate them). Also DDS file can contain several formats including packed dxt1-5 formats or just plain unpacked ARGB (1555, 565, 8888 etc.) where some of them may have alpha information.

I consider DDS-files most useful and they are the only format I use for my projects.

Best regards!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this