3d XNA-绘制线列表(栅格叠加三维地形)

3d XNA-绘制线列表(栅格叠加三维地形),3d,xna,game-engine,3d,Xna,Game Engine,我试图在我的(将成为)3d地形上覆盖一个网格。但是,现在我正在使用顶点列表绘制线列表。当前线列表有12个顶点,并导出此结果。我希望有人能给我指出正确的方向,让电网正常工作 编辑:顺便说一句,现在我需要30个顶点才能得到一个网格 当前顶点代码: private void SetUpTileVertices() { tileVertices = new VertexPositionColor[terrainWidth * terrainHeight]; fo

我试图在我的(将成为)3d地形上覆盖一个网格。但是,现在我正在使用顶点列表绘制线列表。当前线列表有12个顶点,并导出此结果。我希望有人能给我指出正确的方向,让电网正常工作

编辑:顺便说一句,现在我需要30个顶点才能得到一个网格

当前顶点代码:

private void SetUpTileVertices()
    {

        tileVertices = new VertexPositionColor[terrainWidth * terrainHeight];
        for (int x = 0; x < terrainWidth; x++)
        {
            for (int y = 0; y < terrainHeight; y++)
            {
                tileVertices[x + y * terrainWidth].Position = new Vector3(x, heightData[x, y] + 0.01f, -y);
                tileVertices[x + y * terrainWidth].Color = Color.Red;
            }
        }
    }

绘制地形时。。。可以计算世界空间中地形像素的位置,并根据像素与网格线的距离更改其颜色

如果顶点位于(0,0),(1,0),(2,0),。。。。 (0,1),(1,1),(2,1)

可以将顶点着色器上的顶点位置传递给像素着色器。。。在像素着色器中。。。您可以执行类似的操作:

  float4 pixel_shader (in float4 color:COLOR0, 
                     in float2 tex: TEXCOORD0, 
                     in float3 pos:TEXCOORD1) : COLOR
  {
     // Don't draw the pixel if it's to close to grid lines, 
     // Instead you could tint pixel with another color .. 
     clip ( frac(pos.X + 0.01) - 0.02 ); 
     clip ( frac(pos.Z + 0.01) - 0.02 );  

     // Sampling texture and returning pixel color code....
   } 

一个简单得多的方法是用一个图形绘制地形。虽然我不知道哪种方法性能更好。就像将光栅化器设置为线框,绘制我的网格,然后将其设置回fillmode以绘制其余的?完全正确。您还需要调整深度偏移,因为多边形和线最终位于同一位置,否则会导致严重的Z字型冲突。或者干脆完全关闭深度比较,在顶部绘制线框。好吧,有道理,我怎么能不画对角线呢?在这种情况下,恐怕你必须手动创建一个额外的线列表/条带,只包含你想要可视化的边。
  float4 pixel_shader (in float4 color:COLOR0, 
                     in float2 tex: TEXCOORD0, 
                     in float3 pos:TEXCOORD1) : COLOR
  {
     // Don't draw the pixel if it's to close to grid lines, 
     // Instead you could tint pixel with another color .. 
     clip ( frac(pos.X + 0.01) - 0.02 ); 
     clip ( frac(pos.Z + 0.01) - 0.02 );  

     // Sampling texture and returning pixel color code....
   }