PDA

View Full Version : Problem with alpha and polygons



cronodragon
18-10-2005, 06:08 AM
http://www.teleportmedia.com/roleworld2/error_transparencia.jpg

I have this plane that is like a window with 4 glasses, and it's over a big plane. The big plane shows thru the window, but the cone is not rendered correctly. What could be happening, did I forget to set something?

These are the states I'm using:

Device.SetRenderState(D3DRS_AMBIENT, AmbientLight);

Device.SetRenderState(D3DRS_LIGHTING, iTrue);
Device.SetRenderState(D3DRS_DITHERENABLE, iTrue);
Device.SetRenderState(D3DRS_SPECULARENABLE, iTrue);

Device.SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

Device.SetRenderState(D3DRS_ZENABLE, iTrue);

Device.SetRenderState(D3DRS_ALPHABLENDENABLE, iTrue);
Device.SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
Device.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

Device.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
Device.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
Device.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
Device.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
Device.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
Device.SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
Device.SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
Device.SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);


Regards!
-Marco

Paulius
18-10-2005, 07:14 AM
You draw you?¢_Tre translucent thingy first, but it still writes to the Z buffer and you?¢_Tre cone doesn?¢_Tt pass the Z test. You should draw you?¢_Tre translucent after all solids, have Z writes disabled and preferably sort them back to front for a more correctly look.

cronodragon
18-10-2005, 02:15 PM
Thanks a lot! It works sorting the objects. :D

What do you mean with "Z writes disabled"? I'm rather new to 3D programming.

LP
18-10-2005, 02:35 PM
I'm not sure, but it seems that your cone is covered by transparent part of texture. If that is the case, then perhaps the best solution would simply to enable alpha-testing.

Check DirectX SDK:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/gettingstarted/direct3ddevices/states/renderstates/alphatestingstate.asp
(This is what I don't like in PhpBB forums - since you can't put custom title to the link, it appears very long and ugly)

cronodragon
18-10-2005, 02:40 PM
Thanks, I'll check.

And you can use the other URL syntax:

The nice link (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/gettingstarted/direct3ddevices/states/renderstates/alphatestingstate.asp)


[url=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/gettingstarted/direct3ddevices/states/renderstates/alphatestingstate.asp]The nice link[/url]

8)

Paulius
18-10-2005, 03:06 PM
Z testing tests if incoming fragments depth is lower than the one currently in the Z buffer (ensuring that stuff in the background doesn?¢_Tt get drawn on to of stuff in the foreground). Disabling Z writing mean?¢_Ts that nothing gets written to the depth buffer, this should be done for translucent polygons so that stuff that gets rendered later wouldn?¢_Tt be tested against the depth of transparent polygons.
I don?¢_~t use direct3D, but a quick googling gave me this
Device.SetRenderState(D3DRS_ZWRITEENABLE, false);
If you use alpha testing like lifepower suggested then you don?¢_Tt need to worry about sorting and a lot of commercial games do it like that, but this way you?¢_Tll be limited to complete transparency (no translucency) and there?¢_Tll be texture filtering artifacts on passing and non passing fragment edges.

Clootie
18-10-2005, 08:34 PM
If you use alpha testing like lifepower suggested then ... there?¢_Tll be texture filtering artifacts on passing and non passing fragment edges.
Not really artifacts, but aliasing (if you set alpha ref to 1).

marmin
26-10-2005, 04:05 AM
and Never set the Z near value to 0. this will give awkward distortions.

cronodragon
29-10-2005, 09:21 PM
Ok, now I'm writing the code to solve the problem. It's easy to draw the solid triangles lists first and then the translucent ones, but now I have to order the translucent ones. I can think in several ways of doing that, but none that doesn't waste a lot of proccessing time. Any suggestion for a fast sorting method? Thanks in advance. :D

Paulius
30-10-2005, 07:47 AM
There?¢_~s no perfect way to sort as this article (http://www.sjbaker.org/steve/omniv/alpha_sorting.html) explains. You shouldn?¢_Tt sort polygons but rather groups of them (translucent sphere could be drawn correctly from any angle if it?¢_Ts split into 8 groups). As long as these groups are small enough and do not intersect it should be passable to radix or quick sort them by groups centers distance to camera.

cronodragon
30-10-2005, 03:18 PM
Very interesting, thanks.