优化WPF 3D性能

简介: 原文:优化WPF 3D性能Maximize WPF 3D Performance .NET Framework 4.5   As you use the Windows Presentation Foundation (WPF) to build 3D contr...
原文: 优化WPF 3D性能

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 supports 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 performing 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 GeometryModel3D 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 notifications when each vertex is modified, detach the mesh from the visual tree 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 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 CacheInvalidationThresholdMinimum and CacheInvalidationThresholdMaximum) 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), 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 many 3D models in the same Viewport3D rather than creating separate Viewport3D instances for each model.

Freezable

Typically it’s beneficial to reuse MeshGeometry3DGeometryModel3D, 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 including many materials, even simple materials, can dramatically 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 single MatrixTransform3D, setting it to be the product of all 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 will force Windows Presentation Foundation (WPF) to fall back to software rendering.  The limits are roughly 110DirectionalLight 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 PositionsNormalsTextureCoordinates, andTriangleIndices, pre-size the collections before value population. If possible, pass the collections’ constructors prepopulated data structures such as arrays or Lists.

目录
相关文章
|
缓存 C# 虚拟化
WPF列表性能提高技术
WPF数据绑定系统不仅需要绑定功能,还需要能够处理大量数据而不会降低显示速度和消耗大量内存,WPF提供了相关的控件以提高性能,所有继承自`ItemsControl`的控件都支持该技术。
188 0
|
大数据 C# 数据库
WPF DataGrid 性能加载大数据
原文:WPF DataGrid 性能加载大数据 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010265681/article/details/76651725  WPF(Windows Presentation Foundation)应用程序在没有图形加速设备的机器上运行速度很慢是个公开的秘密,给用户的感觉是它太吃资源了,WPF程序的性能和硬件确实有很大的关系,越高档的机器性能越有优势。
2240 0
|
C# 虚拟化 UED
细数改善WPF应用程序性能的10大方法
原文:细数改善WPF应用程序性能的10大方法       WPF(Windows Presentation Foundation)应用程序在没有图形加速设备的机器上运行速度很慢是个公开的秘密,给用户的感觉是它太吃资源了,WPF程序的性能和硬件确实有很大的关系,越高档的机器性能越有优势。
1292 0
|
算法 C# 图形学
WPF绘制深度不同颜色的3D模型填充图和线框图
原文:WPF绘制深度不同颜色的3D模型填充图和线框图 在机械测量过程中,测量的数据需要进行软件处理。通常测量一个零件之后,需要重建零件的3D模型,便于观察测量结果是否与所测工件一致。
3407 0
|
C# 图形学 传感器
WPF在3D Cad模型中利用TextureCoordinates实现颜色渐变显示偏差值的变化
原文:WPF在3D Cad模型中利用TextureCoordinates实现颜色渐变显示偏差值的变化 注:最近在做3D机械模型重建方面的软件,需要根据光栅传感器采集的数据绘制3D图形,并显示出色差以及填充和线框图。
1067 0
|
C# 索引
好玩的WPF第四弹:用Viewport2DVisual3D实现3D旋转效果
原文:好玩的WPF第四弹:用Viewport2DVisual3D实现3D旋转效果 版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/46567895 效果呢就是这么个效果,但是大家要发挥想象力,比如做成一个可以旋转的按钮等等。
956 0
|
C# C++
WPF性能调试系列 – 应用程序时间线
原文:WPF性能调试系列 – 应用程序时间线 WPF性能调试系列文章:     WPF页面渲染优化:Application Timeline     WPF页面业务加载优化:Ants Performance Profiler       WPF内存优化:Ants Memory Profiler   应用程序时间线(Application Timeline)     应用程序时间线工具是VS2015新添加的功能,通过对WPF程序的检测,可以分析应用程序消耗的时间包含用户界面框架、服务网络和磁盘请求、程序启动及页面加载。
1504 0
|
C#
WPF性能调试系列 – 内存监测
原文:WPF性能调试系列 – 内存监测 WPF性能调试系列文章:     WPF页面渲染优化:Application Timeline     WPF页面业务加载优化:Ants Performance Profiler       WPF内存优化:Ants Memory Profiler   内存监测(Ants Memory Profiler)     Ants Memory Profiler是专门针对于.net程序的内存动态分析工具,通过实时监测WPF程序中每个对象分配的内存空间大小,来提供多样式报告展示内存的使用情况。
1385 0
|
监控 C# Windows
WPF性能调试系列 – Ants Performance Profiler
原文:WPF性能调试系列 – Ants Performance Profiler WPF性能调试系列文章:     WPF页面渲染优化:Application Timeline     WPF页面业务加载优化:Ants Performance Profiler       WPF内存优化:Ants Memory Profiler   Ants Performance Profiler     Ant Performance Profiler是RedGate旗下强大的性能调优产品, 可以用于分析.NET Winform、webform以及Windows服务。
1417 0
|
C# 小程序
WPF 3D变换应用
原文:WPF 3D变换应用  WPF可以提供的3D模型使我们可以轻松地创建3D实体,虽然目前来看还很有一些性能上的问题,不过对于一些简单的3D应用应该是可取的,毕竟其开发效率高,而且也容易上手。         下面给大家演示的是使用在WPF 3D上实现视角变换,通过鼠标拖动来变换观察视角,通过滚轮来放缩视距。
743 0