Jump to content
  • Advertisement
Sign in to follow this  
brekehan

Check texture for alpha

This topic is 3580 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

Can anyone suggest a simple way to check if a texture contains any alpha data in DirectX10? I see that the texture description could tell me if I wanted to handle every format constant, but am wondering if there is something cleaner than : if( texDesc.Format == DXGI_FORMAT_R32G32B32A32_TYPELESS || texDesc.Format == DXGI_FORMAT_R32G32B32A32_FLOAT || texDesc.Format == DXGI_FORMAT_R32G32B32A32_UINT || texDesc.Format == DXGI_FORMAT_R32G32B32A32_SINT || texDesc.Format == DXGI_FORMAT_R16G16B16A16_TYPELESS || texDesc.Format == DXGI_FORMAT_R16G16B16A16_FLOAT || texDesc.Format == DXGI_FORMAT_R16G16B16A16_UNORM || texDesc.Format == DXGI_FORMAT_R16G16B16A16_UINT || texDesc.Format == DXGI_FORMAT_R16G16B16A16_SNORM || texDesc.Format == DXGI_FORMAT_R16G16B16A16_SINT || // etc. a bunch of other constants with alpha... ) { // Has alpha } [Edited by - brekehan on December 29, 2008 2:31:06 PM]

Share this post


Link to post
Share on other sites
Advertisement
Another way I thought of was to

request it be loaded in R32G32B32A32 format,
check that it got loaded in R32G32B32A32,
iterate through the data,
check each pixel for alpha != 1

That is also pretty computationally expensive, even if it is at init time.

Anyone have better ideas?

Share this post


Link to post
Share on other sites
I understand from your second post that you want to know that there's an actual non-opaque pixel, regardless of whether the texture has alpha in its format.

In that case, you have no choice but to check the pixels. There are several ways to save from having to check every pixel with the CPU on loading.

- Check offline. Either run a program over your textures, if there's a fixed set of textures, or check them first time they're loaded, then store the information somewhere.

- Check with the GPU. There are several ways to check:

- Scale the texture by half repeatedly, with a shader that keeps a non-opaque alpha if any of the 4 pixels has it. After several passes check the remaining pixel on the CPU.

- Run a shader that changes the Z value depending on alpha, making the pixel fail Z if it doesn't have alpha. Use an occlusion query to count the number of pixels which pass Z testing (and therefore have alpha, in this case).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!