优化WPF 3D性能
Maximize WPF 3D Performance
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 speed (fastest to slowest): DrawingBrush (cached) VisualBrush (cached) DrawingBrush (uncached) VisualBrush (uncached) |
|
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. |
|
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. |
|
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. |
|
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. |
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 forces all affected content to be rendered without hardware acceleration. For best performance, do not use BitmapEffect. |
Performance Impact: Medium
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 TriangleIndices. |
|
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. |
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. |
|
Typically it’s beneficial to reuse MeshGeometry3D, GeometryModel3D, Brushes, and Materials. All are multiparentable since they’re derived from Freezable. |
|
Call the Freeze method on Freezables when their properties will remain unchanged in your application. Freezing can decrease working set and increase speed. |
|
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. |
|
Don’t use BackMaterial unless you actually need to see the back faces of your GeometryModel3D. |
|
Light speed (fastest to slowest): |
|
Try to keep mesh sizes under these limits: Positions : 20,001 Point3D instances TriangleIndices : 60,003 Int32 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 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 |
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. |
|
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. |
|
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. |
|
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 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. |
优化WPF 3D性能的更多相关文章
- 最优化WPF 3D性能(基于“Tier-2”硬件)
原文:最优化WPF 3D性能(基于"Tier-2"硬件) 原文地址:Maximizing WPF 3D Performance on Tier-2 Hardware 开发人员在应用 ...
- [Unity 3D] Unity 3D 性能优化 (一)
听到过很多用Unity 3D开发游戏的程序员抱怨引擎效率太低,资源占用太高,包括我自己在以往项目的开发中也头疼过.最近终于有了空闲,可以仔细的研究一下该如何优化Unity 3D下的游戏性能.其实国外有 ...
- WPF 3D 知识点大全以及实例
引言 现在物联网概念这么火,如果监控的信息能够实时在手机的客服端中以3D形式展示给我们,那种体验大家可以发挥自己的想象. 那生活中我们还有很多地方用到这些,如上图所示的Kinect 在医疗上的应用,当 ...
- WPF 3D 小小小小引擎 - ·WPF 3D变换应用
原文:WPF 3D 小小小小引擎 - ·WPF 3D变换应用 WPF可以提供的3D模型使我们可以轻松地创建3D实体,虽然目前来看还很有一些性能上的问题,不过对于一些简单的3D应用应该是可取的,毕竟其开 ...
- 【原创】构建高性能ASP.NET站点 第七章 如何解决内存的问题(前中篇)—托管资源优化—监测CLR性能
原文:[原创]构建高性能ASP.NET站点 第七章 如何解决内存的问题(前中篇)-托管资源优化-监测CLR性能 构建高性能ASP.NET站点 第七章 如何解决内存的问题(前中篇)—托管资源优化—监测C ...
- 浅谈Unity的渲染优化(1): 性能分析和瓶颈判断(上篇)
http://www.taidous.com/article-667-1.html 前言 首先,这个系列文章做个大致的介绍,题目"浅谈Unity",因为公司和国内大部分3D手游开发 ...
- WPF 3D变换应用
WPF可以提供的3D模型使我们可以轻松地创建3D实体,虽然目前来看还很有一些性能上的问题,不过对于一些简单的3D应用应该是可取的,毕竟其开发效率高,而且也容易上手. 下面给大家演示的是使用在WPF 3 ...
- WPF 3D 模型旋转
原文:WPF 3D 模型旋转 WPF 是 Microsoft 在 Framework3.0 中支持的一种技术,它能作出很绚丽的界面,同时它也支持3D的操作.在3D操作主要包括平移(Translate) ...
- 如何快速优化手游性能问题?从UGUI优化说起
WeTest 导读 本文作者从自身多年的Unity项目UI开发及优化的经验出发,从UGUI,CPU,GPU以及unity特有资源等几个维度,介绍了unity手游性能优化的一些方法. 在之前的文 ...
随机推荐
- iOS获取状态栏和导航栏尺寸(宽度和高度)
iPhone开发当中,有时需要获取状态栏和导航栏高度.宽度信息,方便布局其他控件.下面介绍一下如何获取这些信息: // 状态栏(statusbar) CGRect rectStatus = [[UIA ...
- NYOJ题目817英文藏头诗
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtEAAAKXCAIAAADLqoEhAAAgAElEQVR4nO3dO1LrzNbG8W8S5AyE2D
- js 倒计时点击和当前时间
<input id="btn" type="submit" value="确定" disabled="disabled&qu ...
- Linq学习笔记---Linq to Xml操作
LINQ to XML的成员, 属性列表: 属性 说明 Document 获取此 XObject 的 XDocument EmptySequence 获取空的元素集合 FirstAttribut ...
- MVC – 9.mvc整体请求流程
1.请求管道 2~5微软自己的验证,我们一般不用. 在全局配置文件中-已经配置一个路由过滤器-为第7个事件注册了路由方法 1.在application_start中向静态路由表注册了路由数据,在管 ...
- Java集合源码学习(二)ArrayList分析
>>关于ArrayList ArrayList直接继承AbstractList,实现了List. RandomAccess.Cloneable.Serializable接口,为什么叫&qu ...
- Linux常用的日志分析命令与工具
>>基础命令 操作 命令 说明 查看文件的内容 cat -n access.log -n显示行号 分页显示文件 more access.log Enter下一行,空格下一页,F下一屏,B上 ...
- 缓慢变化维 (Slowly changing dimension)
维度建模的数据仓库中,有一个概念叫Slowly Changing Dimensions,中文一般翻译成"缓慢变化维",经常被简写为SCD.缓慢变化维的提出是因为在现实世 ...
- 攻城狮在路上(叁)Linux(二十二)--- linux磁盘挂载与卸载 mount umount
挂载就是将文件系统与目录结合的操作.挂载点就是目录,该目录就是进入分区或文件系统的入口. 一.挂载前的注意事项: 1.单一文件系统不应该被重复挂载在不同的挂载点中. 2.单一目录不应该重复挂载多个文件 ...
- Linux發送郵件
1.直接使用shell當編輯器 [root@phburdb1 mail]# mail -s "Hello World" juncai.chen@innolux.comHello j ...