【发布时间】: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 或简单地将多边形移得更远来减少”。看起来你在同一个地方有太多多边形。