【问题标题】:Why my Images flickers in my xna project?为什么我的图像在我的 xna 项目中闪烁?
【发布时间】:2012-11-26 10:49:54
【问题描述】:

我的模型在显示纹理时遇到了一些问题。 一切都很完美,但是,我使用循环来重复纹理以在屏幕上表示 20 X 20 的地板。我的纹理重复正确。但我不明白为什么我所有的纹理都会产生闪烁...... 我注意到图像是相互叠加的。我确定我检查了我的循环编码是否正确。

看截图:

我的代码(循环函数生成地):

//Function draw - ground land
    private void draw_groundLand(Vector3 position_model_origin)
    {
        //example generation mode 4x4 cubes
        int[,,] MatriceWorldCube = new int[1,2,2];
        MatriceWorldCube[0, 0, 0] = 1;
        MatriceWorldCube[0, 0, 1] = 1;
        MatriceWorldCube[0, 1, 0] = 2;
        MatriceWorldCube[0, 1, 1] = 1;

        int height = MatriceWorldCube.GetLength(0);
        int width = MatriceWorldCube.GetLength(1);
        int length = MatriceWorldCube.GetLength(2);

        Vector3 pos_reference = position_model_origin;

        for (int thickness = 0; thickness < height; thickness ++)
        {

            for (int column = 0; column < width; column ++)
            {

                for (int line = 0; line < length ; line ++)
                {


                        // Copy any parent transforms.
                        Matrix[] transforms = new Matrix[model_ground_land1.Bones.Count];
                        model_ground_land1.CopyAbsoluteBoneTransformsTo(transforms);

                        // Draw the model. A model can have multiple meshes, so loop.
                        foreach (ModelMesh mesh in model_ground_land1.Meshes)
                        {
                            // This is where the mesh orientation is set, as well 
                            // as our camera and projection.
                            foreach (BasicEffect effect in mesh.Effects)
                            {
                                effect.EnableDefaultLighting();
                                effect.World = transforms[mesh.ParentBone.Index]  *
                            Matrix.CreateRotationY(cubeGroundLand1_modelRotation) * Matrix.CreateTranslation(position_model_origin);
                                effect.View = View;
                                effect.Projection = Projection;


                            }

                            // Draw the mesh, using the effects set above.
                            mesh.Draw();
                        }



                    position_model_origin.X = (float)(line +1);
                }
                position_model_origin.X = pos_reference.X;
                position_model_origin.Z = (float)(column +1);

            }
            position_model_origin.Z = pos_reference.Z;
            position_model_origin.Y = (float)(thickness+1);

        }
        position_model_origin.Y = pos_reference.Y;
        position_model_origin = pos_reference;
    }

提前感谢您的帮助。我失去了耐心(整个周末^ ^)

【问题讨论】:

  • 看起来像z-fighting。
  • 好的,谢谢,我不知道这个问题。我刚刚开始使用“XNA”。你有什么建议来避免这种情况?请问Z-fighting怎么设置?非常感谢。
  • 来自链接:“Z-fighting 可以通过使用更高分辨率的深度缓冲区、在某些情况下通过 z-buffering 或简单地将多边形移得更远来减少”。看起来你在同一个地方有太多多边形。

标签: c# 3d xna mesh vertex


【解决方案1】:

这是 Z 战斗。 Z-buffer 精度随距离下降到目前为止对象有更多“闪烁”GPU 无法确定哪个多边形在顶部,因为 z-buffer 值的尾部不够精确,无法区分 2 个几乎相等的值。

你有 6 种方法来解决它:

  1. 移动几何图形或不显示下方的部分。

  2. 使用类似polygon offset in OpenGL

  3. 使用 CPU z-sorting 而不是 z-buffer。

  4. 仅使用一个具有 2 个纹理的对象,而不是 2 个对象 + 一些着色器(我不知道您到底想要实现什么)

  5. 使用更大的 z 缓冲区。

  6. 将剪裁平面彼此靠近,这将提高精度。

【讨论】:

  • 哦,好的。非常感谢您的解释,但是如何移动几何? ...对不起,我是 xna 的菜鸟。我对此进行了测试: DepthStencilState depthState = new DepthStencilState(); depthState.DepthBufferEnable = true; depthState.DepthBufferWriteEnable = true; GraphicsDevice.DepthStencilState = depthState;但它不工作
  • @MehdiBugnard 只需稍微移动一个重叠的对象,直到闪烁消失。
  • 好的,我要试试这个。再次感谢你 。我回来谈论我的结果
  • 非常感谢。多亏了你,我的问题解决了!我只有一个可以稍后分开我的立方体,结果完美无缺^。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-13
  • 2013-05-17
  • 1970-01-01
  • 1970-01-01
  • 2018-10-22
相关资源
最近更新 更多