2012-11-26 3 views
1

질감이있는 모델을 표시하는 데 문제가 있습니다. 모든 것이 완벽하게 작동하지만, 루프를 사용하여 텍스처를 반복하여 화면에서 바닥 20 X 20을 나타냅니다. 내 텍스처가 올바르게 반복됩니다. 그러나 왜 모든 텍스처가 깜박임을 발생시키는 지 이해할 수 없습니다 ... 나는 이미지가 서로 겹쳐있는 것을 발견했습니다. 루프가 올바르게 코딩되었는지 확인했습니다.내 xna 프로젝트에서 내 이미지가 왜 깜박입니까?

페이지의 스크린 샷 : enter image description here

내 코드 (루프 기능 생성 접지) :

//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; 
    } 

당신의 도움에 미리 감사드립니다. 인내심을 잃어 버린다. (주말 내내^^)

+3

[z-fighting] (http://en.wikipedia.org/wiki/Z-fighting)와 유사합니다. – CodeCaster

+0

감사합니다.이 문제를 알지 못했습니다. 방금 "XNA"를 시작했습니다. 이것을 피하기 위해 무엇을 권하고 싶습니까? Z- 파이팅을 어떻게 설정 하시겠습니까? 대단히 감사합니다. –

+1

링크에서 : _ "Z- 파이팅은 더 높은 해상도의 깊이 버퍼를 사용하거나, 일부 시나리오에서 z 버퍼링을 사용하거나, 단순히 다각형을 멀리 떨어지게하여 줄일 수 있습니다."_ 같은 장소에 너무 많은 다각형이있는 것 같습니다. – CodeCaster

답변

2

그것은 Z 싸움이다. 멀리 떨어진 Z- 버퍼 정밀도 오브젝트는 "깜박임"이 더 많습니다. GPU는 z- 버퍼 값의 꼬리가 2 개의 거의 동일한 값을 구별하기에 정확하지 않기 때문에 상단에있는 폴리곤을 파악할 수 없습니다.

당신은 그것을 해결하기 위해 6 가지 방법이 있습니다

  1. 이동 형상을 이하이다 부분을 표시하지 않습니다. polygon offset in OpenGL

  2. 사용 CPU를 대신 Z 버퍼의 Z-정렬 등

  3. 사용 무언가.

  4. 만 사용하는 대신 + 일부 쉐이더 (난 당신이 달성하기 위해 노력하고 정확히 모르는)

  5. 를 사용하여 더 큰 z 버퍼 2 객체의 2 개 텍스처를 하나의 객체.

  6. 클립면을 서로 가깝게 움직이면 정밀도가 높아집니다.

+0

오우 확인. 이 설명을 해주셔서 감사하지만 형상을 어떻게 움직입니까? 죄송 해요 전 xna에서 멍청한 녀석이에요. 나는 이것을 테스트했다 : DepthStencilState depthState = new DepthStencilState(); depthState.DepthBufferEnable = true; depthState.DepthBufferWriteEnable = true; GraphicsDevice.DepthStencilState = depthState; 하지만 작동하지 않습니다. –

+0

@MehdiBugnard는 깜박 거리기가 사라질 때까지 겹치는 오브젝트 중 하나를 조금 움직입니다. – JAre

+0

좋아, 이걸 시험해 볼거야. 다시 감사합니다 . 나는 나의 결과에 대해 이야기하기 위해 돌아왔다. –