XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

Transparent vertices

Last post 05-12-2008 4:09 PM by MartinR23. 3 replies.
  • 05-12-2008 6:37 AM

    Transparent vertices

    I have managed to get some vertices in my model to become transparent, by setting the vertices alpha to 0 and these settings:
    device.RenderState.SourceBlend = Blend.SourceAlpha ;
    device.RenderState.DestinationBlend = Blend.InverseSourceAlpha;
    device.RenderState.AlphaBlendEnable = true;

    The problem I have is that when rotating the model some of the vertices that should be transparent are still opaque, as if they are only transparent in one direction.

    I am aware that models have to drawn in the correct order for transparency to work, but that is not my problem as there is only one model.

    thanks
  • 05-12-2008 11:40 AM In reply to

    Re: Transparent vertices

    I believe you also need to draw the opaque parts of the model first, and then the transparent parts, from back to front.
  • 05-12-2008 1:12 PM In reply to

    Re: Transparent vertices

    Correct transparent drawing requires full sorting of every triangle, not just each model (Eli has a good explanation as to why). If a model contains more than one triangle, it's pretty random what order those triangles will be drawn, and depending on which way you are looking at the model, this might not give correct results.

    There are many possible solutions:
    • Avoid alpha blending! Seriously. I know this sounds stupid, but most experienced game developers avoid it like the plague, or just isolate it to places where they know it won't cause problems, designing their games so they just don't need many complex alpha blended objects.
    • Make all your alpha blended objects fully convex. If the shape of your mesh is convex, then you can draw it just with backface culling turned on, and not need to sort the triangles within it.
    • If you can't make your alpha blended model 100% convex, split it up into more than one smaller piece, making sure each separate piece is convex, and then depth sort the individual pieces.
    • You can use a multipass technique: first draw the object into the depth buffer with color writes turned on, then render again with alpha blending enabled using the depth buffer data you primed in the first pass.
    XNA Framework Developer - blog - homepage
  • 05-12-2008 4:09 PM In reply to

    Re: Transparent vertices

    Thanks for the responses, I'll try to think of a way to avoid alpha blending in this case, otherwise I'll look into a more complex solution.
Page 1 of 1 (4 items) Previous Next