/// <summary> /// Draws the light with shadows from the hulls /// </summary> /// <param name="lightmapEffect">The lightmap effect.</param> /// <param name="helper">The helper.</param> /// <param name="hulls">The hulls.</param> public void Draw(LightmapEffect lightmapEffect, ILightmapPass lightmapPass, ILightmapDrawBuffer helper, IEnumerable<IHull> hulls) { lightmapEffect.Effect.GraphicsDevice.ScissorRectangle = lightmapPass.GetScissor(this); // lightmapEffect.Effect.GraphicsDevice.ScissorRectangle = new Rectangle(0, 0, 200, 200); // 1) Clear hull buffers helper.Clear(); // 2) Prepare to draw hulls foreach (var hull in hulls.Where(x => Vector2.DistanceSquared(this.Position, x.Position) < this.RadiusSquared + x.RadiusSquared)) { hull.Draw(helper); } // 3) Set lightmapEffect stuff lightmapEffect.LightPosition = this.Position; lightmapEffect.LightTexture = this.Texture; lightmapEffect.LightInesityFactor = this.IntensityFactor; switch (this.ShadowType) { case ShadowType.Illuminated: lightmapEffect.CurrentTechnique = lightmapEffect.IlluminatedShadowTechnique; break; case ShadowType.Occluded: lightmapEffect.CurrentTechnique = lightmapEffect.OccludedShadowTechnique; break; default: lightmapEffect.CurrentTechnique = lightmapEffect.SolidShadowTechnique; break; } // 4) Draw hulls for each shadow pass foreach (var pass in lightmapEffect.CurrentTechnique.Passes) { pass.Apply(); helper.Draw(); } // 5) Draw light for each light pass lightmapEffect.CurrentTechnique = lightmapEffect.LightTechnique; foreach (var pass in lightmapEffect.CurrentTechnique.Passes) { pass.Apply(); helper.DrawClippedFov(this.Position, this.Rotation, this.Radius * 2, this.Color, this.Fov); } // 6) Clear the target's alpha chanel lightmapEffect.CurrentTechnique = lightmapEffect.AlphaClearTechnique; //lightmapEffect.Effect.GraphicsDevice.ScissorRectangle = lightmapEffect.Effect.GraphicsDevice.Viewport.Bounds; foreach (var pass in lightmapEffect.CurrentTechnique.Passes) { pass.Apply(); helper.DrawUnitQuad(); } }