Submitted by , posted on 29 April 2002

Image Description, by

I thought I'd share a tech demo I've been working on for a couple of days to dynamically create a 2D aura or Halo around an arbitrary model in real-time. So as the model rotates or if the camera viewpoint changes, the profile of the model is updated and the aura maintains the correct outline. It's a simple effect, and although I'm sure I can't be the first to come up with it, I haven't actually seen it used in other demos or games.

The demo was created with Director, and can be viewed online via Shockwave here

It needs SW8.5, a plugin freely available for browsers, and there are plenty more demos to justify downloading it ;)

I came up with the idea whilst reading through NeHe's tutorial 28 on shadow mapping for obtaining the visible edges of a model. This is a quick overview of the method.

Pre-processing: Loop through every triangle/face in the model to have the Aura applied to and build an array of its neighbours. For each frame use the array to check each face against its neighbours. A face is checked if it faces the camera, and an edge is stored for each neighbour that is not visible to the camera. An edge is defined by two vertices taken from the original face. The completed edge list defines the 2D profile of the model (from camera POV) and is considered the inner outline. A copy of the edge list vertices is made and then scaled via the Aura_strength value (around 1.2 is good). This second edgelist is the outer outline. Simply connect the dots, or in this case the edge vertices from inner to outer, first forming quads and then splitting them into triangles. Finally build the new Aura mesh and apply an alpha channel texture to achieve the glow. Draw the Aura without writing to the zbuffer, so the model can be drawn afterwards and always over the top of it. This allows for more complex geometry and non-convex models, without the aura cutting into it.

The method is not perfect; there are a couple of issues with graphical glitches. The first is unavoidable, although it could be minimised and that is Aura popping, which happens when an edge suddenly appears or disappears from the profile as the model rotates. Secondly if two alpha textured polygons of the aura overlap they cause a heightened intensity of glow within that area. Perhaps this issue could be solved through use of a stencil buffer? (Not that we have access to one from within Director). Ultimately the method works best for low values of aura_strength, at higher values overlap becomes much more visible.

Talking about stencil buffers, I have wondered if there was an easier way to produce a similar effect. I have seen Halo's done with a stencil buffer, but the halo is just a flat colour, with no graduation, failing to give the nice glow of my method. I guess with 8 bit stencils it should be possible in multiple passes to produce a graduated effect, but presumably this would be to costly in terms of performance to implement currently.

Image of the Day Gallery



Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.