Transparency without color keying

Started by
6 comments, last by CGameProgrammer 20 years, 11 months ago
I''m doing alpha-testing:

m_Device->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
m_Device->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATER );
m_Device->SetRenderState( D3DRS_ALPHAREF, 0 );
m_Device->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
m_Device->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
...and as you can see I''m trying to get it to work based on the alpha values of the individual texels. They are 255 by default but 0 where they''re supposed to be transparent. I create a 32-bit bitmap in memory whose alpha values are set as such, and load it like:

Result = D3DXCreateTextureFromFileInMemoryEx( m_Device,
                                              FileStream,
                                              BMFile.bfSize,
                                              0,
                                              0,
                                              0,
                                              0,
                                              D3DFMT_A8R8G8B8,
                                              D3DPOOL_MANAGED,
                                              D3DX_FILTER_NONE,
                                              D3DX_FILTER_BOX,
                                              0xFF000000,
                                              NULL,
                                              NULL,
                                              &Texture );
But the alpha values seem to be ignored as only black parts of the texture are transparent. I want the color key to be ignored by setting it to 0x00000000 but nothing is transparent then. It''s only using the color key and not the alpha values. I can''t figure out how to fix this. Can anyone help? ~CGameProgrammer( ); DevImg.net - Post screenshots, comment on others. Town 3D Engine - A city-rendering 3D engine. Download the demo.
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
Advertisement
Bump.

~CGameProgrammer( );

~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
m_Device->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATER );
m_Device->SetRenderState( D3DRS_ALPHAREF, 0 );

Are you allowing colors above RGB(0,0,0)? That means, that only black is transparent? Just guessing I don't know for sure! And why not set the colorkey to NULL/0?
BTW: I like your sigs!

.lick


[edited by - Pipo DeClown on May 2, 2003 6:29:09 AM]
ALPHAREF 0 means only an alpha component of 0 is transparent. It has nothing to do with the RGB color though. The alpha component of each pixel is set in the 32-bit bitmap used to create the texture.

Also I did experimentally set the color key to zero, which disables it. That caused nothing to be transparent. So that's how I know it's using the color key and not anything else.

~CGameProgrammer( );



[edited by - CGameProgrammer on May 2, 2003 7:40:12 AM]
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
quote:I want the color key to be ignored by setting it to 0x00000000 but nothing is transparent then. It''s only using the color key and not the alpha values. I can''t figure out how to fix this.

If I understand correctly, the D3DX texture loader discards the image''s alpha values when you disable colorkeying through 0x00000000?!

- I''d post a question to the DirectXDev mailing list to check whether that''s by design, or a bug

- As a workaround, I''d:
1. Use a different image loader (I use DevIL, which is excellent, in my opinion) to load the image with the alpha information, then create a texture, and copy the image into it.

The problem is that you''ll lose the filtering and mip-map creation D3DX does.

2. Set the (transparent) background for my images to be some weird unused color, and supply it as the colorkey.

Cheers,
Muhammad Haggag

quote:Set the (transparent) background for my images to be some weird unused color, and supply it as the colorkey.

No, when I set it to black, only black was transparent, not the part of the image with the null alpha values.

However one theory of mine was that in all cases the alpha values are discarded. I''ll look into this, and maybe contact that mailing list you provided. Thanks.

Originally I had my own texture loader, and creating mipmaps isn''t hard. But the D3DX loading functions poll the card to find out what''s allowed and they adjust the texture as necessary... I didn''t feel like writing that code myself.

~CGameProgrammer( );

~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
Alphatesting SHOULD read the alpha values.
When you give D3DX a colorkey, it searches for that color, and discards it(or not) and puts a alpha value in the alpha channel, so it''s like a 32bit picture. But since youre using a 32bit picture, shouldn''t you turn colorkeying off?

quote:DXSDK DOCS
Select the alpha test function with the D3DRS_ALPHAFUNC render state. Your application can set a reference alpha value for all pixels to compare against by using the D3DRS_ALPHAREF render state.


quote:DXSDK DOCS
D3DRS_ALPHAREF
Value that specifies a reference alpha value against which pixels are tested when alpha testing is enabled. This is an 8-bit value placed in the low 8 bits of the DWORD render-state value. Values can range from 0x00000000 through 0x000000FF. The default value is 0.




.lick



Yes, as I said I turned color-keying off by using 0x00000000 in the createtexture function, which disables color-keying. And nothing was transparent when I did that.

~CGameProgrammer( );

~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.

This topic is closed to new replies.

Advertisement