博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
优化WPF 3D性能
阅读量:6757 次
发布时间:2019-06-26

本文共 6364 字,大约阅读时间需要 21 分钟。

原文:

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 .

 
 

Property

Recommendation

Brush speed (fastest to slowest):

 (cached)

 (cached)

 (uncached)

 (uncached)

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

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

Create different models only when they require different Materials or Transforms. Otherwise, try to coalesce many  instances with the same Materials and Transforms into a few larger  and  instances.

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  by setting the attached property  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  or ) can be slow. Try to use images of the text instead (via ) unless the text will change.

If you must use a  or a  in a 3D scene because the brush’s content is not static, try caching the brush (setting the attached property  to Cache). Set the minimum and maximum scale invalidation thresholds (with the attached properties  and ) so that the cached brushes won’t be regenerated too frequently, while still maintaining your desired level of quality. By default,  and  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.

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

 
 

Property

Recommendation

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 .

Try to minimize texture sizes when you have explicit control over the size (when you’re using a  and/or an ). 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  or ) instead of creating a separate translucent by setting Viewport3D.Opacity to a value less than 1.

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

Typically it’s beneficial to reuse , , Brushes, and Materials. All are multiparentable since they’re derived from Freezable.

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

Use  instead of  or  when the content of the brush will not change. 2D content can be converted to an  via  and then used in an .

Don’t use  unless you actually need to see the back faces of your .

Light speed (fastest to slowest):

Try to keep mesh sizes under these limits:

 : 20,001  instances

 : 60,003  instances

Material speed (fastest to slowest):

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.

Each  in a  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 .

 
 

Property

Recommendation

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

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 110 objects, 70  objects, or 40  objects.

Separate moving objects from static objects by putting them in separate  instances. ModelVisual3D is "heavier" than  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.

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.

To minimize the construction time of large collections in Windows Presentation Foundation (WPF), such as a MeshGeometry3D’s , , , and, pre-size the collections before value population. If possible, pass the collections’ constructors prepopulated data structures such as arrays or Lists.

转载地址:http://cjweo.baihongyu.com/

你可能感兴趣的文章
android 调试源码
查看>>
k-means clustering - Wikipedia, the free encyclopedia
查看>>
三星S6D1121主控彩屏(240*320*18bit,262K)图形设备接口(GDI)实现
查看>>
head first java 01 ( 1 ~ 3 章 )
查看>>
Superhero.js – 构建大型 JavaScript 应用程序的最佳资源
查看>>
什么是UAT测试?
查看>>
FireDAC 下的 Sqlite [8] - 自定义函数
查看>>
Android 驱动测试程序H-M-S <2>
查看>>
Swift语言指南(七)--语言基础之布尔值和类型别名
查看>>
Hadoop 安装记录
查看>>
hdu 5206 Four Inages Strategy 判断是否是正方形
查看>>
Linq中使用Left Join
查看>>
HDFS Safemode问题
查看>>
GDI编程小结
查看>>
(C#基础) byte[] 之初始化, 赋值,转换。(转)
查看>>
mysql设置指定ip远程访问连接实例
查看>>
从js的repeat方法谈js字符串与数组的扩展方法
查看>>
IIS中添加MIME类型
查看>>
Restful风格wcf调用2——增删改查
查看>>
Kettle定时执行(ETL工具)【转】
查看>>