Skip to main content
gamedev.net
🔒 Locked

2D Normal Map Generation

Started by RyanT Mar 2, 2009 at 3:58 PM 5 replies 2k views
Original Post
RyanT
RyanT
Hello everyone! I am currently interested in writing an application that creates 2D normal maps from a texture. I haven't been able to find anything that explains how a normal map really works other than it provides depth to a flat surface. But I have no idea on where to start on this. I don't want someone to write this for me, thats no fun. But can anyone suggest a good read on how normal maps are calculated/created? To start, I learned how to read a given image pixel by pixel and then convert that image into a gray scale image, but now I am unsure how to continue. Thank you!
osmanb
osmanb
You might be able to do something like this, but you really don't want to. Normal maps represent fine surface detail per-pixel. The two most common methods of creating them are:

* Make very high poly models, and then use a tool that generates a normal map from that data. This essentially take the normals of the high-poly mesh, and bakes them into the normal map so that a low-poly mesh looks "similar".

* Convert heightmap textures. This is closer to what you're describing, but you don't want to start with a standard (diffuse) texture. You want to start with a greyscale texture that represents the height of the surface at each pixel (eg, heightmap). From that, you can basically take the difference of adjacent pixels to figure out what direction the surface is pointing and compute your normals. There are many tools to do this (including the popular NVidia Photoshop plugin). Even if you're going to write your own, you might want to look at one of those, at least to understand how the process works.
noisecrime
noisecrime
Look up Sobel filter kernels, that should get you on the right track.
RyanT
RyanT
Perfect! Thank you, I'll be sure to ask if I run into any snags!
MJP
MJP
Well...I mean ideally you want to generate normal maps from a height map but if you don't have one (or don't want to spend hours creating one) you can usually generate a normal map straight from a diffuse map. Nvidia's photoshop plugin does a decent job at this...I've done it in the past. Crazybump is also great for this, but unfortunately it's not free.
GMano
GMano
I have used xNormal and was very pleased with the results. It is free, and can be downloaded here: http://www.xnormal.net/Downloads.aspx .

From the faq:

Quote:

xNormal is an application to generate normal / ambient occlusion / parallax displacement and relief maps. It can also project the texture of the highpoly model into the lowpoly mesh ( complete texture transfer, even with different topologies ).

Includes too an interactive 3D viewer with multiple mesh and textures format support, shaders and realtime soft shadows / glow effect.

To finish, comes with some useful tools like height map - normal map - cavity map - occlusion - tangent/object space tools.


There is also an SDK that allows you to write your own plugins and mappings. I have also used the nVidia plugin, and found xNormal to be far superior.
Adovid
Adovid
A normal map isn't very complicated to understand, the map is used like a texture but as the pixel shader renders the polygon/(or more accurately, the fragment of the screen made by the polygon) for each pixel on the screen it uses the color values in the map (red, green, blue) as a vector (x, y, z) to represent the current normal it is calculating lighting with rather than taking the averaged normal from the vertices given by the vertex shader.

Normals can be derived from height maps, a height map is just a texture where black represents the lowest height and white represents the highest. Obviously since colors are finite this can be scaled by a factor to represent a greater displacement between the colors, but that's done outside of the texture itself.

Making a normal map from a height map involves taking samples of and around the current pixel which represent offsets of a flat plane then using those values to represent a derived plane and then finding the normal of that and setting the value of the pixel at that position.

When you use/make a shader for these normal maps you should note that a normal from a height map should take its orientation from the original normal rather than replace it because the normal is relative to a flat plane and lacks any detail regarding the surface of the model-- mapping to the back side of a model for instance, will look like the model has indentations rather than bumps.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.