/// <summary> /// インスタンスを生成します。 /// </summary> /// <param name="device">デバイス。</param> /// <param name="shadowMapEffect">シャドウ マップ エフェクト。</param> public ShadowMap(GraphicsDevice device, ShadowMapEffect shadowMapEffect) { if (device == null) throw new ArgumentNullException("device"); GraphicsDevice = device; this.shadowMapEffect = shadowMapEffect; }
// コールバック。 void DrawShadowCasters(Matrix eyeView, Matrix eyeProjection, ShadowMapEffect effect) { Matrix viewProjection; Matrix.Multiply(ref eyeView, ref eyeProjection, out viewProjection); currentFrustum.Matrix = viewProjection; ContainmentType containment; currentFrustum.Contains(ref dudeBoxWorld, out containment); if (containment != ContainmentType.Disjoint) { DrawShadowCaster(effect, dudeModel); } }
void DrawShadowCaster(ShadowMapEffect effect, Model model) { // シャドウ マップ エフェクトの準備。 effect.World = world; effect.Apply(); foreach (var mesh in model.Meshes) { foreach (var meshPart in mesh.MeshParts) { GraphicsDevice.SetVertexBuffer(meshPart.VertexBuffer); GraphicsDevice.Indices = meshPart.IndexBuffer; GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, meshPart.VertexOffset, 0, meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount); } } }
protected override void LoadContent() { shadowMapEffect = new ShadowMapEffect(Content.Load<Effect>("ShadowMap")); gaussianBlurEffect = Content.Load<Effect>("GaussianBlur"); drawModelEffect = new DrawModelEffect(Content.Load<Effect>("DrawModel")); drawModelEffect.AmbientColor = new Vector4(0.15f, 0.15f, 0.15f, 1.0f); drawModelEffect.DepthBias = 0.001f; drawModelEffect.LightDirection = lightDirection; drawModelEffect.ShadowColor = new Vector3(0.5f, 0.5f, 0.5f); spriteBatch = new SpriteBatch(GraphicsDevice); spriteFont = Content.Load<SpriteFont>("hudFont"); gridModel = Content.Load<Model>("grid"); dudeModel = Content.Load<Model>("dude"); dudeBoxLocal = BoundingBoxHelper.Empty; foreach (var mesh in dudeModel.Meshes) { BoundingBoxHelper.Merge(ref dudeBoxLocal, BoundingBox.CreateFromSphere(mesh.BoundingSphere)); } for (int i = 0; i < shadowMaps.Length; i++) { shadowMaps[i] = new ShadowMap(GraphicsDevice, shadowMapEffect); } }