/// <summary> /// Draws shadows from the light's position outward /// </summary> /// <param name="helper">A render helper for drawing shadows</param> /// <param name="hulls">The shadow hulls used to draw shadows</param> public void Draw(KryptonRenderHelper helper, List <ShadowHull> hulls) { // Draw the light only if it's on if (!this.mIsOn) { return; } // Make sure we only render the following hulls helper.ShadowHullVertices.Clear(); helper.ShadowHullIndicies.Clear(); // Loop through each hull foreach (ShadowHull hull in hulls) { //if(hull.Bounds.Intersects(this.Bounds)) // Add the hulls to the buffer only if they are within the light's range if (hull.Visible && Light2D.IsInRange(hull.Position - this.Position, hull.MaxRadius * Math.Max(hull.Scale.X, hull.Scale.Y) + this.Range)) { helper.BufferAddShadowHull(hull); } } var shadowEffect = helper.Effect.Techniques["PointLight_Shadow_Fast"]; helper.Effect.CurrentTechnique = shadowEffect; // Set the effect parameters helper.Effect.Parameters["LightPosition"].SetValue(this.mPosition); helper.Effect.Parameters["Texture0"].SetValue(this.mTexture); helper.Effect.Parameters["LightIntensityFactor"].SetValue(1 / (this.mIntensity * this.mIntensity)); shadowEffect.Passes["ShadowStencil"].Apply(); helper.BufferDraw(); shadowEffect.Passes["Light"].Apply(); helper.DrawClippedFov(this.mPosition, this.mAngle, this.mRange * 2, this.mColor, this.mFov); }
/// <summary> /// Draws shadows from the light's position outward /// </summary> /// <param name="helper">A render helper for drawing shadows</param> /// <param name="hulls">The shadow hulls used to draw shadows</param> public void Draw(KryptonRenderHelper helper, List <ShadowHull> hulls) { // Draw the light only if it's on if (!this.mIsOn) { return; } // Make sure we only render the following hulls helper.ShadowHullVertices.Clear(); helper.ShadowHullIndicies.Clear(); // Loop through each hull foreach (ShadowHull hull in hulls) { //if(hull.Bounds.Intersects(this.Bounds)) // Add the hulls to the buffer only if they are within the light's range if (hull.Visible && Light2D.IsInRange(hull.Position - this.Position, hull.MaxRadius * Math.Max(hull.Scale.X, hull.Scale.Y) + this.Range)) { helper.BufferAddShadowHull(hull); } } // Set the effect and parameters helper.Effect.Parameters["LightPosition"].SetValue(this.mPosition); helper.Effect.Parameters["Texture0"].SetValue(this.mTexture); helper.Effect.Parameters["LightIntensityFactor"].SetValue(1 / (this.mIntensity * this.mIntensity)); switch (this.mShadowType) { case (ShadowType.Solid): helper.Effect.CurrentTechnique = helper.Effect.Techniques["PointLight_Shadow_Solid"]; break; case (ShadowType.Illuminated): helper.Effect.CurrentTechnique = helper.Effect.Techniques["PointLight_Shadow_Illuminated"]; break; case (ShadowType.Occluded): helper.Effect.CurrentTechnique = helper.Effect.Techniques["PointLight_Shadow_Occluded"]; break; default: throw new NotImplementedException("Shadow Type does not exist: " + this.mShadowType); } foreach (var pass in helper.Effect.CurrentTechnique.Passes) { pass.Apply(); helper.BufferDraw(); } helper.Effect.CurrentTechnique = helper.Effect.Techniques["PointLight_Light"]; foreach (var pass in helper.Effect.CurrentTechnique.Passes) { pass.Apply(); helper.DrawClippedFov(this.mPosition, this.mAngle, this.mRange * 2, this.mColor, this.mFov); } helper.Effect.CurrentTechnique = helper.Effect.Techniques["ClearTarget_Alpha"]; foreach (var pass in helper.Effect.CurrentTechnique.Passes) { pass.Apply(); helper.GraphicsDevice.DrawUserPrimitives <VertexPositionTexture>(PrimitiveType.TriangleStrip, KryptonRenderHelper.UnitQuad, 0, 2); } }