Sign in to follow this  
superninja

Generate normal map from height map?

Recommended Posts

superninja    139
Hello, I have a height map from which I would like to generate a normal map. I have an outline in my mind of how to proceed, but I'm not 100% sure. I think I have to do something like the Sobel operator at each pixel, and use that to generate the normal at that pixel. I'm not looking for a 100% answer, but a shove in the right direction would be much appreciated. :)

Share this post


Link to post
Share on other sites
ive never used the sobel operator before, any time i've needed to do it ive simply approximated it at each pixel by considering a set of surrounding pixel's height values compared to current and average the normal from the slope between each one - seems to work well enough for me.

there probably is a better way though.

Share this post


Link to post
Share on other sites
dpadam450    2357
I've never done it but here's an idea:

___
|...|
|___| , thats a side view of 3 pixels, the box is the bitmap




___y___
| . |
|. . |x
|_______|


Here are 3 pixels (left, current, and right) with their heights shown. So these 3 pixels are all at the same x-position.

Since you are sampling only the left and right of the current, they have no 'y' component. You can see the vector edges from each pixel using the height, the x compenets will be -1 and 1 since they are 1 pixel apart. and the z component will be the height differences.

Using the height difference, and the +1 or -1, you have a 2d vector. Find an orthogonal vector for each side. Use this same concept for the other adjacent pixels (8 pixels total), and then average them.

Share this post


Link to post
Share on other sites
MaR_dev    154
First: dont write your own algo, unless its for educational purposes. This problem was solved greatly with many options by existing tools -> gimp plugin or NVIDIA texture tools.

If still you want to implement this feature yourself, use Sobel operator or Prewitt edge detection filter. Its not really that complicated, you just need to extend edges of the image by replicating neighboring pixels by size of the filter (3x3 or 5x5 usually).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this