Wednesday, November 18, 2009

Detail Shaders

When attempting to add detail to a 3D model, one option is to simply add more polygons and shape them, but this can drastically lower the framerate of your application. If your application already takes advantage of per-pixel lighting, then you can utilize shaders to give the appearance of detail without actually changing the surface of the mesh. If your application does not use pixel shaders, then you should add support for them.

Take a simple sphere for example. Through the pixel shader, a simple texture can easily be applied to the plane, and both diffuse and specularity lighting can also be implemented.

The simplest of the detail shaders is normal mapping. A key element in this is a normal map, which is an image that stores normal data.

The normal mapping effect is simply done by setting the x normal to the r value, y to g, and z to b. This distorts the orientaion of the pixel, resulting in shading changes that gives the appearance of small crevices and bumps.

This effect, while decent, still does not give a full 3D effect. The next step up is parallax occlusion mapping.

The stones in the above image are actually on a flat plane that appears to be bumpy through a clever use of the parallax effect. The parallax effect involves offsetting the texture based of the viewing angle, thus distorting the image. Occlusion testing is done by casting a ray into the psuedo-volume.

Using these pixel shader techniques, detail can be added to a model without having to change the geometry of the model, and without affecting the frame rate. These techniques, especially normal mapping are widely used in modern games, and parallax mapping is now starting to be seen. These techniques can optimize your game, as well as make it look better.

No comments:

Post a Comment