Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Papervision3D Essentials

You're reading from  Papervision3D Essentials

Product type Book
Published in Sep 2009
Publisher Packt
ISBN-13 9781847195722
Pages 428 pages
Edition 1st Edition
Languages

Table of Contents (18) Chapters

Papervision3D Essentials
Credits
About the Authors
About the Reviewers
1. Preface
1. Setting Up 2. Building Your First Application 3. Primitives 4. Materials 5. Cameras 6. Moving Things Around 7. Shading 8. External Models 9. Z-Sorting 10. Particles 11. Filters and Effects 12. 3D Vector Drawing and Text 13. Optimizing Performance

Chapter 13. Optimizing Performance

In the final chapter of this book, we will have a look at how to make your Papervision3D applications perform better. Papervision3D is a cutting edge technology, which may ask for a lot of the CPU to render all the content. This chapter discusses how to reduce the hit on the CPU, so your applications will run faster.

Some optimizations have already been mentioned in previous chapters. We will summarize them here and discuss more performance optimizations.

This chapter will cover the following topics:

  • Measuring performance

  • Basic optimization strategies

  • Optimizing materials

  • Optimizing objects

  • Optimizing shading

  • Optimizing rendering

Before we take a look at the different optimization techniques, we first need to define what performance is in a Papervision3D context and how we can measure it.

Measuring performance

When we speak of performance in a Papervision3D context, we mean everything that relates to how fast Papervision3D can render a scene. Each do3D that is placed...

Measuring performance


When we speak of performance in a Papervision3D context, we mean everything that relates to how fast Papervision3D can render a scene. Each do3D that is placed somewhere in a scene needs to be calculated. Even when objects are not within the view frustum of a camera, they have a small footprint on the CPU. During each render, Papervsion3D has to decide which triangles are within the view frustum and which triangles are not. Camera-facing surfaces that are placed inside the view frustum have the highest CPU footprint. They need to be projected and then drawn on the screen. Drawing the faces with materials is the most CPU-intensive task.

In order to optimize performance, we first need to know how to measure it. One way to do this is looking at the Activity Monitor on the Mac, or at the processes tab in the Task Manager on Windows. In both utilities, you can look for Flash or the browser used for publishing with Flex Builder or Flash Builder. However, most of the time...

Basic optimization strategies


When you optimize your application, many factors should be taken into consideration. Performance optimization isn't solely related to optimizing the way you use Papervision3D. In the end, it's all about optimizing performance in Flash. Let's first examine some optimization techniques that are not specific to Papervision3D.

Stage quality

Changing the stage quality to low is the easiest way to gain a lot of performance. This might sound odd, as you want to create applications that look good. But decreasing stage quality doesn't necessarily mean that you decrease the quality of what you see on screen. First, take a look at the quality settings that you can set and the effect this will have on your application:

  • StageQuality.BEST: Graphics are anti-aliased using a 4 by 4 pixel grid. This always smoothens bitmaps.

  • StageQuality.HIGH : Graphics are anti-aliased using a 4 by 4 pixel grid. This smoothes out bitmaps if the movie is static. By default, the quality of the...

Optimizing materials


When materials are not used optimally, they can give Papervision3D a hard time rendering them. In Chapter 4 about materials, you have already seen some techniques to keep them as lightweight as possible. In this section, we will discuss these techniques one by one and introduce more optimization strategies.

Transparency

Transparency can set on instances of MovieMaterial or classes that inherit from MovieMaterial. By default, transparency of movie materials is turned off. Whenever you can, you should keep it this way. Transparent images are 32-bit and non-transparent images are 24-bit. The latter are much faster to render.

Tiled

Always try setting the tiled property of a material to true. Depending on your situation this will slightly increase the performance due to the presence of a performance bug in the Flash player.

Power of two textures

Power of two textures enable mipmapping, which allows you to set smoothing on materials to true without losing any performance. Chapter...

Optimizing objects


The more complex your objects are, the more triangles need to be drawn. It's been said before that you should always try to keep the triangle count as low as possible. When modeling with external tools, it's better to make a very low poly model first and then add more polygons or triangles afterwards if necessary. Doing it vice versa, by removing triangles from an advanced model, will be a lot more work.

But there are more techniques available to optimize objects. We will have a look at these in the following sections.

Remove objects that are behind other objects

It sounds easy: Just remove your objects when you know they won't be visible. This does not refer to objects that are positioned outside the camera's view frustum or back facing surfaces of 3D objects, as Papervision3D will detect these automatically for us. The title of this section refers to objects that are located in the view frustum, but are positioned behind other objects from certain points of view.

Because...

Optimizing shading


Real-time shading is an enormous performance hit on your CPU. Real-time shading should always be limited to just a few objects, especially when you apply Phong shading. Wherever possible, you should use baked textures that contain the shading information instead. However, when your project requires real-time bitmap-based shading, a small performance optimization is possible.

A good trick is to add the object that needs to be shaded to the scene twice. The first object has the regular bitmap material applied to it, which is the material you want to be shaded. The other object uses a color-based shader as material, for instance PhongMaterial. The ambient color of this shader should be black to make this trick work. Each object should be added to a sublayer of an index sorted viewport layer. This renders the second object with a color based shader as the top layer. By using the BlendMode.MULTIPLY as the blend mode of the top layer, you can create an illusion of shading on...

Optimizing rendering


When a new render is called for every enter frame, a new render cycle starts. Within this cycle, Papervision3D will run through the process of clipping, culling, z-sorting triangles, projecting vertices, and drawing transformed materials. In other words, everything that results in an image on our screen has been a part of the rendering pipeline. The best way to increase performance is not to render at all. Of course this isn't an option. However, with some creativity you can also win performance in the rendering process.

Only render when you need to

As long as the 3D scene is static because the user is interacting with other elements in your application, you could pause the rendering process. This will give back some performance to the Flash player, which can be of benefit to other elements in your application and the experience of the user.

When working with the BasicView class, the renderer can be stopped by calling the stopRendering() method. As soon as you want to...

Summary


In this final chapter we discussed a number of ideas on how to get the best possible performance, giving you the tool to make your applications perform as good as possible.

We have examined:

  • What performance is and how we can measure it

  • How to change the stage quality for faster rendering

  • Basic performance optimizations for Flash, materials, and objects

  • What power of two textures are and how they can help increase performance for smooth rendering

  • Caching snapshots of animated materials

  • How to use level of detail in your applications

  • How to fake shading by using viewport layers

  • What selective rendering is and how to use it

  • How to scale a bitmap version of the viewport for faster rendering special objects

Performance optimizations are definitely not limited to what has been discussed here. Optimizing performance requires creative thinking in order to come up with ideas on how to win CPU power.

lock icon The rest of the chapter is locked
arrow left Previous Chapter
You have been reading a chapter from
Papervision3D Essentials
Published in: Sep 2009 Publisher: Packt ISBN-13: 9781847195722
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}