简体   繁体   中英

WPF 2D in 3D view Animations : Performance issue

I've put a TextBlock in a 3D panel ( Planerator ) and I used a Storyboard to animate it. (as crawl text)

When the field of view is 1 everything works fine, But if I set the field of view to more than 50 the frame rate will drop sharply and rendering will be choppy.

I used the CompositionTarget.rendering .

Please see the following images:

在此输入图像描述

在此输入图像描述

I need to 2D animations in 3d view with good performance.

Please tell me how can I solve this problem? Should I leave WPF and go to the DirectX?

UPDATE 1 :

I just want to move ONE 2Dtext in 3D space , but the performance is poor.(rendering isn't smooth it is choppy)

This is a sample project .

UPDATE 2:

This is the sample project updated version based on cokeman19's answer. (the performance have been improved ~10 frames, But I need to perfect rendering)

UPDATE 3 :

Finally, I got an acceptable performance with the help of the cokeman19's answer and the contents of this page .

I'm not sure if it's just a byproduct of the sample app, but under Planerator.CreateVisualChild() , it doesn't seem to be necessary to set the GeometryModel3D.BackMaterial . For reference:

VisualBrush vb = new VisualBrush(_logicalChild);
SetCachingForObject(vb);  // big perf wins by caching!!
Material backMaterial = new DiffuseMaterial(vb);
...
GeometryModel3D backModel = new GeometryModel3D() { ..., BackMaterial = backMaterial };

The BackMaterial is a VisualBrush wrapper around the logical child, which doesn't belong to the visual tree, so rendering doesn't seem to make sense here. Moreover, the logical child (the LayoutInvalidationCatcher class), is in turn a wrapper around the visual child, which is already rendered (using _logicalChild ) in setting frontModel.Visual .

Removing the code for the creation and setting of BackMaterial brings the FPS up to ~55.

In addition, if it's an option, setting the following brings the FPS back up to 60, with no noticeable degradation in quality.

RenderOptions.SetEdgeMode(_viewport3d, EdgeMode.Aliased);

Update:

The only other gain I was able to make was to set the CacheMode to BitmapCache , which may not be appliable for your needs.

frontModel.CacheMode = new BitmapCache(20) { EnableClearType = false };

Even on my slowest machine, this allowed for maximum FPS, but there are some drawbacks. Because the zoom level is so high on the text element, and this technique creates a picture to use in the animation (instead of animating the UIElement itself), I had to set the scale level to 20 before it became almost visually imperceptible. This of course has memory implications, as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM