Skip to main content
GameDev.net gamedev.net
🔒 Locked

Normal Map from HeightMap calculation - theory/source ?

Started by Moet_Man Jun 26, 2010 at 1:07 AM 3 replies 2.8k views
Original Post
Moet_Man
Moet_Man

I'm struggling to understand normal Map generation from a greyscale texture programticaly . has anyone tacked this and have any thoughts?
bubu LV
bubu LV
Just calculate normal (x,y,z) for each pixel in heightmap, and then store x,y,z coordinates in normal map texture. Or just store x and y in normal map texture and calculate z in pixel shader.
Hyunkel
Hyunkel
I still had this lying around somewhere on my hdd, so I'm afraid I don't know the source.
It basically calculates two tangent vectors, and obtains the normal by doing a cross product of both tangents.

z1=heightmap[j]-heightmap[i-1][j]z2=heightmap[j]-heightmap[j+1]dx=(1,0,z1)dy=(0,1,z2)normal=dx.cross(dy)


IIrc this looks a bit more "blocky" then running the heightmap through the nvidia photoshop plugin.
I'm pretty sure that I read about using a sobel filter to get rid of the blockyness, but I haven't tried that yet.
szecs
szecs
Quote:
Original post by Hyunkel
I still had this lying around somewhere on my hdd, so I'm afraid I don't know the source.
It basically calculates two tangent vectors, and obtains the normal by doing a cross product of both tangents.

*** Source Snippet Removed ***

IIrc this looks a bit more "blocky" then running the heightmap through the nvidia photoshop plugin.
I'm pretty sure that I read about using a sobel filter to get rid of the blockyness, but I haven't tried that yet.
You should normalize the result.
Hyunkel
Hyunkel
Indeed, all normal vectors should be normalized at all times.
I wonder if I forgot to do so when I tried this the first time.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.