首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络游戏 >

LOD 地形渲染有关问题

2012-08-11 
LOD 地形渲染问题LOD学习有一周了,有一些突破,还是有BUG,不知道怎么解决,下面是效果图:这里只是先修补上方

LOD 地形渲染问题
LOD学习有一周了,有一些突破,还是有BUG,不知道怎么解决,下面是效果图:


这里只是先修补上方点,加了俩条边!


这里多了很多莫名的边,不知道原因.

下面给出顶点添加的代码:
void GameLodTerrain::SetNodeVertex(QuadTreeNode *pNode)
{
   
  if(pNode->m_Size<2||pNode==NULL) return;
  if (FALSE == pNode->m_bIsVisible||FALSE==pNode->m_bIsTouched)
  return;
  if (TRUE == pNode->m_bIsReached)
  {
  // fill vertex buffer
  static INT nSizeDivide2 = m_row >> 1;
  INT L = pNode->m_CenterX - (pNode->m_Size >> 1); // left
  INT R = pNode->m_CenterX + (pNode->m_Size >> 1); // right
  INT X = pNode->m_CenterX; // center X
  INT Y = pNode->m_CenterY; // center Y
  INT T = pNode->m_CenterY - (pNode->m_Size >> 1); // top
  INT B = pNode->m_CenterY + (pNode->m_Size >> 1); // bottom

  INT L1=0;INT R1=0;INT T1=0;INT B1=0;
  if(!pNode->m_bIsLeaf&&pNode->m_Size<=4)
  {
  L1 = pNode->m_CenterX - (pNode->m_Size >> 2); // left
  R1 = pNode->m_CenterX + (pNode->m_Size >> 2); // right
  T1 = pNode->m_CenterY - (pNode->m_Size >> 2); // top
  B1 = pNode->m_CenterY + (pNode->m_Size >> 2); // bottom
  }

  // 1 2 3 TL Top TR
  // 8 0 4 -> Left Center Right
  // 7 6 5 BL Bottom BR
  int i=0;
  // CENTER
  m_pVerticesPtr[m_vbIndex + i]._x = (X - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._z = (Y - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._y = m_heightmap[Y][X];
  m_pVerticesPtr[m_vbIndex + i]._u = m_tuArray[X];
  m_pVerticesPtr[m_vbIndex + i]._v = m_tvArray[Y];
  i++;
  // TL
  m_pVerticesPtr[m_vbIndex + i]._x = (L - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._z = (T - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._y = m_heightmap[T][L];
  m_pVerticesPtr[m_vbIndex + i]._u = m_tuArray[L];
  m_pVerticesPtr[m_vbIndex + i]._v = m_tvArray[T];
  i++;
  // TOP,上方要进行修补处理
  QuadTreeNode *n=FindNode(X,Y-pNode->m_Size);
  if(pNode->m_bIsLeaf||n==NULL)
  {
  m_pVerticesPtr[m_vbIndex + i]._x = (X - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._z = (T - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._u = m_tuArray[X];
  m_pVerticesPtr[m_vbIndex + i]._v = m_tvArray[T];
  m_pVerticesPtr[m_vbIndex + i]._y = m_heightmap[T][X];
  i++; 
  }
  else if(n->m_Size>4||n->m_bIsReached||!n->m_bIsTouched)
  {

  m_pVerticesPtr[m_vbIndex + i]._x = (X - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._z = (T - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._u = m_tuArray[X];
  m_pVerticesPtr[m_vbIndex + i]._v = m_tvArray[T];
  m_pVerticesPtr[m_vbIndex + i]._y = m_heightmap[T][X];
  i++; 
  }
  else if(!n->m_bIsReached&&n->m_Size<=4)
  {
  m_pVerticesPtr[m_vbIndex + i]._x = (L1 - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._z = (T - nSizeDivide2) * m_wScale;


  m_pVerticesPtr[m_vbIndex + i]._u = m_tuArray[L1];
  m_pVerticesPtr[m_vbIndex + i]._v = m_tvArray[T];
  m_pVerticesPtr[m_vbIndex + i]._y = m_heightmap[T][L1];
  i++;
  m_pVerticesPtr[m_vbIndex + i]._x = (X - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._z = (T - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._u = m_tuArray[X];
  m_pVerticesPtr[m_vbIndex + i]._v = m_tvArray[T];
  m_pVerticesPtr[m_vbIndex + i]._y = m_heightmap[T][X];
  i++; 
  m_pVerticesPtr[m_vbIndex + i]._x = (R1 - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._z = (T - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._u = m_tuArray[R1];
  m_pVerticesPtr[m_vbIndex + i]._v = m_tvArray[T];
  m_pVerticesPtr[m_vbIndex + i]._y = m_heightmap[T][R1];
  i++;
  }
  // TR
  m_pVerticesPtr[m_vbIndex + i]._x = (R - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._z = (T - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._y = m_heightmap[T][R];
  m_pVerticesPtr[m_vbIndex + i]._u = m_tuArray[R];
  m_pVerticesPtr[m_vbIndex + i]._v = m_tvArray[T];
  i++;
  // RIGHT
  m_pVerticesPtr[m_vbIndex + i]._x = (R - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._z = (Y - nSizeDivide2) * m_wScale; 
  m_pVerticesPtr[m_vbIndex + i]._u = m_tuArray[R];
  m_pVerticesPtr[m_vbIndex + i]._v = m_tvArray[Y];
  m_pVerticesPtr[m_vbIndex + i]._y = m_heightmap[Y][R];
  i++;
  // BR
  m_pVerticesPtr[m_vbIndex + i]._x = (R - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._z = (B - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._y = m_heightmap[B][R];
  m_pVerticesPtr[m_vbIndex + i]._u = m_tuArray[R];
  m_pVerticesPtr[m_vbIndex + i]._v = m_tvArray[B];
  i++;
  //BOTTOM
  m_pVerticesPtr[m_vbIndex + i]._x = (X - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._z = (B - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._u = m_tuArray[X];;
  m_pVerticesPtr[m_vbIndex + i]._v = m_tvArray[B];
  m_pVerticesPtr[m_vbIndex + i]._y = m_heightmap[B][X];
  i++;
  // BL
  m_pVerticesPtr[m_vbIndex + i]._x = (L - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._z = (B - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._y = m_heightmap[B][L];
  m_pVerticesPtr[m_vbIndex + i]._u = m_tuArray[L];
  m_pVerticesPtr[m_vbIndex + i]._v = m_tvArray[B];
  i++;
  // LEFT
  m_pVerticesPtr[m_vbIndex + i]._x = (L - nSizeDivide2) * m_wScale;
  m_pVerticesPtr[m_vbIndex + i]._z = (Y - nSizeDivide2) * m_wScale; 
  m_pVerticesPtr[m_vbIndex + i]._u = m_tuArray[L];
  m_pVerticesPtr[m_vbIndex + i]._v = m_tvArray[Y];
  m_pVerticesPtr[m_vbIndex + i]._y = m_heightmap[Y][L];
  i++;


  // fill index buffer
  // 1 2 3
  // 8 0 4
  // 7 6 5
  int j=0;
  for(int k=1;k<i-1;k++)
  {
  m_pIndicesPtr[m_ibIndex+ j] = (WORD)m_vbIndex + k;
  j++;
  m_pIndicesPtr[m_ibIndex+ j] = (WORD)m_vbIndex + k+1;


  j++;
  m_pIndicesPtr[m_ibIndex+ j] = (WORD)m_vbIndex + 0;
  j++;
  }
  m_pIndicesPtr[m_ibIndex+ j] = (WORD)m_vbIndex + i-1;
  j++;
  m_pIndicesPtr[m_ibIndex+ j] = (WORD)m_vbIndex + 1;
  j++;
  m_pIndicesPtr[m_ibIndex+ j] = (WORD)m_vbIndex + 0;
  j++;
   
  m_vbIndex += i;
  m_ibIndex += j;

}
else if (!pNode->m_bIsLeaf)
  {
  SetNodeVertex(pNode->m_pTLChildNode);
  SetNodeVertex(pNode->m_pTRChildNode);
  SetNodeVertex(pNode->m_pBLChildNode);
  SetNodeVertex(pNode->m_pBRChildNode);
  } 
}
希望有高手指点下迷津。




[解决办法]
问你个问题,你这样 的 地形 ,做了lod,那么贴图 怎么帖?用1张贴图?还是多个 平铺?
[解决办法]
那么我想问,那么大型的地形 也是用一张贴图么?比如 大型3d网游的?

热点排行