由highmap计算法向量

转自:Calculate Normals from Heightmap

 

 

 

From vector calculus, the normal of a surface is given by the gradient operator:

由highmap计算法向量

 

A height map h(x, y) is a special form of the function f:

由highmap计算法向量

 

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:

由highmap计算法向量

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)