ImageVerifierCode 换一换
格式:PPT , 页数:56 ,大小:765.23KB ,
资源ID:373203      下载积分:2000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-373203.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Advanced 3D Techniques with WPF.ppt)为本站会员(hopesteam270)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

Advanced 3D Techniques with WPF.ppt

1、Advanced 3D Techniques with WPF,David Teitlebaum - Program Manager Jordan Parker - Developer Kurt Berglund - Developer Microsoft Corporation,Talk Outline,Introduction to WPF3D What do you need to do to see something? Interactive 2D on 3D Make VisualBrush work like you expected it to Performance Tips

2、 Learn how to avoid common mistakes,Jordan Parker,basics,The Name Game Warmup Time,Pattern: FooBar is a Bar with a Foo Examples: ModelVisual3D is a Visual3D with a Model3D GeometryModel3D is a Model3D with a Geometry3D MeshGeometry3D is a Geometry3D with a mesh ScaleTransform3D is a Transform3D with

3、 a scale And so on (generally) DrawingImage vs. ImageDrawing anyone?,The Near Minimal Scene,Lets do a simple 3D video example step-by-step,Our Coordinate System,Right-handed Notice that +Y is up opposite of 2D!,(Image from http:/www.willamette.edu/gorr/),MeshGeometry3D,Specifies a mesh of triangles

4、Positions: Triangle vertices TriangleIndices: Optional indices Normals: Per-vertex orientation used in lighting. Generated for you. TextureCoordinates: Describes the 2D Brush mapping. NOT generated for you. Not needed for SolidColorBrushes. Triangle vertices should be given in CCW order,TriangleIndi

