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

Detecting transparent materials for correct rendering?

Last post 1/22/2009 5:43 AM by jwatte. 1 replies.
  • 1/22/2009 3:19 AM

    Detecting transparent materials for correct rendering?

    I understand that to render opaque and semi-transparent objects correctly, you would normally:

    1) Render all opaque objects from front to back with depth buffer on & alpha blending off.
    2) Then render all transparent objects from back to front with depth buffer off & alpha blending on.

    But what happens when you have models with both opaque and transparent parts? Is there any way to check whether individual meshes or meshparts are transparent or opaque (I cant find any way to get info on the material out of the model)? Or you'd have to set up your own model wrapper class with additional flags/info for each model to say which parts should be rendered in each pass?

    /Steve
  • 1/22/2009 5:43 AM In reply to

    Re: Detecting transparent materials for correct rendering?

    Yes, you would have to split out the ModelMeshParts and draw the transparent ones in the second pass. Note that you want depth writes to be off, but depth test to be on, when drawing back-to-front.

    To know whether a material is transparent or not, you'll have to come up with some convention. What I do is put an annotation on the technique used in the effect, and thus use different techniques for the transparent and opaque parts. If you're using the BasicEffect, that won't work, as you don't have control of the technique; you'll have to write a custom model processor that somehow figures out what's transparent, and adds that information to the Tag of the mesh (or mesh parts).

    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
Page 1 of 1 (2 items) Previous Next