While Brian has been toiling away at the bolts and gears under the hood of our game to implement our networking system, I have been working on getting our environments polished up and in the game. While I was playing around with Ogre's fixed-function environment mapping features, I noticed a method of environment mapping listed that I had never tried out before, cubic_normal mapping. According to the manual: " Generates 3D texture coordinates containing the camera space normal vector from the normal information held in the vertex data." While that is pretty self explanatory, let me explain to you how it is different from most of the environment mapping utilized by Zero Gear. The environment mapping I use a lot to make things look shiny, simulates a cube sitting around whatever it is applied to. I basically use a black cube with a few white highlights around the top panel of the cube, and when applied to an object, a white highlight appears reflected as from the top of the scene. In this method, the cube is static. However, using this cubic_normal method, the cube that objects are reflecting is locked to the camera, so wherever you move around in the scene, the cube moves with you. An easy way to look at it, is one method the cube is a room you stand in, and the other method the cube is a box you wear on your head that moves around with you. This is significant becuase I can easily use this second method to simulate rim lighting. Since the environment map is locked to your view, it will always be facing in one direction, and you would just need to build a cube map that simulates a halo of light on all sides. Here is the cubemap that I came up with:
Here is a screenshot of what this environment map looks like applied to an object, with both the cubic_normal and cubic_reflection methods:
The environment map on the left remains relative to the model, and using the method on the right, remains relative to the camera.
This method has some advantages and some drawbacks.
- It's fixed-function which means it is fast and will work on low end hardware. Also it does not require another pass for cards that support multi-texturing (almost all of them).
- It can be implemented using Ogre's material script, which means I don't have to mess with a shader language.
- Artist control. I can change the cubemap face assets, and the resulting effect without touching a line of script or code.
- It looks pretty good!
- It's not per-pixel. This means that the effect relies on the verticies of the model to figure out how to apply the map. This means that the effect will be less accurate on very low poly objects.
- Cubemap asset takes up memory. If this were done using a shader there would be no memory hit, but using this method requires 6 textures - one for each face of the cubemap.