#1 Members - Reputation: 368
Posted 02 February 2012 - 03:30 AM
What should I do to make it transparent ( fixed pipeline atm ) ?
#2 GDNet+ - Reputation: 1731
Posted 02 February 2012 - 04:02 AM
I suppose the sprite class internally sets up alpha blending and your code does not.
You need to enable D3DRS_ALPHABLENDENABLE (default: false). I suggest to take the chance to also consider D3DRS_SRCBLEND, D3DRS_DESTBLEND. There are more advanced alpha blending settings as well.
For this specific application however, you might just be interested in alpha testing: see D3DRS_ALPHATESTENABLE, D3DRS_ALPHAREF, D3DRS_ALPHAFUNC.
#3 Members - Reputation: 368
Posted 03 February 2012 - 02:21 AM
Places like some corners or edges there are small specks of black being visible. This is not shown in the game I "borrow" the asset from.
What are tyical sources for corner and edges specks?
#4 Moderators - Reputation: 1918
Posted 03 February 2012 - 04:14 AM
Steve Macpherson
Senior programmer, Firebrand Games
#5 Members - Reputation: 368
Posted 04 February 2012 - 07:30 AM
SetRenderState(D3DRS_ZENABLE, TRUE); SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50)); SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
What else is needed?
#7 Members - Reputation: 368
Posted 04 February 2012 - 01:32 PM
It might be that my faces are two-sided. One interesting observation I have is that a strip of triangles are black on one side(alpha black) and have a texture on the other side, but with ALPHABLENDENABLE set to true both sides are invisble, while I want the other side visible.
So if the same "subset" is curled ontop of itself it like a sphere or ring, it will make invisible faces behind it that should not be.
#10 Members - Reputation: 368
Posted 06 February 2012 - 11:04 AM
Now, if the Mesh is barely 5+ units away from the camera the mesh will have many faces start becoming fully transparent.
Turning off D3DRS_ALPHATESTENABLE corrects this but that messes up my textures... And it seems the further away my Mesh gets from the camera the darker it gets..
What is going on? I have messed around with these states without any results
SetRenderState(D3DRS_LIGHTING, false); SetRenderState(D3DRS_ZENABLE, true); SetRenderState(D3DRS_ALPHAREF, 0x50); SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER); SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50)); SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); SetRenderState(D3DRS_NORMALIZENORMALS, true); SetRenderState(D3DRS_ALPHABLENDENABLE, true); SetRenderState(D3DRS_ALPHATESTENABLE, true); SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
#12 Members - Reputation: 368
Posted 07 February 2012 - 03:05 PM
SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
Turning this off makes everything fine. But I want to know what it messed it up. Why would a DXT3 dds manually loaded mess this up?
Here is the loading code, I tried with software vertex processing also but nothing good came out of it:
D3DLOCKED_RECT rc;
if( *(DWORD*)(pTextureData) == 'DXT3' ){
hr = pGraphicsDevice->GetDevice()->CreateTexture(width, height, NULL, NULL, D3DFMT_DXT3, D3DPOOL_MANAGED, &pTex, NULL);
if( hr!=D3D_OK ) return NULL;
hr = pTex->LockRect(0,&rc,NULL,0);
if(hr==D3D_OK){
CopyMemory(rc.pBits,pTextureData+4,(width/4) * (height/4) * 16 );
pTex->UnlockRect(0);
}
pTex->GenerateMipSubLevels(); //on or off makes no diff
return pTex;
}
#13 Moderators - Reputation: 1918
Posted 07 February 2012 - 04:50 PM
In either case, you ned up with a texture that has a lot of alpha in the lower mips, and the lower mips are displayed when the texture is further away. Setting the mip filter to linear means the two closest mip levels are linearly interpolated to give the output colour, and not setting it means it stays at point (I.e. no mip filtering).
I can only assume that your particular setup makes the linear interpolation go screwy somehow.
What happens if you use D3DXSaveTextureToFile, save as .dds and then use the DirectX texture tool to look at the lower mip levels?
Also, slightly off topic, your code won't work correctly if the texture is not a multiple of 4 in width and height. It should be:
CopyMemory(rc.pBits, pTextureData+4, ((width+3)/4) * ((height+3)/4) * 16);
Steve Macpherson
Senior programmer, Firebrand Games
#14 Members - Reputation: 1410
Posted 07 February 2012 - 04:58 PM
I'm guessing you probably want to load the mipmaps from the texture file. The simplest option is to create a .dds file with the texture tool that comes with the SDK and load that with D3DXCreateTextureFromFile().
#15 Members - Reputation: 368
Posted 08 February 2012 - 02:18 AM
All I know is that there are no mipmap levels saved in the file beforehand, and the Game which I take the assets from do support Mipmaps, so the should be post generated, but how....
Maybe I need to decompress the DXT3, generate mipmaps and then compress it back to DXT3 or just leave it uncompressed... What do you think?
#16 Members - Reputation: 368
Posted 08 February 2012 - 10:52 AM
also CopyMemory(rc.pBits, pTextureData+4, ((width+3)/4) * ((height+3)/4) * 16); breaks my app, my code works for this...
#17 Members - Reputation: 368
Posted 08 February 2012 - 01:47 PM
if(FAILED(d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
D3DFMT_X8R8G8B8,
D3DUSAGE_AUTOGENMIPMAP,
D3DRTYPE_TEXTURE,
D3DFMT_DXT3)))
{
MessageBox(NULL, L"Can't D3DUSAGE_AUTOGENMIPMAP", L"Error", MB_OK);
PostQuitMessage(0);
}
This does not fail atleast. But D3DUSAGE_AUTOGENMIPMAP does not do anything anyway....
#18 Moderators - Reputation: 1918
Posted 09 February 2012 - 12:07 PM
This is also why there's no cards I know of that can use DXT compressed formats as render target formats.
You'd be better off making the mip levels yourself manually, and loading each mip level into the texture instead of getting D3D / the driver to try and do it itself. Or, pass 1 for the 3rd parameter to CreateTexture to create a texture with a single mip level, and don't bother calling GenerateMipSubLevels().
Steve Macpherson
Senior programmer, Firebrand Games







