Johannes Hansen

I've just tested some of the WPF 3D features in the latest release of the WinFX SDK. I noticed some strange opacity behavior which I have described in greater detail here:

http://espy.dk/WPF3DOpacity/

Is it a bug or a feature


Best regards,
Johannes Hansen
frontAvenue A/S


Re: Windows Presentation Foundation (WPF) Strange WPF 3D opacity behavior

David Teitlebaum MSFT

It's a feature, for two reasons:

1.  The blend function.

When an alpha blended polygon is drawn in Avalon 3D, a blend function is performed on each fragment of transparent polygon to determine how much color contribution comes from the polygon being rendered, and how much comes from the contents of the buffer into which it's being rendered.  Doing this properly requires the use of a non-commutative blend function (in OpenGL parlance, it's GlBelndFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ), meaning all the polygons behind an alpha blended polygon need to be drawn before that polygon is drawn.  However, this requires that every alpha blended polygon in the scene gets rendered after all polygons behind it have been rendered, and this necessitates depth sorting of overlapping alpha-blended polygons.  As you can probably guess, this operation is extremely expensive.

You run into additional trouble when you're dealing with intersecting alpha blended polygons, since no amount of sorting will result in a correctly rendered image.  To deal with this situation, the intersecting polygons need to be broken up into non-intersecting pieces, those pieces need to be sorted, and finally rendered in sorted order.  Extremely expensive.

2.  The z-buffer

When an alpha blended polygon is drawn, it writes its depth values into the z-buffer.  Because of this, polygons rendered behind the alpha blended polygon will be occluded during the z-test during rendering, and there will be no resulting color contribution.  Lower level 3D APIs (OpenGL and D3D) allow z-test and z-write to be disabled arbitrarily, though we chose not to expose that level of granular control in Avalon 3D for version 1.



These are problems inherent to all major 3D APIs.  Typically with major 3D APIs, a scene is most optimally rendered in the following way:

1.  All opaque polygons are rendered in close -> far order to get the maximum occlusion performance boost.  (the order isn't critical here)
2.  All transparent polygons are sorted and then rendered in far -> order (for proper alpha blending; order is critical)



To get around the issue in Avalon 3D, you can use emissive materials (rather than alpha blended diffuse materials).  Emissive materials use a purely additive blend function, and addition is fully commutative.  Also, we are disabling z-write for all materials with an additive blend function (emissive and specular).  This means that they won't have to be sorted.  This isn't in any public builds yet but should be eventually.

The one caveat is that the output doesn't look the same as it would with true alpha blending.  Overlapping colors are simply added.  It's vastly better than the alternative, however, and would work very well in the scenario you've described.

Hope that helps  Smile
David




Re: Windows Presentation Foundation (WPF) Strange WPF 3D opacity behavior

Johannes Hansen

Thank you for this very thorough answer. It helped a lot. Smile

- Johannes




Re: Windows Presentation Foundation (WPF) Strange WPF 3D opacity behavior

damien morton

Is this optimization for emissive materials in the Jan CTP Will it be in the Feb CTP





Re: Windows Presentation Foundation (WPF) Strange WPF 3D opacity behavior

David Teitlebaum MSFT

It's in the Feb CTP.




Re: Windows Presentation Foundation (WPF) Strange WPF 3D opacity behavior

Boman

how to change the z-depth on a object I¡¯am also having trouble with transparency i 3d when 3d objects overlap

where to find to property Smile

/Bo





Re: Windows Presentation Foundation (WPF) Strange WPF 3D opacity behavior

Peter S Antal - MSFT

Hello Bo,

I'll elaborate a bit on some details from David's old post.

The Z depth is a computed floating point value representing the object's distance from the camera, with 0 corresponding to the near plane, and 1 being at the far plane of your camera. It is used to identify if a pixel is in front, or behind of what has already been rendered(in which case we do not render). The Z-value is calculated pixel by pixel on each triangle which is rendered in the camera frustum. These values are not made available as a property per-se, but you can easily change the Z-depth an object will be sampled at, by moving it via Transform3D's.

The Z-buffering concept is not exclusive to WPF, and is seen in DirectX and OpenGL also - you can learn more about it at:

http://en.wikipedia.org/wiki/Z-buffering

With regards to transparency, you may have noticed that order affects how transparent surfaces are rendered. Because we use the Z-Buffer to ignore processing of any objects behind the buffer in non-additive blend functions (ie- DiffuseMaterial), this means that in order to get the desired transparency effect, one needs to order the objects so that we render the most distant objects first, with closest objects last.

Here's a simple overview. Imagine two quads with diffuse, partially transparent material, one over the other. When the first object to be rendered is behind the next object, both objects are successfully rendered, and you get your intended blending.

Camera --> 2 1

In the case where the first object is in front of a later object, the later object does not get rendered/blended, because the Z-Buffer was marked to ignore everything behind the first one.

Camera -> 1 2

Let me know if you would like some other details/elaboration on this.

I hope this helps,

Peter






Re: Windows Presentation Foundation (WPF) Strange WPF 3D opacity behavior

Boman

Hi Peter

Thank you for the infos - ..

Just wanted to know if there was a easy way to tell a object to be infront of another. zindex on framework object ..

I have made a application like the cover browser from thirteen23 Harmoni http://www.thirteen23.com/labs/winfx/harmony/

I just wanted to add alpha/opasity to the other objects than the one selected ..
( or even better animate them to grayscale , just havent figured that out jet )
But my problem is exactly the order that the objects are rendered ... so the left side of the selected item works as expected - but the right side does not - I have tried to make the samething in 2D and here I just change the zindex - but it just looks a lot cooler i 3D Big Smile because of the cameraPostion ect. So just wanted to know if I could do the same with z depth i 3D.

- Another thing now i have your attention Smile ..
What is the best way to map panel content onto 3D meshes to keep the aspect ratio they are created in ..
Can a control the way I map the panels ... or Should I make the mesh size according to the panelsize ..

Hope you understand my question ... as it is now my panels just stretch across the mesh and thats not exacly how I wanted it Smile ..

Do you have any info on how to deal with this problem

/Bo