/// <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); } }
/// <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; if (mflicker) { step+=1; if (step % (phaseDuration + 30) == 0) { randFactor = random.Next(50)/30 + 0.8f; phaseDuration = (int)randFactor; if (step == 360) { step = 0; } } mIntensity = (float)Math.Sin((step * randFactor) / 20) * (originalIntensity/30) + originalIntensity; } // 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); } }
public void Draw( KryptonRenderHelper helper, IList <ShadowHull> shadowHulls) { if (!IsOn) { return; } // Make sure we only render the following shadowHulls helper.ShadowHullVertices.Clear(); helper.ShadowHullIndicies.Clear(); // Loop through each hull foreach (var hull in shadowHulls) { if (!hull.Visible) { continue; } if (!IsHullWithinRange(hull)) { continue; } helper.BufferAddShadowHull(hull); } // Set the effect and parameters helper.Effect.Parameters["LightPosition"] .SetValue(_position); helper.Effect.Parameters["Texture0"] .SetValue(Texture); helper.Effect.Parameters["LightIntensityFactor"] .SetValue(1 / (_intensity * _intensity)); switch (ShadowType) { 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 ArgumentOutOfRangeException( nameof(ShadowType), $"Shadow Type does not exist: {ShadowType}"); } 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( _position, Angle, Range * 2, Color, _fov); } helper.Effect.CurrentTechnique = helper.Effect.Techniques["ClearTarget_Alpha"]; foreach (var pass in helper.Effect.CurrentTechnique.Passes) { pass.Apply(); helper.GraphicsDevice.DrawUserPrimitives( PrimitiveType.TriangleStrip, KryptonRenderHelper.UnitQuad, vertexOffset: 0, primitiveCount: 2); } }
/// <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 (!isOn) return; // Make sure we only render the following hulls helper.ShadowHullVertices.Clear(); helper.ShadowHullIndicies.Clear(); // Loop through each hull foreach (var hull in hulls) { // Add the hulls to the buffer only if they are within the light's range if (hull.Visible && IsInRange(hull.Position - Position, hull.MaxRadius * Math.Max(hull.Scale.X, hull.Scale.Y) + Range)) { helper.BufferAddShadowHull(hull); } } // Set the effect and parameters helper.Effect.Parameters["LightPosition"].SetValue(position); helper.Effect.Parameters["Texture0"].SetValue(texture); helper.Effect.Parameters["LightIntensityFactor"].SetValue(1 / (intensity * intensity)); switch (shadowType) { 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: " + shadowType); } 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(position, angle, range * 2, color, fov); } helper.Effect.CurrentTechnique = helper.Effect.Techniques["ClearTarget_Alpha"]; foreach (var pass in helper.Effect.CurrentTechnique.Passes) { pass.Apply(); helper.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, Unit.Quad, 0, 2); } }