Sign in to follow this  
jad_salloum

transparency for textures

Recommended Posts

You must load texture by D3DXCreateTextureFromFileEx and set ColorKey as your transparent color.

http://msdn.microsoft.com/archive/en-us/dx81_c/directx_cpp/Graphics/Reference/CPP/D3DX/Functions/Texture/D3DXCreateTextureFromFileEx.asp?frame=true

Share this post


Link to post
Share on other sites
thanks guys for ur reply , but what i need to do is give the whole texture transparency not a fixed color in it , and i don't care about the picture if it has originaly alpha in it or not but usualy it should not , like when i draw a mesh i give its material color Alpa to make it transparent so ow to do it for textures ??

Share this post


Link to post
Share on other sites
You create a texture with an alpha channel. This can be done several ways. Either you can create the texture and add an alpha channel directly using a program such as photoshop or you can use the DirectX Texture Tool to add two textures (one RGB and one grayscale) together to form a RGBA texture. When loading the texture you also need to specify a format that uses alpha channel, i.e. D3DFMT_A8R8G8B8 instead of D3DFMT_X8R8G8B8 for example...

Then for the rendering you need to enable alpha blending and set the blendstates. A common setting is:
AlphaEnable = true
SrcBlend = SrcAlpha
DestBlend = InvSrcAlpha

Maybe not exactly the correct C# names for it (Don't have the doc's on this computer) but you should get the point.

Also when rendering with transparency you should disable ZBuffer writing. You need to make sure to draw the opaque objects first and then sort the transparent ones by Z.

I'm using shaders in my app but I believe it would work fine with fixed function as well.

Hope this helps!

Share this post


Link to post
Share on other sites
Do you mean the last part about texture drawn on vertexbuffer or the part of using c#? Anyway... could you explain your problem a little more in detail?

EDIT: Sorry missed one there

[Edited by - fortia on September 11, 2006 3:36:09 PM]

Share this post


Link to post
Share on other sites
If the texture does not have alpha, then it has an implicit alpha of 1. So, in order to use any other alpha value you will need to modulate the texture color with a material color that is white, and has the alpha value you desire.

Share this post


Link to post
Share on other sites
(This is a generic reply, since I use C++, but it should apply to managed DX as well.)

If you're using the fixed function pixel pipeline (texture stages), you can use the texture factor to provide alpha for the stage (they just use a 'selectarg1 texturefactor' stage entry). The texture factor is easy to change and doesn't require any buffer changes.

If you're using pixel shaders, then just use a shader constant to provide the alpha.

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