Archived

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

Chaucer

texture transparency

Recommended Posts

I''d like to set the alpha channels in my billboard bitmaps to transparent but so far, all I''ve been able to come up with is a way to set a color transparent using CreateTextureFromFileEx(). How do you go about setting the alpha channels to transparent in direct3D? Or maybe some blending is needed? Thanks.

Share this post


Link to post
Share on other sites
Hi - you can do this either way, but the easiest way is to use a file format that has an alpha channel (e.g, tga).

This image shows two sprites that get their alpha info from a .tga file''s alpha channel:



I know photoshop and edit the alpha channels of .tga files and I suspect the paintshop pro can as well. The texture utility that comes with DX also lets you combine multiple textures to include alpha info in the texture.

If you want to set a constant alpha value for a texture (say to make the entire texture partially transparent, you can do so by changing the color of your vertices and setting your texture state 0 as follows:

D3DTSS_ALPHAOP, D3DTOP_MODULATE

If you want, you can combine the above two methods.

For example:



Finally, you can use multi-texturing to do alpha-blending as well. I do this by setting texture state 1 as follows:

D3DTSS_COLOROP, D3DTOP_MODULATE
D3DTSS_ALPHAARG1, D3DTA_TEXTURE
D3DTSS_ALPHAOP, D3DTOP_SELECTARG1

You can then set texture 0 to the texture you want to display and texture 1 to your mask texture.

For exampe:



In the image above the dirt textures are applied over the grass texture using a mask file. This is somewhat inefficient, as it requires two passes - 1) render the grass texture, 2) render the ground texture with a mask...

There probably are more efficient methods to do the above. If anyone has a more efficient method or methods, I would interested in hearing about it/them.

-BM

Share this post


Link to post
Share on other sites
You can get alpha in at least 3 ways.

One is the way you described where you tell d3d that a specific color is to be treated as transparent.

Another way is to use a mask that will apply alpha to the surface using the grayscale or B+W mask.

A third way is to have the alpha be in the texture image. If you plan to use this method, you have to use image files that support an alpha channel. Common ones that do this include .tga and .png

Share this post


Link to post
Share on other sites
What about bmps?
Does directx support loading .tga files the same way .bmp files are loaded?

Also do you still have to set alpha blending for it to work or is it automatic?

[edited by - Chaucer on March 5, 2003 11:47:34 AM]

Share this post


Link to post
Share on other sites
Hi - standard bmps don''t have an alpha channel. Having said this, I know that Photoshop 7, though, will let you save to a bitmap that can support an alpha channel, so if you have photoshop 7 you can play around with making one of this bitmaps...

The directx texture and surface loading routines can handle .tga as well as .bmp.

Yes - you would have to enable alpha blending, etc... to make the alpha components of .tga based textures work.

-BM

Share this post


Link to post
Share on other sites