Over the past few years, developers have created some amazing projects using 3D in Flash. 3D engines such as Papervision3D, Away3D, and Alternativa3D and all of the great applications that have been made with these engines demonstrate the strong demand for real-time 3D rendering in Flash.
Previously, Flash 3D rendering was performed without using 3D hardware acceleration. In fact, all 3D rendering in Flash Player before version 11 was accomplished using the software mode that relied on the CPU for rendering. Software mode is slow and cannot be used to render detailed 3D scenes. Up until now, it hasn't been possible to integrate advanced graphic effects that we’re all used to seeing in today’s 3D games.
With the release of Flash Player 11, new opportunities are now available. Developers can leverage 3D hardware acceleration rather than relying on the computer’s CPU to do the rendering. The new mode of rendering enables Flash 3D content to be handled by a secondary processor, part of the video hardware of a computer, called the Graphics Processing Unit (GPU). GPU is a piece of hardware that is totally dedicated to rendering objects in 3D.
Working with Stage3D
Stage3D is the new Flash API that Adobe recently released. It is dedicated to real-time 3D rendering. With Stage3D, you can take full advantage of the hardware accelerated capabilities of the user's computer GPU directly from Flash.
The release of Stage3D is a huge event for Flash developers. Being able to use 3D acceleration in Flash opens up many possibilities for Flash games and Flash applications that were previously not possible.
If you think back to the time when 3D hardware acceleration initially came out for native platforms, you'll remember how it changed the world of 3D coding forever. The quality and complexity of games increased exponentially. Hardware acceleration has vastly improved the capabilities of 3D games, by enabling the lightning-fast rendering required for complex models, realistic effects, and responsive game play.
With its 98%+ of market penetration, Flash Player is ubiquitous. Games and applications developed in Flash become instantly available for use on almost any computer in the world. Users can enter the game's URL in a browser and begin playing it immediately. Besides Flash Player, which is already installed on most browsers, the user doesn't need to install anything: special runtime libraries, OS versions, or special hardware are not required.
The ubiquity of Flash Player and 3D hardware acceleration is a powerful combination that might transform the online gaming forever, similar to the rapid evolution of computer games after the introduction of 3D-accelerated hardware.
Imagine the Flash websites common today: 2D experiences with content. And then consider how they may change in the near future, as a 3D experience of a 3D world, where users can immerse themselves in the environment as they explore it. In the future, most websites may resemble a video game with interactive 3D objects, rather than providing a simple 2D experience.
That's what Stage3D is all about. It's about leveraging the 3D hardware that is present in any modern computer in order to build 3D games and 3D interactive websites that can easily be experienced using every single computer connected to the Internet.
Working with 3D hardware acceleration
In this section, you'll get an overview of rendering Flash content with 3D hardware acceleration.
3D hardware acceleration leverages a very advanced piece of hardware, the GPU, which is
included in all modern computers. GPU is totally dedicated to the task of rendering content in 3D.
Using this setup, the software, your Flash application, will limit itself to just specifying the definition of a 3D scene. It passes the 3D scene data to the GPU hardware so that the hardware can process the data and render the scene. This process is much faster than using the CPU to render 3D content with software mode rendering.
Take a moment to compare the differences between software mode rendering and hardware mode rendering.
Generally speaking, a 3D scene is defined as a group of 3D geometries (meshes). Each geometry is specified as a set of triangles, and each triangle, in turn, is comprised of a set of vertices. So, defining a 3D scene simply means to define a set of vertices, and eventually add some related rendering information—such as textures or vertex colors.
When you worked with the older software mode, a 3D engine such as Away3D would receive this stream of vertices. It would calculate the screen positions of the triangles and then prompt Flash Player to natively render those triangles one by one, through a series of "fill" draw operations.
This process, although smartly coded within the engine, was extremely slow. In some cases the rendering result wasn't particularly accurate. The content was rendered per triangle, instead of per pixel. This caused depth sorting errors. Triangles would sometimes render out of place, at the wrong depth.
In order to compare statistics, the software mode in Flash Player 10 typically renders scenes with a maximum of 4,000 triangles to maintain acceptable performance.
Now consider the possibilities with Stage3D. Using 3D hardware acceleration, the software simply defines the geometries and then passes them on to the computer's GPU. The geometries are uploaded to the GPU memory, which is a piece of memory that sits on the video hardware that is dedicated for use by the GPU. The GPU receives the data and processes it, completely taking over the job of rendering the 3D content.
The software works much more efficiently because it is only required to pass the parameters needed for rendering to the GPU. For example, the software specifies where the eye point (the 3D camera) is located in the 3D scene, sets the location of lights in the scene, and other details about the 3D objects and effects in the scene.
The GPU receives all this data. It starts by analyzing the defined vertices and begins rendering the scene triangle by triangle. The GPU produces the final rendered image that is ready for display on the screen.
The GPU rendering process is much faster than software mode. The GPU is designed to focus on a very specific task: it simply calculates the vertices and renders triangles. That's it.
Since the hardware of the GPU is extremely specialized for this very specific task, the hardware accelerated 3D rendering process is extremely efficient.
In contrast, the CPU is a generic processor. It not optimized for the specific task of rendering triangles. As a result, it is much less efficient at the rendering operation, as you may have experienced when rendering Flash 3D content using software mode.
To compare the numbers, using hardware acceleration it’s not uncommon to render scenes that contain more than a million of triangles. A significant improvement over the 4,000 triangles rendered in software mode.
Analyzing the 3D rendering pipeline