Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 theCompositionTarget.rendering.

Please see the following images:

enter image description here

enter image description here

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.

like image 290
Maria Avatar asked Mar 06 '16 17:03

Maria


1 Answers

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.

like image 127
cokeman19 Avatar answered Oct 25 '22 11:10

cokeman19