In Chapter 12, Filters and Postprocessing Effects, we saw how the FogFilter
class could be used to add a fog effect to the scene. It was also noted that those 3D objects that were behind the last layer of fog were not rendered at all, providing an increase in performance.
Two additional filters are also included in the away3d.core.filter
package: MaxPolyFilter
and ZDepthFilter
. Neither adds a visual effect to the scene, but they can both be used to reduce the number of mesh elements that get drawn to the screen.
Both filters can be applied like the FogFilter
class from Chapter 12, Filters and Postprocessing Effects, by assigning them to the filters
property available on both the BasicRenderer
and QuadrantRenderer
classes. Or they can be passed into either the BasicRenderer
or QuadrantRenderer
constructors, with the resulting render class then assigned to the renderer
property from the View3D
class.
The ZDepthFilter
class defines a maximum z depth for mesh elements. Those that lie beyond that maximum depth are not drawn to the screen. This provides the same performance benefits as the FogFilter
class, but without the fog effect.
The ZDepthFilter
constructor takes one parameter, maxZ
, which defines the distance from the camera after which mesh elements are culled. In the following example, a new instance of the ZDepthFilter
class has been created that will cull all mesh elements that are more than 200 units away from the camera.
var zDepthFilter:ZDepthFilter = new ZDepthFilter(200); view.renderer = new BasicRenderer(zDepthFilter);
In Away3D 3.6, there is a bug in the ZDepthFilter
class that prevents it from working correctly. By using the FrustumClipping
class, from the away3d.core.clip
package, you can achieve the same visual effect as the ZDepthFilter
class, but there is no performance benefit.
view.clipping = new FrustumClipping({maxZ:200});
The MaxPolyFilter
filter will only allow a set number of mesh elements to be drawn to the screen. It does this by retaining only the specified number of mesh elements from the collection that would be drawn to the screen. Since this collection is sorted by depth, this has the effect of discarding those mesh elements that represented the furthest 3D objects in the scene.
The ZDepthFilter
constructor takes one parameter, maxP
, which defines how many mesh elements will be rendered. The following code creates a new instance of the MaxPolyFilter
class that will draw only the closest 500 mesh elements.
var maxPolyFilter:MaxPolyFilter = new MaxPolyFilter(500); view.renderer = new BasicRenderer(maxPolyFilter);