transparency for textures

Started by
7 comments, last by ET3D 17 years, 7 months ago
hi guys i need to give trancparency for a texture drawn on a VertexBuffer so how could i do this ??? am using C# thanks alot for any help. jad
Advertisement
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
What format are your images in? PNG and 32-bit TGAs already have alpha information so there's no need to colorkey them.

If you do want to colorkey a texture use this overload of TextureLoader.FromFile, the last argument is the colorkey. Also make sure you have alpha testing on so it actually works.
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 ??
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!
thanks Guys for ur help but plzzzzzzzzzzzz read my posts till the end to get what i mean, thanks
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]
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.
.
(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.

This topic is closed to new replies.

Advertisement