wpftexturestransparentclipping

WPF 3D transparent textures - clipping?


http://www.youtube.com/watch?v=gZNdfVwkttM - you can see all of the problem described on this video if you can't see pictures.

All of walls in all images below have a semitransparent PNG texture. Each square wall, floor and ceiling tile is a separate GeometryModel3D (I know that is no good for performance but...). The floor and the ceiling of the central cube have no any geometry and textures - so they have a color the same as Window.Background (black). But the effect considered appears in any way of transparency obtaining: texture for ImageBrush with transparency, Material.Color (for example DiffuseMAterial.Color) where Color has alpha channel, ImageBrush as material where ImageBrush has Opacity - all the way I have the same problem.

All of walls consists of two triangles. Where are no explicit normals , because I define triangle indices so normals culculated automatically by WPF.

http://imagepost.ru/images/i/ma/image00001.png

It also haven't any back material or extra triangles from the back side.

As you can see there is no problem if you look only from +Z to -Z (standing on the blue square and looking to the red square - that is the second picture).

But if you look backward (from red to blue - the first picture) there is no transparency!

Well, I desided to look from the yellow square (third picture).

And then I walked nearer - you can see what was happening (pictures from 4 to 6).

There are no geometry construction error or texture mapping error or lighting error! It is some kind of clipping, I guessed! In addition there are some interested pictures 7 and 8 to prove my guess.

The last picture shows the white background of the window that hosted Viewport3D (previous was black), and my guess about clipping confirmed - WPF just not painted this part of the scene and we can see the window background!

BUT! If this happens from various looks, why the look from +Z to -Z (second picture) seems well?!


Solution

  • You need to sort the triangles based on their distances from the viewpoint. Only then, wpf will be able to blend the transparent textures. DirectX is able to blend triangles on top of each other but only when drawing them back to front

    http://www.ericsink.com/wpf3d/2_Transparency.html