/// <summary> /// Draws a mesh with a shadow map drawer /// </summary> /// <param name="effect">Effect</param> /// <param name="drawingData">Drawing data</param> /// <param name="meshName">Mesh name</param> /// <param name="index">Instance buffer index</param> /// <param name="length">Instance buffer length</param> /// <returns>Returns the number of drawn triangles</returns> private int DrawMeshShadow(IShadowMapDrawer effect, DrawingData drawingData, string meshName, int index, int length) { int count = 0; var graphics = this.Game.Graphics; var meshDict = drawingData.Meshes[meshName]; foreach (string materialName in meshDict.Keys) { var mesh = meshDict[materialName]; var material = drawingData.Materials[materialName]; count += mesh.IndexBuffer.Count > 0 ? mesh.IndexBuffer.Count / 3 : mesh.VertexBuffer.Count / 3; effect.UpdatePerObject(0, material, 0); this.BufferManager.SetIndexBuffer(mesh.IndexBuffer.Slot); var technique = effect.GetTechnique(mesh.VertextType, true, material.Material.IsTransparent); this.BufferManager.SetInputAssembler(technique, mesh.VertexBuffer.Slot, mesh.Topology); for (int p = 0; p < technique.PassCount; p++) { graphics.EffectPassApply(technique, p, 0); mesh.Draw(graphics, index, length); } } return(count); }
/// <summary> /// Draws the scenery patch shadows /// </summary> /// <param name="sceneryEffect">Scenery effect</param> /// <param name="bufferManager">Buffer manager</param> public void DrawSceneryShadows(IShadowMapDrawer sceneryEffect, BufferManager bufferManager) { var graphics = this.Game.Graphics; foreach (string meshName in this.DrawingData.Meshes.Keys) { var meshDict = this.DrawingData.Meshes[meshName]; foreach (string materialName in meshDict.Keys) { var mesh = meshDict[materialName]; var material = this.DrawingData.Materials[materialName]; var technique = sceneryEffect.GetTechnique(mesh.VertextType, false, material.Material.IsTransparent); sceneryEffect.UpdatePerObject(0, material, 0); bufferManager.SetIndexBuffer(mesh.IndexBuffer.Slot); bufferManager.SetInputAssembler(technique, mesh.VertexBuffer.Slot, mesh.Topology); for (int p = 0; p < technique.PassCount; p++) { graphics.EffectPassApply(technique, p, 0); mesh.Draw(graphics); } } } }
/// <summary> /// Draws a mesh shadow /// </summary> /// <param name="context">Context</param> /// <param name="effect">Effect</param> /// <param name="meshName">Mesh name</param> /// <returns>Returns the number of drawn triangles</returns> private int DrawMeshShadow(DrawContextShadows context, IShadowMapDrawer effect, string meshName) { int count = 0; var graphics = this.Game.Graphics; var meshDict = this.DrawingData.Meshes[meshName]; var localTransform = this.GetTransformByName(meshName); effect.UpdatePerFrame(localTransform, context); foreach (string materialName in meshDict.Keys) { var mesh = meshDict[materialName]; var material = this.DrawingData.Materials[materialName]; effect.UpdatePerObject(this.AnimationOffset, material, this.TextureIndex); this.BufferManager.SetIndexBuffer(mesh.IndexBuffer.Slot); var technique = effect.GetTechnique(mesh.VertextType, false, material.Material.IsTransparent); this.BufferManager.SetInputAssembler(technique, mesh.VertexBuffer.Slot, mesh.Topology); count += mesh.IndexBuffer.Count > 0 ? mesh.IndexBuffer.Count / 3 : mesh.VertexBuffer.Count / 3; for (int p = 0; p < technique.PassCount; p++) { graphics.EffectPassApply(technique, p, 0); mesh.Draw(graphics); } } return(count); }