• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tispe

dds Alpha channel not working on mesh

17 posts in this topic

I have a DXT3 dds image loaded in a LPDIRECT3DTEXTURE9. Drawing it as a sprite will make the "black pixels/alpha" transparent. However if I use it on a mesh it will show black edges along the texture where it should be transparent.

What should I do to make it transparent ( fixed pipeline atm ) ?
0

Share this post


Link to post
Share on other sites
I suppose you're referring to the D3DX sprite class. I've never used it so this post is mere speculation.
I suppose the sprite class internally sets up [i]alpha blending[/i] and your code does not.
You need to enable [color=#000000][font=Consolas, Courier, monospace][size=3]D3DRS_ALPHABLENDENABLE [/size][/font][/color](default: false). I suggest to take the chance to also consider [color=#000000][font=Consolas, Courier, monospace][size=3]D3DRS_SRCBLEND[/size][/font][/color], [color=#000000][font=Consolas, Courier, monospace][size=3]D3DRS_DESTBLEND[/size][/font][/color]. There are more advanced alpha blending settings as well.
For this specific application however, you might just be interested in [i]alpha testing[/i]: see [color=#000000][font=Consolas, Courier, monospace][size=3]D3DRS_ALPHATESTENABLE, [/size][/font][/color][color=#000000][font=Consolas, Courier, monospace][size=3]D3DRS_ALPHAREF, [/size][/font][/color][color=#000000][font=Consolas, Courier, monospace][size=3]D3DRS_ALPHAFUNC[/size][/font][/color].
0

Share this post


Link to post
Share on other sites
Ok, I got the effect I wanted but with a bug.

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?
0

Share this post


Link to post
Share on other sites
That sounds like you've only got alpha test on, so the pixel is either opaque or transparant, and not actually blended properly. What render states are you setting?
0

Share this post


Link to post
Share on other sites
[CODE]
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);
[/CODE]

What else is needed?
0

Share this post


Link to post
Share on other sites
I have recoded this 4 times now and still no go. Tried even with just a pure vertex buffer, with and without indices.

[img]http://img19.imageshack.us/img19/2207/specks.png[/img]
0

Share this post


Link to post
Share on other sites
Another thing that is occuring is that if I have a sphere where a spot on the sphere surface is made transparent with alpha blending, the back/opposite side through the "spot hole" of the sphere also becomes transparent but is not supposed to.

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.
0

Share this post


Link to post
Share on other sites
lol fixed it:
[CODE]
SetRenderState(D3DRS_ALPHAREF , 0x80);
SetRenderState(D3DRS_ALPHAFUNC , D3DCMP_GREATER);
[/CODE]
0

Share this post


Link to post
Share on other sites
What DireCt version and what compiler and windows version are you using? I have problem finding AlphaBlend myself
0

Share this post


Link to post
Share on other sites
Always a new bug to figure out for me :(

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

[CODE]
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);
[/CODE]
0

Share this post


Link to post
Share on other sites
Does anyone have any idea why my alphas are getting darker the further away the mesh is from the camera?
0

Share this post


Link to post
Share on other sites
Finally I have traced the problem down to
[CODE]
SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
[/CODE]

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:
[CODE]
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;
}
[/CODE]
0

Share this post


Link to post
Share on other sites
The 3rd parameter to CreateTexture() is the number of mip levels to generate, with 0 meaning "All, down to 1x1". NULL evaluates to 0, so you're generating a texture with a full mip chain. I'm not sure what the texture contains when it's created, but I'd assume that it's either undefined or all 0 bytes. If you have 0 bytes, then you'll end up with the alpha channel being set to 0 in the lower mips. If you generate the lower mips with a call to GenerateMipSubLevels, then you may end up with the texture getting blurred and the alpha channel messed up - especially if the texture has a lot of alpha in it.

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);
0

Share this post


Link to post
Share on other sites
I suspect GenerateMipSubLevels() is failing - check the return code. You probably won't be able to get it to work either because I don't know of any cards which support that function for DXT compressed textures as that would require them to decompress and then recompress the texture. It's intended for use on render targets.

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().
0

Share this post


Link to post
Share on other sites
Thanks a lot for the comments. I think Evil Steve is right, the mipmap alphas are getting messed up by the filter. [b]But without the filter are the mipmaps even made?[/b] Does the pTex->UnlockRect(0); generate them? Is the filter just making them "worse" afterwards? Maybe pTex->GenerateMipSubLevels(); is called in UnLockRect().. who knows :P

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?
0

Share this post


Link to post
Share on other sites
Using D3DXSaveTextureToFile I can now see that all the mipmaps are all solid black in the DirectX Texture Tool when viewing the alpha channel and they remain solid black with any mipmap filter applied, even D3DTEXF_NONE. Also, the color channels are clear, no mipmaps are actually generated.... Just a blank space. pTex->GenerateMipSubLevels(); Does nothing!!


also CopyMemory(rc.pBits, pTextureData+4, ((width[b]+3[/b])/4) * ((height[b]+3[/b])/4) * 16); breaks my app, my code works for this...
0

Share this post


Link to post
Share on other sites
Hmm, still have no clue:
[CODE]
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);
}
[/CODE]

This does not fail atleast. But D3DUSAGE_AUTOGENMIPMAP does not do anything anyway....
0

Share this post


Link to post
Share on other sites
As Adam_42 said, now I think about it, I wouldn't expect GenerateMipSubLevels() to work for DXT compressed textures, since it would require uncompressing the DXT texture (Which is easy), resizing it (Which is also easy), and then re-compressing it (Which is hard - that's why art packages that save DXT compressed textures often have various settings like perceptual and so on to decide how it compresses).
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().
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0