monogame奇怪的网格纹理

monogame weird grid texture

我在第一个单游戏项目中使用 DrawUserPrimitives 时遇到问题。我正在尝试绘制多个看起来像地形的图块。它有效……不知何故。这是它的样子:

My terrain -_-. Sorry, I cant post it directly because of 0 reputation

每个图块看起来像这样:

Single tile with a white border

如您所见,每个图块都有一个 1px 的白色边框。我猜这是白线的唯一来源。

问题:我不喜欢这些白色水平线(不是每个图块周围的边框,这些都可以)。

所以我的问题是:如何摆脱它们。我的代码有什么问题?

每个单元格都是由该代码创建的:

        // [ ][ ][ ]
        // [ ][ ][ ]
        // [x ][ ][ ]
        primitiveList[0].Position = new Vector3(0 + startpos.X, 0, 0 + startpos.Z);
        primitiveList[0].TextureCoordinate.X = 0;
        primitiveList[0].TextureCoordinate.Y = 1;

        // [ ][ ][ ]
        // [ ][ ][ ]
        // [ ][ ][x]
        primitiveList[1].Position = new Vector3(1 + startpos.X, 0, 0 + startpos.Z);
        primitiveList[1].TextureCoordinate.X = 1;
        primitiveList[1].TextureCoordinate.Y = 1;

        // [ ][ ][x ]
        // [ ][ ][ ]
        // [ ][ ][ ]
        primitiveList[2].Position = new Vector3(1 + startpos.X, 0, 1 + startpos.Z);
        primitiveList[2].TextureCoordinate.X = 1;
        primitiveList[2].TextureCoordinate.Y = 0;
        // Ergibt:
        // [ ][ ][x]
        // [ ][ ][ ]
        // [x][ ][x]


        // [ ][ ][x]
        // [ ][ ][ ]
        // [ ][ ][ ]

        primitiveList[3].Position = new Vector3(1 + startpos.X, 0, 1 + startpos.Z);
        primitiveList[3].TextureCoordinate.X = 1;
        primitiveList[3].TextureCoordinate.Y = 0;
        // [x][ ][ ]
        // [ ][ ][ ]
        // [ ][ ][ ]
        primitiveList[4].Position = new Vector3(0 + startpos.X, 0, 1 + startpos.Z);
        primitiveList[4].TextureCoordinate.X = 0;
        primitiveList[4].TextureCoordinate.Y = 0;

        // [ ][ ][ ]
        // [ ][ ][ ]
        // [x][ ][ ]
        primitiveList[5].Position = new Vector3(0 + startpos.X, 0, 0 + startpos.Z);
        primitiveList[4].TextureCoordinate.X = 0;
        primitiveList[4].TextureCoordinate.Y = 1;

及绘图代码:

        _graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

        foreach (var pass in effect.CurrentTechnique.Passes)
        {
            pass.Apply();
        }


        _graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, _terrainManager.TerrainVertices, 0, _terrainManager.TerrainVertices.Length / 3,VertexPositionNormalTexture.VertexDeclaration);

效果设置:

        if (effect == null)
        {
            effect = new BasicEffect(_graphics.GraphicsDevice);
            /*effect.CurrentTechnique = effect.Techniques ["BasicEffect_PixelLighting_Texture"];
            */

            effect.EnableDefaultLighting();
            effect.TextureEnabled = true;
            effect.Texture = _grassGrid;

            var state = new RasterizerState { MultiSampleAntiAlias = true };
            state.DepthBias = 100.0f;
            effect.GraphicsDevice.RasterizerState = state;

            /*foreach (var lol in effect.Techniques) 
            {
                Console.WriteLine (lol.Name);
            }*/
            //effect.CurrentTechnique = effect.Techniques ["BasicEffect_Texture"];

            _graphics.PreferMultiSampling = true;
            _graphics.GraphicsDevice.PresentationParameters.MultiSampleCount = 4;
            //_graphics.ApplyChanges ();

就是找不到问题出在哪里。至少在谷歌搜索/尝试错误 3 小时后。我还尝试了一些多重采样来包括在内。但这完全没有效果。我不知道只是猜测这里可能出了什么问题。我不需要解决方案(尽管那很好:))。一个提示会很棒。提前感谢您的帮助!

你这里有错字:

// [ ][ ][ ]
// [ ][ ][ ]
// [x][ ][ ]
primitiveList[5].Position = new Vector3(0 + startpos.X, 0, 0 + startpos.Z);
primitiveList[4].TextureCoordinate.X = 0;
primitiveList[4].TextureCoordinate.Y = 1;

primitiveList的索引应该都是5。 你的纹理坐标搞砸了,导致随机白线。