Skip to content

Commit

Permalink
[Penumbra] Mark light dirty when ignored hull collection changed
Browse files Browse the repository at this point in the history
  • Loading branch information
discosultan committed Feb 12, 2017
1 parent 1115be3 commit df52dd3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Source/Graphics/Renderers/ShadowRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void Dispose()
continue;
}

Polygon points = hull.WorldPoints;
Polygon points = hull.WorldPoints;

Vector2 prevPoint = points[points.Count - 1];

Expand Down
32 changes: 21 additions & 11 deletions Source/Light.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Penumbra.Geometry;
Expand All @@ -20,9 +21,18 @@ public abstract class Light
{
private const float Epsilon = 1e-5f;

private readonly ObservableCollection<Hull> _ignoredHulls = new ObservableCollection<Hull>();
// Used privately to determine when to calculate world transform and bounds.
private bool _worldDirty = true;

/// <summary>
/// Initializes a new instance of the <see cref="Light"/> class.
/// </summary>
protected Light()
{
_ignoredHulls.CollectionChanged += (s, e) => Dirty = true;
}

/// <summary>
/// Gets or sets if the light is enabled and should be rendered.
/// </summary>
Expand Down Expand Up @@ -124,7 +134,7 @@ public Vector2 Scale
}
}
}

private Color _nonPremultipliedColor = Color.White;
private Vector3 _color = Vector3.One;
/// <summary>
Expand All @@ -140,7 +150,7 @@ public Color Color
Calculate.FromNonPremultiplied(value, out _color);
}
}

private float _intensity = 1.0f;
/// <summary>
/// Gets or sets the intensity of the color applied to the final scene.
Expand Down Expand Up @@ -180,8 +190,8 @@ public float Radius
Dirty = true;
}
}
}
}

/// <summary>
/// Gets or sets how the shadow <see cref="Hull"/>s are shadowed. See
/// <see cref="ShadowType"/> for more information.
Expand All @@ -191,14 +201,14 @@ public float Radius
/// <summary>
/// Gets a list of hulls not participating in the light's shadow casting process.
/// </summary>
public List<Hull> IgnoredHulls { get; } = new List<Hull>();
public IList<Hull> IgnoredHulls => _ignoredHulls;

// Cleared by the engine. Used by other systems to know if the light's world transform has changed.
// Cleared by the engine. Used by other systems to know when to regenerate shadows for the light.
internal bool Dirty;

internal BoundingRectangle Bounds;

internal Matrix LocalToWorld;
internal Matrix LocalToWorld;

internal virtual EffectTechnique ApplyEffectParams(LightRenderer renderer)
{
Expand Down Expand Up @@ -232,18 +242,18 @@ private void CalculateBounds()
Vector2.Multiply(ref _origin, ref _scale, out min);
Vector2.Subtract(ref _position, ref min, out min);

Vector2 max;
Vector2 max;
Vector2.Add(ref min, ref _scale, out max);

Bounds = new BoundingRectangle(min, max);
}
else
{
{
var bounds = new BoundingRectangle(Vector2.Zero, Vector2.One);
BoundingRectangle.Transform(ref bounds, ref LocalToWorld, out Bounds);
}
}
}
}

/// <summary>
/// Determines how the shadows cast by the light affect shadow <see cref="Hull"/>s.
Expand All @@ -257,7 +267,7 @@ public enum ShadowType
/// <summary>
/// Shadow hulls are not lit by the light.
/// </summary>
Solid,
Solid,
/// <summary>
/// Occluded shadow hulls (hulls behind other hulls) are not lit.
/// </summary>
Expand Down

0 comments on commit df52dd3

Please sign in to comment.