【问题标题】:Strange 'striping' issue when rendering terrain normals渲染地形法线时出现奇怪的“条纹”问题
【发布时间】:2013-08-11 00:51:41
【问题描述】:

我有一个奇怪的问题,我的法线在渲染地形时不起作用。我的地形渲染得很好,所以我省略了从高度图计算地形点以及如何计算索引的所有代码。我知道我应该使用着色器,但我想在继续之前先解决这个问题。我假设问题来自于我在法线生成代码中忽略的明显问题,如下所示:

for (currentind = 0; currentind < indices.size() - 3; currentind+=3)
{

indtopt = indices[currentind] * 3;
point1.vects[0]=terrainpoints[indtopt];//x
point1.vects[1]=terrainpoints[indtopt+1];//y
point1.vects[2]=terrainpoints[indtopt+2];//z


indtopt = indices[currentind+1] * 3;
//second indice

//points of that indice
point2.vects[0]=terrainpoints[indtopt];//x
point2.vects[1]=terrainpoints[indtopt+1];//y
point2.vects[2]=terrainpoints[indtopt+2];//z

indtopt = indices[currentind+2] *3;
//third indice

//points of that indice
point3.vects[0]=terrainpoints[indtopt];//x
point3.vects[1]=terrainpoints[indtopt+1];//y
point3.vects[2]=terrainpoints[indtopt+2];//z

//--------------------------------------------------
point4.vects[0]=(point2.vects[0]-point1.vects[0]);
point4.vects[1]=(point2.vects[1]-point1.vects[1]);
point4.vects[2]=(point2.vects[2]-point1.vects[2]);

point5.vects[0]=(point3.vects[0]-point2.vects[0]);
point5.vects[1]=(point3.vects[1]-point2.vects[1]);
point5.vects[2]=(point3.vects[2]-point2.vects[2]);
//-------------------------------------------------

//cross product
point6.vects[0]=point4.vects[1]*point5.vects[2] - point4.vects[2]*point5.vects[1];
point6.vects[1]=point4.vects[2]*point5.vects[0] - point4.vects[0]*point5.vects[2];
point6.vects[2]=point4.vects[0]*point5.vects[1] - point4.vects[1]*point5.vects[0];

point6 = point6.normalize();
ternormals[currentind]=point6.vects[0];
ternormals[currentind+1]=point6.vects[1];
ternormals[currentind+2]=point6.vects[2];
}

下面是线框和三角形渲染中存在的问题的图片:

如果需要,我可以发布更多代码,但我只是想保持这篇文章简短,所以我试图找到我认为问题可能出在哪里。

【问题讨论】:

    标签: opengl vbo terrain normals


    【解决方案1】:

    嗯,对于每个“暗”带,您都会意外翻转法线,可能是因为表面切线向量以错误的顺序传递到叉积中

    a × b = - (b × a)
    

    如果您的地形由三角形条带组成,那么您就有了双向排序,这意味着您必须翻转操作数或对每个奇数行取反叉积的结果。

    【讨论】:

    • 我认为可能是这样。不过,地形实际上是由三角形渲染的,因此不需要双向排序。
    • 嗯,有些东西正在颠覆你的常态。作为一个简单的解决方法,我建议您只需测试法线点是否向下,在这种情况下只需翻转法线;你也应该翻转三角形的绘制顺序,否则如果启用剔除,它就会被剔除。
    猜你喜欢
    • 2011-08-04
    • 1970-01-01
    • 2014-02-15
    • 2014-02-20
    • 2012-08-25
    • 1970-01-01
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多