How do I create an Object-Space normal map from a height map?

1.2k views Asked by At

I'm able to convert my existing height-map into a normal map by sampling the surrounding pixels, like in this question Generating a normal map from a height map? except I'm doing it on CPU.

I have a sphere that I want to normal map in object-space. How to I apply the above normal-map to the normals on my sphere vertices?

2

There are 2 answers

0
Joonazan On

Normal maps do not modify vertex normals. They are used for details smaller than vertices.

In your fragment shader, look up the normal at the fragment's texture coordinates and modify the fragment's normal with it.

0
agnu17 On

As stated before, normal mapping is done per-pixel, so applying it on your sphere's vertices would not work.

In your fragment shader you have to supply/calculate a tangent and bitangent along with the mesh normal vectors.

Then you can use a 3x3 matrix of the normal, tangent and bitangent vectors, and the normal vector you read from the normalmap to calculate the new normal vector.

There's a great tutorial on this topic here: http://ogldev.atspace.co.uk/www/tutorial26/tutorial26.html