Skip to main content
GameDev.net gamedev.net
🔒 Locked

Normal Map Generation

Started by serious_learner07 Aug 15, 2008 at 10:58 AM 5 replies 2.2k views
Original Post
serious_learner07
serious_learner07
I have a file which has a only vertex information - (x,y,z) corresponding to each verticies.I need to generate Normal Map, so as to do Normal Mapping. How can I generate Normal map. I don't want to use Blender or similar tools for the Normal Map generation, rather I want to use C/C++/OpenGL for it. How to generate Normal Maps?
Kambiz
Kambiz
You need two versions of the model to generate a normal map:
1) A lowpoly model with a uv map
2) A highpoly version of the same model

The algorithm:
normal_map = new texture(width,height)for each pixel(x,y) in normal_map do    u = x/width , v = y/height    find position(=p) and normal(=n) on lowpoly model corresponding to (u,v)    find the nearest point(=np) to p on the highpoly model (along n)    read the normal at np from the highpoly model and write it to the normal_mapend
serious_learner07
serious_learner07

Thanks a lot kambiz.

Quote:
Original post by Kambiz
You need two versions of the model to generate a normal map:
1) A lowpoly model with a uv map
2) A highpoly version of the same model


What is the difference between lowpoly model and highpoly model.
Is it possible to generate them from a give 3D Model file such as *.obj ( wavefront).I only have vertex(x,y,z) information of the polygon and I need to generate Normal Map.








VizOne
VizOne
Hm, I have the feeling that you aren't looking for normal map generation but for vertex normal generation if you only have the positions of the vertices.

There are different approaches to automatically generate normals for a vertex. For example, you could do this:

- calculate the normals of all faces which the vertex is part of
- take the average of those normals as the vertex normal.

To calculate the normal of a face with vertices A, B and C, you create two vectors AB = B-A and AC = C-A and take their cross product:

face.normal = normalize(cross(face.B - face.A, face.C - face.A));

The only problem is the winding order of the vertices, because depending on the correct order of A, B and C you'd get a normal that's pointing inwards or outwards the mesh. For purely convex meshes that's easy, because the normal will always be pointing away from the center point (= dot(center-face.A, face.normal) < 0)
Kambiz
Kambiz
Are you sure you are looking for normal maps?

(Image from www.game-artist.net)

Per-vertex normals can be calculated as VizOne described, although they should ideally exported from the modeling program. To make sharp edges light correctly you also need to use a maximum smoothing angle. Modeling tools give you a lot of control, you can use different smoothing groups with different smoothing angles... so don't expect to get the same result calculating the normals yourself.
serious_learner07
serious_learner07

Quote:
Original post by Kambiz
Are you sure you are looking for normal maps?
(Image from www.game-artist.net)


Yes this is what I want.But I don't have the required input.
Ok No problems. I will attempt as suggested by kambiz.
I will seek the help of fellow classmate to generate the poly models.

But I have few basic doubts.

Quote:

find position(=p) and normal(=n) on lowpoly model corresponding to (u,v)


Does this involve a linear search of position in the lowpoly model file corresponding to the (u,v) coordinate?

Quote:

find the nearest point(=np) to p on the highpoly model (along n)


Does it involve distance compuatation between the p and highpoly model?

What is the Optimized way?












BlackSeeds
BlackSeeds
If you want to generate a normal map for a texture map all the graphics guys where I work are loving CrazyBump

don't know if this is what you want but its a good tool to generate normal maps for things that already have a UV texture map.

Topic Locked

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

Sign in to reply to this topic.