Issue with transparent texture on 3D primitive, XNA 4.0

后端 未结 4 875
礼貌的吻别
礼貌的吻别 2021-01-01 05:50

I need to draw a large set of cubes, all with (possibly) unique textures on each side. Some of the textures also have parts of transparency. The cubes that are behind ones w

相关标签:
4条回答
  • 2021-01-01 06:07

    Drawing transparent objects properly is harder than regular ones. The reason is when face is rendered by default it marks all pixels as drawn at certain depth and as result pixels that are behind will not be drawn at all. I'd recommend getting a book on 3d rendering and look through for more details.

    The easiest approach you already found - draw transparent objects AFTER non-transparent ones. Works for transpreant and semi-transparent objects. Note that transparent objects need to be sorted to be drawn correctly (unlike non-transparent ones).

    In your particular case (non-semitransparent) you can change texture renreding to NOT render anything for transparent parts.

    0 讨论(0)
  • 2021-01-01 06:08

    You are relying on depth buffering to achieve occlusion. This technique only works for opaque objects.

    To achieve correct occlusion for a scene containing transparent objects:

    1. Set DepthBufferEnable and DepthBufferWriteEnable to true

    2. Draw all opaque geometry

    3. Leave DepthBufferEnable set to true, but change DepthBufferWriteEnable to false

    4. Sort alpha blended objects by distance from the camera, then draw them in order from back to front

    Extract from Depth sorting alpha blended objects by Shawn Hargreaves

    0 讨论(0)
  • 2021-01-01 06:16

    You may be able to use this if you don't have semi-transparent pixels on the objects. It'll either render completely solid or won't write to the Z-Buffer. As in Riemers Alpha Testing.

    0 讨论(0)
  • 2021-01-01 06:21

    XNA (and DirectX and all major 3D libraries) take in consideration something called culling. Although from your code I cannot tell for sure, from the images I think this is your problem. The polygons that you don't see have the vertices in the wrong order. If this is the problem, you have two solutions:

    • either turn culling off (device.RenderState.CullMode = CullMode.None; if I remember correctly)
    • apply your texture twice, with the points of the polygon both in clockwise order and counter clockwise
    0 讨论(0)
提交回复
热议问题