Optimizing WPF 3D Performance

Source: Internet
Author: User

Original: Optimizing WPF 3D Performance

Maximize WPF 3D performance. NET Framework 4.5

As your use of the Windows Presentation Foundation (WPF) to build 3D controls and include 3D scenes in your applications, it I s important to consider performance optimization. This topic provides a list of 3D classes and properties that has performance implications for your application, along wit H Recommendations for optimizing performance if you use them.

This topic assumes a advanced understanding of Windows Presentation Foundation (WPF) 3D features. The suggestions in this document apply to "rendering Tier 2"-roughly defined as hardware that supports pixel shader versio N 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 "do not" need to the 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 are enabled (slow) by Def Ault on Viewport3D.

IsHitTestVisible

Set viewport3d.ishittestvisible to False whenever if you don't need Windows Presentation Foundation (WPF) to consider th  E content of a Viewport3D when performing mouse hit testing. Hit testing 3D content was done in software and can being 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 GeometryModel3D instances with the same materials and Transforms into a few larger geometr Ymodel3d and MeshGeometry3D instances.

MeshGeometry3D

Mesh animation-changing The individual vertices of a mesh on a per-frame basis-is don't always efficient in Windows Presenta  tion Foundation (WPF). To minimize the performance impact of change notifications when each vertex was modified, detach the mesh from the visual T  Ree before performing per-vertex modification.  Once the mesh has been modified, reattach it to the visual tree. Also, try to minimize the size of meshes that would be a animated in this.

3D antialiasing

To increase rendering speed, disable multisampling on a Viewport3D by setting the attached property EdgeMode to Aliase D. By default, 3D antialiasing are disabled on Microsoft Windows XP and enabled on Windows Vista with 4 samples per pixel.< /c0>

Text

Live text in a 3D scene (live because it's in a DrawingBrush or VisualBrush) can is slow. Try to use images of the text instead (via RenderTargetBitmap) unless the text would change.

TileBrush

If 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&NBSP;CACHINGHINT&NBSP;TO&N Bsp cache). Set the minimum and maximum scale invalidation thresholds (with the attached PROPERTIES&NBSP;CACHEINVALIDATIONTHRESHOLDMI Nimum and cacheinvalidationthresholdmaximum) So and the cached brushes won ' t be regenerated too frequently, wh Ile still maintaining your desired level of quality. By Default, drawingbrush and visualbrush are not cached, meaning that every time something painted With the brush have to be re-rendered, the entire content of the brush must first being re-rendered to an intermediate surface .

BitmapEffect

BitmapEffect forces all affected content to be rendered without hardware acceleration. For best performance, does not use BitmapEffect.

Performance Impact:medium

Property

Recommendation

MeshGeometry3D

When a mesh was defined as abutting triangles with shared vertices and those vertices has the same position, normal, and T Exture coordinates, define each GKFX vertex only once and then define your triangles by index with triangleindices.

ImageBrush

Try to minimize texture sizes If you had explicit control over the size (if 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 perf Ormance.

Opacity

When rendering translucent 3D content (such as reflections), use the opacity properties on brushes or materials (via Opaci Ty 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 many 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 is multiparentable since they ' re derived from Freezable.

Freezable

Call the Freeze method on Freezables when their properties would 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 won't change. The content can is converted to a Image via RenderTargetBitmap and then used in an ImageBrush.

Backmaterial

Don ' t use backmaterial unless your 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. Consider omitting these from your scene.

Materialgroup

Each Material in a materialgroup causes another rendering pass, so including many materials, even simple materials, can Dr amatically increase the fill demands 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 Si Ngle Matrixtransform3d, setting it to being the product of the the transforms that would otherwise exist independently in the Transform group.

Light

Minimize the number of lights in your scene.  Too Many lights in a scene would force Windows Presentation Foundation (WPF) to fall back to software rendering. The limits is roughly 110DirectionalLight objects, pointlight objects, or + 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 GKFX instances of GeometryModel3D into the scene.

Light

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

Light

Black Lights won ' is visible, but they'll 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, Andtriangleindices, pre-size the collections before value population. If possible, pass the collections ' constructors prepopulated data structures such as arrays or Lists.

Optimizing 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.