The second one is correct, but the first one is almost correct. The cross product of (1, 0, dz1) and (0, 1, dz2) is (0*dz2 - dz1*1, dz1*0 - dz2*1, 1*1 - 0*0) = (-dz1, -dz2, 1), which is the same as the first one except for the signs being flipped in the x and y coordinates. What the second one is doing is really defining two tangent vectors dx and dy, and the normal is of course the cross product of the tangents.

hi,

how do i convert a heightmap to a normal map? I found two different solutions but i need a correct explanation

(i)

dx=heightmap[j]-heightmap[i-1][j]

dy=heightmap[j]-heightmap[j+1]

vector3d normal=(dx,dy,1)

normal.normalize()

(ii) dz1=heightmap[j]-heightmap[i-1][j]

dz2=heightmap[j]-heightmap[j+1]

dx=(1,0,dz1)

dy=(0,1,dz2)

normal=dx.cross(dy)

the above two procedures don’t seem to be the same to me. the first one samples the heights in the X and Y directions whereas the second one defines the X and Y components as unit. which one is the correct?