Per-Vertex Normals from perlin noise?

后端 未结 2 2147
别那么骄傲
别那么骄傲 2021-02-14 01:47

I\'m generating terrain in Opengl geometry shader and am having trouble calculating normals for lighting. I\'m generating the terrain dynamically each frame with a perlin noise

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-14 01:55

    The normal is the vector perpendicular to the tangent (also known as slope). The slope of a function is its derivative; for n dimensions its n partial derivatives. So you sample the noise around a center point P and at P ± (δx, 0) and P ± (0, δy), with δx, δy choosen to be as small as possible, but large enough for numerical stability. This yields you the tangents in each direction. Then you take the cross product of them, normalize the result and got the normal at P.

提交回复
热议问题