Convert Normal Map to grayscale Bump Map?

Started by
42 comments, last by s ludwig 19 years, 2 months ago
The image he posted is a normal map with the blue channel (z component) cleared. We use this kind of normal map all the time (we put information like glow or shine in the blue channel instead).

You can use these maps in a shader by re-contructing the z from the x,y. Either with the proper math (if you can take the hit to speed) or just by setting it to 1.0 and re-normalizing (if you can live with it being inaccurate but still decent). This works because normal maps always have normals with positive z values (think about it, if a normal in your map had a negative z value then the texel would not be visible).

Anyway, I played around with some code to attempt to generate a height map from this normal map, but the results were skewed by it being a jpeg. I was able to produce reasonable results using a different map I had. I'll try and post the results tonight when I get home from work.
Advertisement
Okay, here are the (scaled) images I've got (even if Kuroyume0161 already has the solution at his hands..)

Initialized to zero (1, 10, 50, 1000 passes):


Initialized with direct integration result (0,10,50,200 passes):


Using the map directly as a dudv map or reconstructing the z-component doesn't really make a visible difference is this case. The output quality of a direct integration scheme will depend largely on the normalmap. especially for normalmaps like this one with large flat regions and thin elevations you will get errors because of the rounding that is done when storing the normal inside of an 8-bit integer (unless proper dithering is done). Because of those rounding errors there is also normally no solution to the corresponding equation system - you will have to approximate.

The source is here. Takes only uncompressed tga's, outputs test.tga. (edit: the program currently uses a repeat wrap mode when sampling the map while clamping would of course give better results for the eagle texture)
I was going to post results, but the results above are better than mine.

If I come up with anything better, I'll post it.

One addition.. fixed a small error that caused edges to blur slightly and generated a too large height range.


(source updated)

This topic is closed to new replies.

Advertisement