关于Fast Terrain Rendering Using Geometrical MipMapp

75 篇文章 0 订阅
72 篇文章 0 订阅

在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 equations
	float C, A, T;

	T = 2 * MaxError / Vres;
	//convert FoV to radians
	FoV *= 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 vertices
			for( 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值