Optimize WPF 3D Performance

Source: Internet
Author: User
Maximize WPF 3D Performance . NET Framework 4.5 

As you use the Windows Presentation Foundation (WPF) to build 3D controls and include 3D scenes in your applications, it is important to consider performance optimization. this topic provides a list of 3D classes and properties that have performance implications for your application, along with recommendations for optimizing performance when you use them.

This topic assumes an advanced understanding of Windows Presentation Foundation (WPF) 3D features. the suggestions in this document apply to "rendering Tier 2"-roughly defined as hardware that pixorts pixel shader version 2.0 and vertex shader version 2.0. for more details, see graphics rendering tiers.

Performance impact: high

Property

Recommendation

Brush

Brush speed (fastest to slowest ):

Solidcolorbrush

Lineargradientbrush

Imagebrush

Drawingbrush (cached)

Visualbrush (cached)

Radialgradientbrush

Drawingbrush (Uncached)

Visualbrush (Uncached)

Cliptoboundsproperty

Set viewport3d. cliptobounds to false whenever you do not need to have Windows Presentation Foundation (WPF) explicitly clip the content of a viewport3d to the viewport3d's rectangle. windows Presentation Foundation (WPF) antialiased clipping can be very slow, and cliptobounds is enabled (slow) by default on viewport3d.

Ishittestvisible

Set viewport3d. ishittestvisible to false whenever you do not need Windows Presentation Foundation (WPF) to consider the content of a viewport3d when ming mouse hit testing. hit testing 3D content is done in software and can be slow with large meshes. ishittestvisible is enabled (slow) by default on viewport3d.

Geometrymodel3d

Create different models only when they require different materials or transforms. Otherwise, try to coalesce many rymodel3d instances with the same materials and transforms into a few larger geometrymodel3d and meshgeometry3d instances.

Meshgeometry3d

Mesh Animation-changing the individual vertices of a mesh on a per-frame basis-is not always efficient in Windows Presentation Foundation (WPF ). to minimize the performance impact of change configurications when each vertex is modified, detach the mesh from the visual tree before configurming per-vertex modification. once the mesh has been modified, reattach it to the visual tree. also, try to minimize the size of meshes that will be animated in this way.

3D antialiasing

To increase rendering speed, disable multisampling on a viewport3d by setting the attached property edgemode to aliased. by default, 3D antialiasing is disabled on Microsoft Windows XP and enabled on Windows Vista with 4 samples per pixel.

Text

Live text in a 3D scene (live because it's in a drawingbrush or visualbrush) can be slow. Try to use images of the text instead (via rendertargetbitmap) unless the text will change.

Tilebrush

If you must use a visualbrush or a drawingbrush in a 3D scene because the brush's content is not static, try caching the brush (setting the attached property cachinghint to cache ). set the minimum and maximum scale invalidation thresholds (with the attached properties between and between) so that the cached brushes won't be regenerated too frequently, while still maintaining your desired level of quality. by default, drawingbrush and visualbrush are not cached, meaning that every time something painted with the brush has to be re-rendered, the entire content of the brush must first be re-rendered to an intermediate surface.

Bitmapeffect

Bitmapeffect forces all affected content to be rendered without hardware acceleration. for best performance, do not use bitmapeffect.

Performance impact: Medium

Property

Recommendation

Meshgeometry3d

When a mesh is defined as abutting triangles with shared vertices and those vertices have the same position, normal, and texture coordinates, define each shared vertex only once and then define your triangles by index with triangleindices.

Imagebrush

Try to minimize texture sizes when you have explicit control over the size (when you're using a rendertargetbitmap and/or an imagebrush ). note that lower resolution textures can decrease visual quality, so try to find the right balance between quality and performance.

Opacity

When rendering translucent 3D content (such as reflections ctions), use the opacity properties on brushes or materials (via opacity or color) instead of creating a separate translucent viewport3dby setting viewport3d. opacity to a value less than 1.

Viewport3d

Minimize the number of viewport3d objects you're using in a scene. Put into 3D models in the same viewport3d rather than creating separate viewport3d instances for each model.

Freezable

Typically it's beneficial to reuse meshgeometry3d, geometrymodel3d, brushes, and materials. All are multiparentable since they're derived from freezable.

Freezable

Call the freeze Method on freezables when their properties will remain unchanged in your application. Freezing can decrease working set and increase speed.

Brush

Use imagebrush instead of visualbrush or drawingbrush when the content of the brush will not change. 2d content can be converted to an image via rendertargetbitmap and then used in an imagebrush.

Backmaterial

Don't use backmaterial unless you actually need to see the back faces of your geometrymodel3d.

Light

Light speed (fastest to slowest ):

Ambientlight

Directionallight

Pointlight

Spotlight

Meshgeometry3d

Try to keep mesh sizes under these limits:

Positions: 20,001 point3d instances

Triangleindices: 60,003 int32 instances

Material

Material speed (fastest to slowest ):

Emissivematerial

Diffusematerial

Specularmaterial

Brush

Windows Presentation Foundation (WPF) 3D doesn' t opt out of invisible brushes (black ambient brushes, clear brushes, etc.) in a consistent way. Consider omitting these from your scene.

Materialgroup

Each material in a materialgroup causes another rendering pass, so far when materials, even simple materials, can encrypt increase the fill demans on your GPU. Minimize the number of materials in your materialgroup.

Performance impact: low

Property

Recommendation

Transform3dgroup

When you don't need animation or data binding, instead of using a transform group containing multiple transforms, use a single matrixtransform3d, setting it to be the product of all the transforms that wowould otherwise exist independently in the transform group.

Light

Minimize the number of lights in your scene. too worker lights in a scene will force Windows Presentation Foundation (WPF) to fall back to software rendering. the limits are roughly 110 directionallight objects, 70 pointlight objects, or 40 spotlight objects.

Modelvisual3d

Separate moving objects from static objects by putting them in separate modelvisual3d instances. modelvisual3d is "heavier" than geometrymodel3d because it caches transformed bounds. geometrymodel3d is optimized to be a model; modelvisual3d is optimized to be a scene node. use modelvisual3d to put shared instances of geometrymodel3d into the scene.

Light

Minimize the number of times you change the number of lights in the scene. each change of light count forces a shader regeneration and recompilation unless that configuration has existed previously (and thus had its shader cached ).

Light

Black lights won't be visible, but they will add to render time; Consider omitting them.

Meshgeometry3d

To minimize the construction time of large collections in Windows Presentation Foundation (WPF), such as a meshgeometry3d's positions, normals, texturecoordinates, counters, pre-size the collections before value population. if possible, pass the collections 'constructors prepopulated data structures such as arrays or lists.

Optimize WPF 3D Performance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.