Pretentious, opinionated language

Games, technology, music, silliness. Oh and ninjas. Lots of ninjas.

My Photo
Location: Oslo, Norway

I am Andreas. Day time programmer and technical consultant. Night time musician and game developer.

Monday, February 14, 2005

Normal maps in Maya 4.0+

A little tutorial, just because i think it's ultimate badass and something all Maya users should be familiar with.

Normal maps work in all versions of Maya post 4.0, so it's not exactly ground breaking technology considering how pop of a buzzword it has become in the games industry.

First of all, in case you're not acquinted with the term, a surface normal is its facing direction, hence a normal map is a texture that alters the way the camera calculates a surface's direction. In essence this allows you to fake geometry. For instance, normal mapping a logo and applying that texture to a simple plane will allow you to animate lights across the surface and retain an illusion of 3d even though the texture is 2d on a flat plane. Alternatively, as it is in use in the games industry, you can apply normal maps to a surface to give it greater resolution while retaining a low polycount, ensuring a better framerate with no real expense to the quality of your graphics. Recent usage of this technique is Halflife 2 and Farcry. Doom 3 makes more use of them than any other game on the market.

So what does a normal map look like? You're probably familiar with bumpmaps already, which are grayscale textures that alter the way light is calculated across a surface. The difference is of course that you lose any surface direction information, which is seriously detrimental to the quality of the illusion. An example bump map looks something like this:

This texture contains grayscale information ranging from 0 to 1, with black being 0 and white being 1. This information is interpreted by the renderer to alter the way light flows across the surface and give the illusion of real texture, and in use with a comparable color map you can produce some very good looking results.

However, a bump map just won't give you realistic lighting. Try having a bump that cuts from 0 to 1 to make hard tiles, and you will have the ugliest jaggies since the catholic church.

A normal map however, is a different creature, containing RGB information. Have a look why don't you :)

Ugly, but it serves as a good example. RGB translates to XYZ vectors. Red being the surface direction left/right, Green being up/down and Blue being the depth perceived by the camera. This kind of map is usually created through difference maps, where one high resolution model is compared to a low res model. However we have no such luxury today. We shall do it in the filthy, quick, dirty and fun way of true amateurs; creating a normal map shader. The above image was created by placing a few nurbs spheres in empty space, applying a normal map shader to them and rendering from the top view.

Building a normal map shader in maya is far easier than most things you'll do. Here's the shading network:

It really is that simple. Pipe the normalcamera of a sampler info node into the outcolor of a surface shader.

Applying this normal map is sort of a reversal of the process. Here's a shader that makes use of an imported normalmap texture:

Run the outColor of your normal map texture into the normalcamera of your shader.

Keep in mind that certain shaders such as surface shaders don't have a true diffuse component and thus don't have a normal camera property. Now lets see what this looks like in render shall we? If you have Maya 6 this will render just fine with High Quality Preview, which is rather convenient. Here's a simple nurbs plane with the above lambert applied:

Now with a point light, moved into a couple of positions:

It really is rather nifty. An immediate field of use is billboards with realistic lighting to simulate fields of flowers or dense forests without having to render complex geometry. It renders quick as the devil in most renderers, and for the most part, hardware render+alpha will actually suffice for compositing (!), which is rather rare.

Another potentially useful use for this type of methodology is creating bumpmaps (which still renders faster) by piping the normalcamera Z property of the sampler info node into all color channels of the surface shader, resulting in a grayscale that is completely based on the depth.

Hopefully you'll have had some use of this, it's really a lot of fun to just play around with, and who knows, you may just find a good use for it to speed up your render times.


Blogger FishZombie said...

Just wanted to say thanks for posting this tutorial, I've been trying to find out how to use normal maps and your article was really helpful. Thanks!

9:11 PM  

Post a Comment

Links to this post:

Create a Link

<< Home