由highmap计算法向量
转自:Calculate Normals from Heightmap
From vector calculus, the normal of a surface is given by the gradient operator:
A height map h(x, y)
is a special form of the function f
:
For a discretized height map, assuming that the grid size is 1, the first-order approximations to the two derivative terms above are given by:
Since the x
step from L
to R
is 2, and same for y
. The above is exactly the formula you had, divided through by 4. When this vector is normalized, the factor of 4 is canceled.
(No linear algebra was harmed in the writing of this answer)