游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2157|回复: 4

如何让directx 只 render 看到的地形

[复制链接]

4

主题

8

帖子

8

积分

新手上路

Rank: 1

积分
8
发表于 2007-1-24 22:41:00 | 显示全部楼层 |阅读模式
我是用 DrawPrimitive 来画地形, 但一次过画上512x512的正方形好像太慢,
正在想办法让directx 只 render 看到的地形,
我上www.gamedev.net 看到一个教 occlusion query 的东西,

g_pMapQuery->Issue( D3DISSUE_BEGIN );
  {
     g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, ....       
  }
g_pMapQuery->Issue( D3DISSUE_END );

DWORD dwMapData;

while( g_pMapQuery->GetData( (void*)&dwMapData, sizeof(DWORD), D3DGETDATA_FLUSH) == S_FALSE );

但用起来, 好像没有快了, 反而慢了...[em7]

其实除此之外, 还有什么方法让 directx 只 render camera 看到的地形呢?
因为连 camera 的背向的地形也 render 好像太笨了...

9

主题

688

帖子

688

积分

高级会员

Rank: 4

积分
688
发表于 2007-1-24 23:15:00 | 显示全部楼层

Re:如何让directx 只 render 看到的地形

要自己写算法吧。

35

主题

1735

帖子

1739

积分

金牌会员

Rank: 6Rank: 6

积分
1739
QQ
发表于 2007-1-25 08:35:00 | 显示全部楼层

Re:如何让directx 只 render 看到的地形

使用四/八叉树,BSP,视锥拣选,LOD,等相关的可见性检测算法.

4

主题

8

帖子

8

积分

新手上路

Rank: 1

积分
8
 楼主| 发表于 2007-1-25 13:25:00 | 显示全部楼层

Re:如何让directx 只 render 看到的地形

谢谢大家, 我上网找了这个来测试vertex是否在视锥内:
float abs_f(float f)
{
    if( f<0 ) return -f;
    return f;
}
bool FrustrumCheck(float x, float y, float z)
{
       



      D3DXMATRIX matWorld, matView, matProjection;

      g_pd3dDevice->GetTransform(D3DTS_WORLD, &matWorld);
      g_pd3dDevice->GetTransform(D3DTS_VIEW,  &matView);

      g_pd3dDevice->GetTransform(D3DTS_PROJECTION, &matProjection);
      // I chaned this line, so you could change the projection view here, adjusting
      // the near and far plane...alternatively you can just use the GetTransform
      // DX call, and use the pre-set one.

      D3DXMATRIX Cull = matWorld * matView * matProjection;
      D3DXVECTOR4 vNode = D3DXVECTOR4(x,y,z,1);

      D3DXVECTOR4 vTestVert;
      D3DXVec4Transform(&vTestVert, &vNode, &Cull);


      if( abs_f(vTestVert.x) > abs_f(vTestVert.w) ) // Outside our X Frustum Plane
            return false;

      if( abs_f(vTestVert.y) > abs_f(vTestVert.w) ) // Outside our Y Frustum Plane
            return false;

      if( (vTestVert.z<0.0f) || (vTestVert.z>vTestVert.w)) // Outside our z Frustum Plane
            return false;

      return true;
}
可是时间都花到cpu之上, 只多了10左右的fps...

44

主题

248

帖子

274

积分

中级会员

Rank: 3Rank: 3

积分
274
发表于 2007-1-26 09:46:00 | 显示全部楼层

Re:如何让directx 只 render 看到的地形

按四叉树划分好terrain然后 在根据四叉树 剔除

剔除肯定是要按patch来进行的,按顶点剔除的话 没什么意义
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-26 08:06

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表