优化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.

时间: 2024-10-06 09:03:12

优化WPF 3D性能的相关文章

最优化WPF 3D性能(基于“Tier-2”硬件)

原文:最优化WPF 3D性能(基于"Tier-2"硬件) 原文地址:Maximizing WPF 3D Performance on Tier-2 Hardware 开发人员在应用程序中使用Windows Presentation Foundation来构建大量的3D控件.包含3D场景时,常常会遇到如何优化其性能的问题.WPF 3D组的几个成员提供了一个影响应用程序性能的3D类和属性的列表.当我们使用她们来优化应用程序性能时应该遵从这些建议. 本随笔假定你深刻的理解了WPF 3D AP

优化手机游戏性能,美术相关

何时选择3D(何时保留2D) 作为一个3d游戏美术,我得到的第一个关键教训就是,让所有的东西尽可能的保持低模--不要使用额外的不必要的顶点,如果你确实要让你的模型拥有精度,把它放置在贴图中.比如说,我们的建筑物都是用简单的方块创建而成,然后贴上带有质感的细节纹理. 当我们要为Vogel教授(它只在我们游戏的GUI和HUD中出现)建模时,首先尝试的是3D模型,但是最终,我们还是把它分解为像Flash中那样的多层2D平面.它运行非常流畅,看上去也更棒,事实最终的结果比用3D模型赞非常多!使用带有动画

WPF 3D 小小小小引擎 - ·WPF 3D变换应用

原文:WPF 3D 小小小小引擎 - ·WPF 3D变换应用 WPF可以提供的3D模型使我们可以轻松地创建3D实体,虽然目前来看还很有一些性能上的问题,不过对于一些简单的3D应用应该是可取的,毕竟其开发效率高,而且也容易上手. 下面给大家演示的是使用在WPF 3D上实现视角变换,通过鼠标拖动来变换观察视角,通过滚轮来放缩视距. 有关3D的基础知识可以参考MSDN文档:三维图形概述 首先创建一个3D立方体,立方体是由六个面构成(F1, F2 ....F6)其XAML代码如下: <Viewport3

WPF 3D 知识点大全以及实例

原文:WPF 3D 知识点大全以及实例 引言 现在物联网概念这么火,如果监控的信息能够实时在手机的客服端中以3D形式展示给我们,那种体验大家可以发挥自己的想象. 那生活中我们还有很多地方用到这些,如上图所示的Kinect 在医疗上的应用,当然还有体感游戏等等. 3D 用来增加视觉效果,给人以更加直观,真实的感觉. 3D如此美妙,那我们在WPF中又该从何处入手开启我们的3D编程旅程? WPF中3D开发技术的基础知识应该有以下几点: 3D开发基础知识 WPF中3D开发的基础元素(Elements)

WPF 3D变换应用

WPF可以提供的3D模型使我们可以轻松地创建3D实体,虽然目前来看还很有一些性能上的问题,不过对于一些简单的3D应用应该是可取的,毕竟其开发效率高,而且也容易上手. 下面给大家演示的是使用在WPF 3D上实现视角变换,通过鼠标拖动来变换观察视角,通过滚轮来放缩视距. 首先创建一个3D立方体,立方体是由六个面构成(F1, F2 ....F6)其XAML代码如下: <Viewport3D> <Viewport3D.Camera> <PerspectiveCamera Positi

如何快速优化手游性能问题?从UGUI优化说起

WeTest 导读 本文作者从自身多年的Unity项目UI开发及优化的经验出发,从UGUI,CPU,GPU以及unity特有资源等几个维度,介绍了unity手游性能优化的一些方法. 在之前的文章<手游内存占用过高?如何快速定位手游内存问题>中提到,Mono内存和native内存是PSS内存主要的组成部分,mono内存更多的起到内存调用的功能,因此常常成为了开发人员优化内存的起点:而在游戏的其他的进程中,同样有很多因素影响着游戏的性能表现.本文将从UGUI的优化角度,介绍unity游戏性能优化的

Tomcat 7优化前及优化后的性能对比

Tomcat 7在我们日常开发.测试.生产环境都会使用到,但对于大部分开发人员来说,对其性能还是没有多大了解.本文就对它做一次性能测试,对比优化前后的性能区别. 一.运行环境 CPU: Intel(R) Pentium(R) [email protected]  : 内存:4G,装的是32位win7,只认出3G,没有花时间去整ramdisk之类的东西: 操作系统:win7 32位: JDK:1.7.0_55 Tomcat:7.0.53 大家不要笑,公司电脑,就给配这样的,慢的要死,悲剧! 下面所

java gc的工作原理、如何优化GC的性能、如何和GC进行有效的交互

java gc的工作原理.如何优化GC的性能.如何和GC进行有效的交互 一个优秀的Java 程序员必须了解GC 的工作原理.如何优化GC的性能.如何和GC进行有效的交互,因为有一些应用程序对性能要求较高,例如嵌入式系统.实时系统等.只有全面提升内存的管理效 率,才能提高整个应用程序的性能. 本篇文章首先简单介绍GC的工作原理,然后再对GC的几个关键问题进行深入探讨,最后提出一些Java程序设计建议,从GC角度提高Java程序的性能. GC的基本原理     Java 的内存管理实际上就是对象的管

WPF 3D 常用类(1)

原文:WPF 3D 常用类(1) 几何数据相关类 Geometry3D 抽象类, 用于定义物体的几何数据, 可用于计算HitTest和BoundingBox MeshGeometry3D Geometry3D的子类, 定义网格的顶点, 三角形顶点, 法线, Texture(纹理)的座标 常用属性: Positions, TriangleIndices, Noramls, TextureCoordinates 模型相关类 (模型=几何数据+变形(位置,旋转,尺寸)+材质) Model3D 抽象类,