Jump to content
  • Advertisement
Sign in to follow this  
serious_learner07

OpenGL Normal Map Generation

This topic is 3653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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_map
end

Share this post


Link to post
Share on other sites

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.








Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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?












Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!