rim lighting extravabonanzathon

Thursday, February 7, 2008

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:

To create this cubemap, I built a scene in maya of a hollow white sphere, with a black dot on the front face. Since you are always looking through the "front" of the cube, when this is applied to objects it will apply that light gradient around the top, bottom, left and right of it.

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.

The advantages:
  • 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!
The disadvantages:
  • 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.
After getting this effect on a lot of things in the game and some tweaking and tuning, I made some screenshots / wallpapers of the rimlighting in action for everyone to enjoy. They come in 1280x720 and 1920x1080 flavors:

click -> 720 , 1080

click -> 720 , 1080

click -> 720 , 1080


Anonymous said...

Nice work!

Anonymous said...

A real-time rim-lighting technique that looks good and is performance-worthy? Dang, you've hit on a really nifty solution-- great job!

Pau said...

When I saw your first post comparing your game with rim-lighting and without it I thought it was a really nice effect, it makes a real impact on the overall graphic style.

I'll probably try something similar in the game I'm working on... When I get to that stage :)

Have you implemented a pixel shader version to check the improvements you can get, quality-wise?

Thanks for this post, very interesting!

David Marsh said...

thanks Pau! We have not gotten a shader version of the effect working in the engine to compare, that would be a good thing for us to do at some point down the road.

Brian Cronin said...

We actually had a shader version working in engine a couple months ago but we couldn't get it to work with textures so we put that effort on hold. I intend to look back into that sooner or later...

Anonymous said...

Cool story you place here. It will be useful to read anything more concerning this article. Thanks for tell that information. Sara
Kiev escort