Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Height maps -> Normal Maps

This topic is 5409 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

In the Cg Tutorial book, it states that to generate a normal map from a height map you just : take each texel Hg and find the texel above it Ha and the texel to the right Hr. and use normal = ( Hg - Ha, Hg - Hr, 1 ) / sqrt( (Hg-Ha)^2 + (Hg-Hr)^2 + 1 ). Ok thats no problem its just if i take say a 64x64 image there will only be 63x63 normals on the normal map because i cant do the ones on the very right or very top can I? or do i just use this 63x63 normal map??

Share this post

Link to post
Share on other sites
I tend to use central differences for the interior points:

f[i+1][j] - f[i-1][j]

and just use forward or backward difference for the edges:

f[1][j] - f[0][j]
f[n-1][j] - f[n-2][j]

Of course, the same should go for the j direction too.

so 2 main sections

//Center calcs
for (i=1; i < n-1; ++i)
for (j=1; j < n-1; ++j)
// central difference

// Edge calcs
for (i=0; i < n; ++i)
// north edge
// east edge
// south edge
// west edge

Also, there may be a scaling factor involved, if the "heightmap" is really scaled (like into a 0-255 range, for example).


Piranha are people too.

Share this post

Link to post
Share on other sites
Uh... Just a thought here, but

A) wrap around the the other side of your map, if it wraps
B) go backwards one vertice for the last one. Yes you might have to invert it, i''m not sure, but that should still form a proper normal.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!