Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我的图像在我的xna项目中闪烁?_C#_3d_Xna_Mesh_Vertex - Fatal编程技术网

C# 为什么我的图像在我的xna项目中闪烁?

C# 为什么我的图像在我的xna项目中闪烁?,c#,3d,xna,mesh,vertex,C#,3d,Xna,Mesh,Vertex,我在使用纹理显示模型时遇到一些问题。 一切都很完美,但是,我使用一个循环来重复纹理,在屏幕上表示一个20 X 20的地板。我的纹理重复正确。但我不明白为什么我所有的纹理都会产生闪烁。。。 我注意到图像相互叠加。我肯定我检查了我的循环是否正确编码 请参见屏幕截图: 我的代码(循环函数生成接地): //功能图-地面 私人空旷地(矢量3位置模型原点) { //示例生成模式4x4立方体 int[,]MatriceWorldCube=新的int[1,2,2]; MatriceWorldCube[0,0,

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

请参见屏幕截图:

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

//功能图-地面
私人空旷地(矢量3位置模型原点)
{
//示例生成模式4x4立方体
int[,]MatriceWorldCube=新的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);
矢量3位置参考=位置模型原点;
对于(int厚度=0;厚度<高度;厚度++)
{
for(int column=0;column

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

这是一场激战。Z缓冲区的精度随着距离的增加而下降。到目前为止,对象有更多的“闪烁”,GPU无法确定哪个多边形在顶部,因为Z缓冲区值的尾部不够精确,无法区分两个几乎相等的值

您有6种修复方法:

  • 移动几何图形或不显示下面的零件

  • 使用类似

  • 使用CPU z排序而不是z缓冲区

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

  • 使用较大的z缓冲区

  • 将剪辑平面彼此移近,将提高精度


  • 看起来像。好的,谢谢。我不知道这个问题。我刚刚开始学习XNA。你有什么建议来避免这种情况?请问如何设置Z字型?非常感谢。在链接中:“通过使用更高分辨率的深度缓冲区,在某些情况下通过Z缓冲,或者简单地将多边形移动得更远,可以减少Z战斗”。看起来你在同一个地方有太多的多边形了。非常感谢您的解释,但如何移动几何体。。。对不起,我是新华社的noob。我已经测试过了:DepthStencilState depthState=new DepthStencilState();depthState.DepthBufferEnable=true;depthState.DepthBufferWriteEnable=true;GraphicsDevice.DepthStencilState=depthState;但事实并非如此working@MehdiBugnard只需移动一个重叠的对象,直到闪烁消失。好的,我要试试这个。再次感谢你。我回来谈我的成绩,非常感谢。多亏了你,我的问题解决了!我只有一个可以稍后分离我的多维数据集,这里是结果完美的^。
    //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;
        }