The Venom Deferred Renderer

Venom employs (optionally but with preference) what is referred to as a 'Deferred Renderer'. This is a method of rendering that uses multiple (deferred) passes on the source geometry, rather than a single pass, on order to perform lighting effects. While this requires multiple issuing of the geometry to the GPU, each pass is much simpler, and hence much faster, than that of a normal render. It also removes hard limits on the number of lights and shadows, so being far more scalable, both in a given game, and for future hardware.

Example Pass Summary

Depth Pass

The first pass lays down the Z buffer. On some machines this may be as simple as rewriting to the Z buffer without writing to any frame buffer. On DX9 it isn't possible to sanely get the Z Buffer as a texture source, so we write it out to a frame buffer. We take the opportunity to write it out in a linear normalised format, 0-1.0 for eye to far clip plane.

Venom also supports punch through on this pass. 'Punch through' is a nemesis to modern rendering techniques, but is still required. By laying down the punch through now, we do not have to worry about it in any more passes. This is because we can use Z EQUAL compare for all other 3D passes.

depth pass

Material pass

The second pass lays down the information for lighting and other effects. This is nominally normals as shown here, and the specular decay (hidden in the alpha channel of this image). The normals may come from vertex normals or bump maps, and stored as RGB in viewspace orientation.

Note we use Z EQUAL, with no Z update, so we only do exactly one screens worth on pixel shading (in theory). Other material information can be laid down on this pass, including material multipliers and such. Venom, however, does not do this, but provides this information in the final composite pass. Also motion blur vectors and other special effect information may be laid down.

normal pass

Lighting

This is of course the main meat of the exercise, why we are doing this in the first place!. The lighting pass is often referred to as '2D' because each light is processed as a quad (or two tris!) render, rather than the geometry of the object receiving the light. But of course the actually lighting is 3D!. Small point lights are a winner here, costing no more than particles sprites, but giving proper lighting results (like specular) instead of just polygon additive effects.

So first a full screen quad pass is made to lay down the ambient colour and clear the specular buffer. This uses dual render buffers, but if this is not possible is can easily be be done in two. In this pass the Venom engine also renders global 'rim' lights. One for horizontal lighting and another for vertical. Rim lights are used to help outline objects in other wise dark scenes. Because the normals are in view space we simply look that up for each pixel and use the X and Y components accordingly.

diffuse pass

Then for each scene light in the viewable frustum (parallel, spot etc.) a rectangle covering the extent of the light is drawn. The pixel shader extracts the normal, and uses the depth buffer with the screen position to inversely project the viewspace position. Then the standard lighting models can be used to generate the diffuse and specular colours, which are additive blended to the frame buffers. Repeat for each light. This is why there is no hard limit to the lighting, because we can simply do as many light passes as required, or GPU possible. Each light can be any lighting model we desire are well, even toon lighting or outline generation for example.

Shadows

Shadows buffers are generated the same way as for other lighting methods, by rendering depth from the camera perspective to a buffer, or a set of buffers for hierarchical resolution. They are applied, however, as textures to the corresponding light pass, where the viewspace position is projected into light space and the z value compared with the XY look up in the shadow buffer. The comparison result determines if the light calculation is done or not.

specular pass

Compositing

final imageThen it is time to stick it all together. The usually method for a deferred renderer at this stage is to render the source geometry for real as so to speak, laying down diffuse texture, and maybe some decals. Then apply lighting as a quad pass using the diffuse and specular render outputs. This method, however, requires the lighting tint values, be either a constant or a map, to have been laided down in the material pass, using at least another buffer. It is just as easy to access these values in the diffuse render pass and blend in the diffuse and specular renders at this time, which is what the Venom engine does. And as alpha channel specular maps are one of the most common forms of map, it is actually far more efficient this way, as the alpha channel of the diffuse texture is already available and doesn't require another texture stage.

Below is a short clip of the example deferred render. First the normal Direct X style render is shown, and then a deferred render. The various buffers, including the shadow buffer, are then shown.

Get the Flash Player to see this video.

Games

Universal version for iPhone,iPad and iPod. Free download of first level.

iPad HD version, with higher resolution artwork and audio.

Free mini game based on the Golem Defense universe.

Green Web Hosting! This site hosted by DreamHost.