#### Archived

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.

## 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 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]
and
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).

lonesock

Piranha are people too.

##### 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 on other sites
Thanks a lot.

Ya my object just repeats so i can just use the other side...

Thx for the help!

1. 1
2. 2
Rutin
19
3. 3
khawk
19
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633771
• Total Posts
3013763
×