Skip to main content
GameDev.net gamedev.net
🔒 Locked

DX9 Transparency Test

Started by Tones2 Jan 12, 2003 at 5:39 PM 11 replies 750+ views
Original Post
Tones2
Tones2
I'm having a lot of trouble getting the black areas of textures to show up as transparent using an alpha test. I'm loading a texture like this: D3DXCreateTextureFromFileEx( m_pObjectDevice, strPath, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE, D3DX_FILTER_TRIANGLE, 0xFF000000, NULL, NULL, &m_pMeshTextures[j] ); And testing for black pixels like this: m_pObjectDevice->SetRenderState(D3DRS_ALPHAREF, (DWORD)0x00000001); m_pObjectDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); m_pObjectDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); However, the black background on the texture is still showing up and is NOT transparent. I'm using DX9, BTW. What am I doing wrong? Tony [edited by - Tones2 on January 13, 2003 7:28:26 AM]
Tones2
Tones2
ANYONE see what might be wrong? This is driving me BATTY!!

Tony
spock
spock
The alpha testing won''t be affected by the color of the pixels, only by their alpha. Make sure your texture have the proper alpha values for the black areas.
Tones2
Tones2
quote:
Original post by spock
The alpha testing won''t be affected by the color of the pixels, only by their alpha. Make sure your texture have the proper alpha values for the black areas.



I''m confused here.....I thought the colorkey parameter in the D3DXCreateTextureFromFileEx() function sets the alpha channel on the texture.

In any case, how do I set the alpha channel for the colorkey color on a 24 bit .BMP file?

Tony


Tones2
Tones2
quote:
Original post by Anonymous Poster
In DX8 you would do something like this
D3DDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
D3DDevice->SetTextureStageState(0,D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
Graphics.D3DDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
Graphics.D3DDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
Graphics.D3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);



Thanks, but I'm really trying to do straight transparancy TESTING, not alpha blending.

Any other ideas?

Tony


[edited by - Tones2 on January 13, 2003 11:22:28 PM]
Tones2
Tones2
quote:
Original post by Jim Adams
Try 0x08 for the ref instead of 0x01. Also, make sure the pixels are actually black opaque in an image-editing program.




Thanks Jim. I''ve tried using 0x08 but still no transparancy. I''m also sure that the black areas in the texture are RGB(0,0,0).

I think it may have something to do with the fast that I''m using a 24 bit .BMP file that doesn''t have alpha information. However, I''m not sure how to ADD alpha information to a 24 bit .BMP file. Any ideas? I''m using Paintshop Pro 7.

Thanks,

Tony
ZoomBoy
ZoomBoy
quote:
Original post by Tones2
I think it may have something to do with the fast that I''m using a 24 bit .BMP file that doesn''t have alpha information. However, I''m not sure how to ADD alpha information to a 24 bit .BMP file. Any ideas? I''m using Paintshop Pro 7.

Thanks,

Tony



Create a 32bit .bmp
Look at mask information

ZoomBoy
Tones2
Tones2


Paintshop Pro won't allow me to create a 32 bit format bitmap. I'm really trying to convert an EXISTING 24 bit bitmap to 32 bits anyway.

Tony


[edited by - Tones2 on January 14, 2003 7:43:58 AM]
Tones2
Tones2
I got the transparency test to work but only after converting all my 24 bit .BMP files to 32 bit .TGA files which included the alpha information, and then replacing all the references to this new file manually in the .X file definitions.

So the question becomes - Is there actually a 32 bit .BMP format that includes an alpha channel? I don''t see how to create this at least in Paintshop Pro 7.

Thanks,

Tony

spock
spock
quote:
Original post by Tones2
Is there actually a 32 bit .BMP format that includes an alpha channel?


Yeah, sort of. There''s a 32 bit DIB format defined, but what little documentation exist is a bit vague about the pixel data layout, and as you have noted the BMP support in image manipulation programs is spotty. Another example of this is compressed BMPs, which I have struggled with in the past (I''m not sure if the support for that is better now, it could be).

Photoshop is able to save 32 bit BMPs, but Photoshop is very strict about the difference between alpha and opacity so you''ll need an explicit alpha channel in order to save a 32 bit BMP with alpha.

As far as I''m concerned BMP is a messy format with virtually no advantages apart from the fact that Windows have built-in functions to load them. You''re much better off working with PNG or TGA files if you can.
Zarmax
Zarmax
Have you tried using DDS textures? I seem to be converting everything over to using DDS textures with one bit alpha. Saves space and load very quickly.

Not sure if the DDS save plugin works with PSP7, but does work with Photoshop and is available I think from the Nvidia developers site.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.