关于Fast Terrain Rendering Using Geometrical MipMapp

来源:互联网 发布:软件需求变更流程图 编辑:程序博客网 时间:2024/05/17 22:24

在3D中,LOST OF DETAIL 是一种避免过多渲染细节的方法。
使用一些列的级别细节图来模拟LOST OF DETAIL;
但是如何选择合适的距离来使用不同的细节图呢?
下面一个方法。
[img]

 



 [/img]

 

在以上图中:

    errorH表示图块失去细节后所失去的高度。

因此根据三角形相似可以求出d.

   CB 为errorH的投影。

当CB为一个阀值的时候,errorH可以被忽略。

errorH越远,CB越短,当短到人的肉眼可以忽略的时候,说明errorH从错误变成了可以忽略的误差。这个时候,细节图可以被更高级别模糊度的图块所取代。

 

 

公式就是三角形相似外加坐标转换,像素坐标转换为自定义坐标。

 

 

代码如下:

 

//earlier in the file:inline int PINDEX( int x, int z ) { return x * 33 + z; }void CScape::CalcErrors( float MaxError, int Vres, float FoV, float NearClip ){//vars for de Boer's equationsfloat C, A, T;T = 2 * MaxError / Vres;//convert FoV to radiansFoV *= PI / 180.0f;A = 1.0f / (float) tan( FoV / 2.0f );C = A / T;//go through all of the vertices that will be removed and calc errors/**-----*-----*-----*-----*|     |     |     |     ||     |     |     |     ||     |     |     |     ||     |     |     |     |*-----*-----*-----*-----*|     |     |     |     ||     |     |     |     ||     |     |     |     ||     |     |     |     |*-----*-----*-----*-----*|     |     |     |     ||     |     |     |     ||     |     |     |     ||     |     |     |     |*-----*-----*-----*-----*|     |     |     |     ||     |     |     |     ||     |     |     |     ||     |     |     |     |*-----*-----*-----*-----**/int x, z, l, p;ScapePatch* Patch;float Delta;ScapeVertex* Vert;for( p = 0; p < m_NumPatches; ++p ){Patch = &m_Patches[p];Delta = 0.0f;for( l = 0; l < 4; l++ ){int start = (int)fastpow( 2.0f, l );int inc = start*2;//first set of removed verticesfor( x = start; x < 33; x+=inc ){for( z = start; z < 33; z+=inc ){Vert = &Patch->Vertices[PINDEX(x,z)];Delta = Max( Delta, fabsf(Vert->y-(Patch->Vertices[PINDEX(x-start,z-start)].y + Patch->Vertices[PINDEX(x+start,z+start)].y) / 2.0f) );Delta = Max( Delta, fabsf(Vert->y-(Patch->Vertices[PINDEX(x+start,z-start)].y + Patch->Vertices[PINDEX(x-start,z+start)].y) / 2.0f) );}}Patch->D[l] = Delta * C;}}}

 
完毕。

 

 

 

 

 

 

 

 

  • 大小: 4.3 KB
  • 查看图片附件
阅读全文
0 0
原创粉丝点击