计算高度图的法线 [英] Calculating normals for a height map

查看:229
本文介绍了计算高度图的法线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在计算高度图的法线时遇到了一个小问题.它有一个奇怪的行为.在较高和较低的点处,法线很好,但是在中间,它们似乎是错误的.它们由点光源点亮.

I have a small problem calculating normals for my heightmap. It has a strange behavior. At the higher and the lower points the normals are fine, but in the middle they seem wrong. They are lighted by a point light.

未固定来源已删除

尝试了2种新方法:

这是按面正常的.看起来不错,但您看到的是单张面孔.

This is per-face-normal. It looks fine but you see the single faces.

Position normal = crossP(vectorize(pOL, pUR), vectorize(pOR, pUL));

我也尝试通过这种方式对每个顶点执行此操作,但输出结果也很奇怪.

I also tried to do it per-vertex this way, but also with a strange output.

这是Nico的建议:

看起来也很奇怪.也许我在计算帮助点时有一个错误.

It looks also rather odd. Maybe there is a mistake how I calculate the helping points.

未固定来源已删除

我的观点的定义: OL,OR,UL,UR是要绘制的平面的角顶点.

EDIT 2: Definition of my points: OL,OR,UL,UR are the corner vertices of the plane that is to be drawn.

                postVertPosZ1 postVertPosZ2
preVertPosX1         pOL           pOR         postVertPosX1
preVertPosX2         pUL           pUR         postVertPosX2
                 preVertPosZ1  preVertPosZ2

我现在解决了.这是一个愚蠢的错误: 我忘记了将辅助顶点的y值与高度乘数相乘,而不得不更改一些值.

I solved it now. It was a stupid mistake: I forgot to multiply the y value of the helping Vertices with the height Multiplier and had to change some values.

现在很漂亮.

推荐答案

有很多方法可以解决此问题.我没遇到你的我建议使用中心差来估计高度场的偏导数.然后使用叉积获得正常值:

There are lots of ways to solve this problem. I haven't encountered yours. I suggest using central differences to estimate partial derivatives of the height field. Then use the cross product to get the normal:

每个顶点法线可以从其四个相邻法线计算得出.您不需要飞机及其邻居:

Each vertex normal can be calculated from its four neighbors. You don't need the plane plus its neighbors:

  T
L O R
  B

O是要为其计算法线的顶点.其他顶点(上,右,下,左)是它的邻居.然后我们要计算水平和垂直方向的中心差:

O is the vertex for which you want to calculate the normal. The other vertices (top, right, bottom, left) are its neighbors. Then we want to calculate the central differences in the horizontal and vertical direction:

             /           2           \
horizontal = | height(R) - height(L) |
             \           0           /

             /           0           \
vertical   = | height(B) - height(T) |
             \           2           /

法线是这些切线的叉积:

The normal is the cross product of these tangents:

normal = normalize(cross(vertical, horizontal))
                   / / height(L) - height(R) \ \
       = normalize | |           2           | |
                   \ \ height(T) - height(B) / /

请注意,这些计算假设您的x轴右对齐,而z轴向下对齐.

Note that these calculations assume that your x-axis is aligned to the right and the z-axis down.

这篇关于计算高度图的法线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