2
\$\begingroup\$

OK been googling nonstop for ages...

My problem is, i need transparent models in my game. After a lot of annoying fiddling around with my code, i changed the blendstate to alphablend. This allowed me to start having transparency in my models.

However now i face another problem. Any other part of the same model that is meant to be view THROUGH the transparent part of the model, is not shown.

Basically it is only showing the outermost part of the model, even though an inner part is meant to be seen through the transparent part.

Any help? Thanks

\$\endgroup\$
3
  • \$\begingroup\$ Do you render first opaque model and than transparent model? Becuase that is the only correct way. \$\endgroup\$
    – Notabene
    Commented Jun 13, 2011 at 10:37
  • \$\begingroup\$ No they are the same model, i just have parts of the texture than are transparent, and parts that aren't. \$\endgroup\$
    – Joel
    Commented Jun 13, 2011 at 11:31
  • \$\begingroup\$ For example a window model, with a border around it, but the glass is transparent/semi transparent \$\endgroup\$
    – Joel
    Commented Jun 13, 2011 at 11:31

2 Answers 2

3
\$\begingroup\$

In order to get proper blending you will probably have to break the object up into multiple models. And even then you are still limited since from certain angles you will be able to break the transparant blend again. Transparancy is actually quite difficult to get correct without using some cool but fairly exotic solutions. One that comes to mind is Order Independant Transparancy, unfortunately it requires DX Capabilities that XNA doesnt have yet. My recomendation is to go back into your 3d editor and break your mesh apart so you can sort the transparant and non transparant parts into a correct order.

\$\endgroup\$
4
  • \$\begingroup\$ Thankyou! However before i answer, could you tell me this. If you have played Minecraft... How would this be done for something like the glass block? Because it is all still rendered as one chunk as far as i am aware... \$\endgroup\$
    – Joel
    Commented Jun 13, 2011 at 13:44
  • 2
    \$\begingroup\$ Those glass chunks uses 1-bit alpha = 1 opaque, 0 transparent. You can write simple shader, which doesn't need any sorting, which uses something like this: if (1bitAlpha) discard(). That discards fragment(pixel) from rendering and writing to the depth buffer \$\endgroup\$
    – Notabene
    Commented Jun 13, 2011 at 13:54
  • 1
    \$\begingroup\$ If something is fully tansparent it is relatively easy to deal with as Notabene mentioned, just don't allow it to affect the color/depth buffers. Breaking up and sorting will most probably be used only to control the render order of partially transparent (translucent) objects. \$\endgroup\$ Commented Jun 13, 2011 at 20:49
  • \$\begingroup\$ yeah it was discard i needed. I ended up using if (samplerColor.a == 0) discard; and that did the trick :D \$\endgroup\$
    – Joel
    Commented Jun 14, 2011 at 12:39
0
\$\begingroup\$

Folow this workflow:

  • Sort your model parts by depth, from the furthest one to the nearest one.
  • Enable depth-writing and draw the opaque ones in order.
  • Disable depth writing and draw the transparent ones in order.
\$\endgroup\$
2
  • \$\begingroup\$ it's one mesh. One model.. I can't have different settings for the same mesh. \$\endgroup\$
    – Joel
    Commented Jun 13, 2011 at 12:26
  • \$\begingroup\$ Why to do sorting on the opaque geometry? \$\endgroup\$
    – Notabene
    Commented Jun 13, 2011 at 13:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .