Bright Hub
 
Matthew Casperson's Hubfolio

Away3D Programming Tutorials - Fog

Article by Matthew Casperson (229,259 pts )
Published on Sep 20, 2009

Learn how to add a fog to an Away3D outdoor scene.

Introduction

A common method in older games to increase frame rates while rendering large outdoor scenes was to add a fog. Magic Carpet and Terminator Future Shock both come to mind. Despite the power of modern PC’s, Flash is only just catching up when it comes to utilizing the power of GPU’s, so old techniques like adding fog to levels still apply. Here we will see how to use the FogFilter class to add a fog to a terrain scene, and reduce polygon counts.

This code is based on the last tutorial in which we created an application where the camera could move over a terrain. We will add a fog to the scene by using the FogFilter class. This class progressively applies a colour to polygons, with those in the distance beyond the maximum range of the fog not being rendered at all. The image below shows how this works.

Fog

Code Documentation

ApplicationManager.as

Thankfully applying the FogFilter class is quite easy. First we create a new ColorMaterial that defines the colour of the fog. [code]

We then get a reference to the BasicRenderer created by the EngineManager. [code]

We then create an array of filters – the only one we need is the FogFilter. The minZ and maxZ properties define the distance over which the fog is applied. The subdivisions property defines how many distinct fog layers will be created. The material property is a reference to the ColorMaterial that defines the colour of the fog. [code]

This array is then supplied to the BasicRenderer.filters property. [code]

Final Words

The FogFilter class is a tried and true way to reduce polygon counts in open scenes like outdoor terrains, and it only takes a few lines of code to implement.

Go back to Away3D Tutorials

Related Files

Images

Screenshot

Search More About:

 
Follow Matthew Casperson
Receive weekly updates from Matthew Casperson
 
Bright Hub - Science & Technology Articles, Buyer's Guides, How-To Tips and Software Reviews
About Bright Hub | Contact Us | Advertise with Us | Become a Writer | RSS | Site Map | Terms of Use | Privacy Policy | Copyright Policy
©2010 Bright Hub Inc. All rights reserved. Page copy protected against web site content infringement by Copyscape