2012-01-04 3 views
1

3D 그래픽을 사용하여 XNA 게임을 만들고 싶습니다. 궁금한 점이 하나 있습니다. 내 장면에 1Model 초가 있다고 가정 해 봅시다. 방향 조명과 같은 광원으로 모두 그려야합니다. 이제 Model에는 Effect이 있고 Effect에는 조명 정보가 있다는 것을 알고 있습니다. 내 질문은, 내가 어떻게 자신의 광원을 가지고 각 모델 대신에, 내 장면에있는 모든 모델에 동일한 광원을 적용할까요? 누군가 내가 기지에서 멀어 졌는지 말해.XNA - 3D 게임 - 모든 모델에 조명 적용

+0

따라서 더 나은 응답을 얻을 수 있습니다. http://gamedev.stackexchange.com –

답변

1

XNA 4.0을 사용하여 게임을 만드는 경우 효과를 사용해야합니다. 다행히도 XNA 팀에는 BasicEffect라고하는 강력하면서도 간단한 효과가 포함되었습니다. 달리 지정하지 않는 한 BasicEffect는 모델을 렌더링 할 때 사용되는 기본 효과입니다. BasicEffect는 최대 3 방향 라이트를 지원합니다. 아래 샘플 코드는 BasicEffect 인스턴스를 조작하여 지향성 광원을 사용하여 렌더링하는 방법에 대한 아이디어를 제공합니다.

public void DrawModel(Model myModel, float modelRotation, Vector3 modelPosition, 
         Vector3 cameraPosition 
    ) { 
    // Copy any parent transforms. 
    Matrix[] transforms = new Matrix[myModel.Bones.Count]; 
    myModel.CopyAbsoluteBoneTransformsTo(transforms); 

    // Draw the model. A model can have multiple meshes, so loop. 
    foreach (ModelMesh mesh in myModel.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(modelRotation) * 
          Matrix.CreateTranslation(modelPosition); 
      effect.View = Matrix.CreateLookAt(cameraPosition, 
          Vector3.Zero, Vector3.Up); 
      effect.Projection = Matrix.CreatePerspectiveFieldOfView(
            MathHelper.ToRadians(45.0f), 1.333f, 
            1.0f, 10000.0f); 
      effect.LightingEnabled = true; // turn on the lighting subsystem. 
      effect.DirectionalLight0.DiffuseColor = new Vector3(0.5f, 0, 0); // a red light 
      effect.DirectionalLight0.Direction = new Vector3(1, 0, 0); // coming along the x-axis 
      effect.DirectionalLight0.SpecularColor = new Vector3(0, 1, 0); // with green highlights 
     } 
     // Draw the mesh, using the effects set above. 
     mesh.Draw(); 
    } 
} 
+0

기본적으로 모델의 조명을 수정하여 모델의 조명을 무시합니까? 나는 괜찮아. –