5、ces,If specified:positionsindices0 positionsindices1 texcoordsindices0 texcoordsindices1 normalsindices0 normalsindices1 If not specified:positions0 positions1 texcoords0 texcoords1 normals0 normals1 ,TextureCoordinates,(image from you dont specify normals, we generate them by averaging the “real”

6、normals of the triangles that share the vertex. This gives a smooth appearance If you duplicate a vertex, it will end up with different normals each time. Triangle specification matters! If you specify too many, we throw out the extras If you specify too few, we generate the rest,Normals Cylinder Ca

7、p Generation Example,Specifying the Plane,(-1,1,0) 0 (0,0),(-1,-1,0) 1 (0,1),(1,-1,0) 2 (1,1),(1,1,0) 3 (1,0),Key:posidxtc,Looking down -Z,Mesh XAML,Well let WPF compute the normalsIn general, youll be exporting a mesh to XAML from a tool,Materials,Reflection/absorption of light EmissiveMaterial: Su

8、rface appears to give off light SpecularMaterial: Shine DiffuseMaterial: Soft scattering Takes a Brush for the base color Combine them with MaterialGroup When in doubt, use DiffuseMaterial,Material Examples,Video DiffuseMaterial XAML,(In code, you could use a DrawingBrush w/ a VideoDrawing instead),

9、GeometryModel3D,Combines the Material and the Geometry3D Allows you to specify a transform,(the plane mesh)(the video material),Lights,Not unlike reality, without light you cant see anything* AmbientLight: Equal contribution everywhere DirectionalLight: The sun PointLight: Light bulb SpotLight: Self

10、 explanatory Lights are Model3Ds and thus have transforms Well use an AmbientLight in our example for simplicity,* Except EmissiveMaterials,Model3DGroup,(the ambient light)(the plane GeometryModel3D) ,Group multiple Model3Ds together Is a Model3D,Visual3D,3D analog of the 2D Visual class You need at

11、 least one just like you need at least one Visual in 2D (FrameworkElements are Visuals) To draw a Model3D, use ModelVisual3D,(the Model3DGroup),Cameras,Determine what part of the scene you see and project 3D onto a 2D plane OrthographicCamera: parallel lines stay parallel PerspectiveCamera: perspect

12、ive foreshortening MatrixCamera: Specify your own projection,Viewport3D,The bridge between the 2D and 3D world It is a FrameworkElement Takes a Camera and the root of your Visual3D tree,(the PerspectiveCamera)(the ModelVisual3D) ,3D Video,demo,Kurt Burglund,Interactive 2D on 3D,Flickr Photo Browser,

13、demo,Using Interactive 2D on 3D,Interactive3DDecorator Goes around the Viewport3D you want to make interactive InteractiveVisual3D Subclass of ModelVisual3D used to add interactive 2D on 3D Has DependencyProperties Geometry, Visual, and Material used to set the appearance of the object,Interactive 2

14、D on 3D Example - Before,Interactive 2D on 3D Example - After,How it works,Hidden visual layer placed above Viewport3D 2D on 3D that the mouse is over is placed in hidden layer Layer moved so that the point the mouse is over in 3D is the same as the point the mouse is over in the hidden layer,Hit Te

15、sting,public void HitTest(object sender, System.Windows.Input.MouseButtonEventArgs args) Point mouseposition = args.GetPosition(myViewport); PointHitTestParameters pointparams = new PointHitTestParameters(mouseposition); VisualTreeHelper.HitTest(myViewport, null, HTResult, pointparams); public HitTe

16、stResultBehavior HTResult(System.Windows.Media.HitTestResult rawresult) RayHitTestResult rayResult = rawresult as RayHitTestResult; if (rayResult != null) RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as RayMeshGeometry3DHitTestResult;if (rayMeshResult != null) return HitTestResultBehavio

17、r.Continue; ,Hit Testing Return Results,RayMeshGeometry3DHitTestResult contains all the information about the hit test Point, Mesh, Model, Visual3D hit Vertex indices of triangle hit Barycentric coordinates for point of intersection: can be used to compute texture coordinate of intersection,Barycent

18、ric Coordinates,Weighted sum of triangles vertices p = VertexWeight1 * v1 + VertexWeight2 * v2 + VertexWeight3 * v3 Can be extended to texture coordinates uv = VertexWeight1 * uv1 + VertexWeight2 * uv2 + VertexWeight3 * uv3 Use to figure out where on texture you are,Filling the Viewport3D,Say we wan

19、t to fill the viewport with a 3D rectangle Viewport3D has width, height, and camera is at origin looking down negative z axis,Horizontal FieldOfView,-z,Databinding,Can bind any DependencyProperty,David Teitlebaum,performance,WPF3D Performance Do more with less,Performance must be a priority througho

20、ut app construction Test early, test often Do not assume you can easily fix performance problems after your application is functionally complete Test on the hardware you care about Old Desktops, New Desktops, Laptops Most Dev machines are not “Old Desktops”,Potential Bottlenecks,CPU Easy to measure

21、with task manager, profilers, etc. Many potential causes of CPU load GPU Hard to measure there are few public tools to measure GPU load Can degrade frame rates without taxing CPU Few potential causes typically the result of insufficient fill rate on the GPU or background video decode GPUs are optimi

22、zed for video games with few state changes,WPF Hardware Tiers Know your limits,Coarse indicator of maximum machine capabilities Queryable via: (RenderCapability.Tier 16) Tier resides in the high word so dont forget the shift! Indicates static capabilities An upper bound on what can be expected Does

23、not account for dynamically consumed machine resources Value is read only (unfortunately! ),WPF Hardware Tiers Continued,Useful Performance Tools,Performance tools WPFPerf.exe Profilers Microsoft F1 AMD Code Analyst Intel Vtune,WPFPerf,demo,Best Practices Common Pitfalls,#1 Brush Selection Persisten

24、ce vs. Nonpersistence of realizations Intermediate Render Targets Texture memory swizzling Texture size Smaller is better Watch out for automatic texture sizing RenderTargetBitmap - best of both worlds?,Best Practices Common Pitfalls,#1 Continued - RenderTargetBitmapRectangle r = new Rectangle(); r.

25、Width = 50; r.Height = 50; r.Fill = new LinearGradientBrush(Colors.CornflowerBlue, Colors.PeachPuff, 13.37);r.Measure(new Size(50, 50); r.Arrange(new Rect(new Size(50, 50); r.UpdateLayout();RenderTargetBitmap rtb = new RenderTargetBitmap(int)r.ActualWidth, (int)r.ActualHeight, 96.0, 96.0, PixelForma

26、ts.Pbgra32); rtb.Render(r);,Best Practices Common Pitfalls,#1 Continued - Brush Speed on Tier-2 Hardware in 3D ONLY,Best Practices Common Pitfalls,#2 Disable Viewport3D.ClipToBounds WPF uses complex antialised clipping When Viewport3D.ClipToBounds = False, 3D content can exceed 2D region of Viewport

27、3D Implementation of clipping is slow enough that it should be disabled when it is not needed,Best Practices Common Pitfalls,#3 Disable Viewport3D.IsHitTestVisible WPF3D performs mouse-over hit testing on the CPU Mouse cursor is projected into object space and intersected with GeometryModel3Ds axis-

28、aligned bounding box If bounding box is intersected, ray of projected mouse cursor must be intersection-tested against every triangle in GeometryModel3D, all on the CPU If you dont need hit testing, disable it.,Best Practices Common Pitfalls,#4 GeometryModel3D Coalescence Each Model3D requires a cha

29、nge of GPU state Each requires the projection of its axis-aligned bounding box to device coordinates A Few complex GeometryModel3Ds is vastly preferable to many simple GeometryModel3Ds,Performance Impact of Model Coalescence,demo,Best Practices Common Pitfalls,#5 Minimize Mesh Animations They do not

30、 scale well due to platform architecture Entire Collections are remarshalled rather than collection deltas Disconnect meshes from 3D scene before modifying to minimize change notifications Keep animated meshes small (a few thousand vertices at the most),Best Practices Common Pitfalls,#6 Disable 3D A

31、ntialiasing On Vista, WPF3D will try to render with 4 samples/pixel multisampling On XP, WPF3D will not try to multisample To prevent WPF3D from attempting to render with multisampling on Vista, add the attached property RenderOptions.EdgeMode=“Aliased” to your Viewport3D,Best Practices Common Pitfa

32、lls,#7 Text in 3D Text is expensive Glyphs are abstractly defined by Beziers Glyphs are generated and cached according to scale Small glyphs Bitmaps / Large glyphs - Polygons scale changes cause glyph cache invalidation, glyph regeneration, and glyph cache repopulation RenderTargetBitmap / ImageBrus

33、h is strongly recommended for static text,Best Practices Common Pitfalls,#8 Caching of VisualBrush and DrawingBrush Attached Property - RenderOptions.CachingHint Use when ImageBrush is not sufficient Still slower than ImageBrush due to less aggressive texture memory swizzling on D3Ds RenderTargetTex

34、tures Frequency of cache regeneration can be controlled by RenderOptions.CacheInvalidationThresholdMinimum and RenderOptions.CacheInvalidationThresholdMaximum,Best Practices Common Pitfalls,#9 BitmapEffects Should only be used on static 3D content Implemented on the CPU Forces affected content to al

35、so be rendered on the CPU Great for static content, otherwise dont use them,Performance Impact of BitmapEffects,demo,Resources,WPF3D http:/ http:/ http:/ http:/ WPF Perf http:/ http:/ Ask Questions http:/ news:/microsoft.public.windows.developer.winfx.avalon Books Windows Presentation Foundation Unl

36、eashed Petzolds book coming out Summer 2007, 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only

37、and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.,

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1