Chapter 4. Z-Sorting

Correctly sorting 3D objects within a scene is critical to being able to draw the scene on the screen correctly. Away3D uses what is known as the painter's algorithm to draw the elements that make up the scene to the screen, and it is very easy to take this process for granted, as most of the time Away3D will draw these elements in the correct order. However, there are certain situations where it is necessary to tweak the order in which Away3D sorts the 3D objects within the scene. This chapter demonstrates one such situation, and presents the methods that are available to manually correct the sorting process.

Away3D also includes some additional renderers that can be used to automatically correct the sorting order of the 3D objects within the scene. These renderers are demonstrated, and their implications on the performance of an Away3D application are explored.

This chapter covers the following:

  • The painter's algorithm
  • How the scene is sorted
  • How to influence or force the sorting order of 3D objects
  • The additional renderers

The painter's algorithm

The painter's algorithm refers to a technique employed by many painters in which the most distant parts of a scene are painted first, with the closer parts of the scene then being progressively painted over the top. The following image, from the Wikipedia article on the subject, shows the steps that are taken to paint an outdoor scene.

The painter's algorithm

The mountains, being furthest back in the scene, are painted first. The ground and shrubs are then painted, and finally the trees are painted over both.

Z-Sorting, or depth sorting, is a technique that is used to sort the elements that make up a 3D object based on how far away they are when viewed by the camera. This then allows these 3D object elements to be rendered to the screen using the painter's algorithm, in order from those furthest back in the scene to those that are the closest.

For the most part, this algorithm works fine and there are no additional steps that need to be taken to render the 3D object elements in the correct order. However, there are situations where this algorithm fails. To understand how the painter's algorithm can fail, we first need to look at how the elements that make up a 3D object are sorted within the scene.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.35.16