Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Problem with alpha and polygons

  1. #1

    Problem with alpha and polygons



    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:
    Code:
      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

  2. #2

    Problem with alpha and polygons

    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.

  3. #3

    Problem with alpha and polygons

    Thanks a lot! It works sorting the objects.

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

  4. #4

    Problem with alpha and polygons

    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/de...stingstate.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)

  5. #5

    Problem with alpha and polygons

    Thanks, I'll check.

    And you can use the other URL syntax:

    The nice link

    Code:
    [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]

  6. #6

    Problem with alpha and polygons

    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.

  7. #7

    Problem with alpha and polygons

    Quote Originally Posted by Paulius
    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).
    There are only 10 types of people in this world; those who understand binary and those who don't.

  8. #8

    Problem with alpha and polygons

    and Never set the Z near value to 0. this will give awkward distortions.
    Marmin^.Style

  9. #9

    Problem with alpha and polygons

    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.

  10. #10

    Problem with alpha and polygons

    There?¢_~s no perfect way to sort as this article 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.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •