Shadows
namespace Griff.Runtime;
public static class ShadowsWhat blocks the light of a Light with Shadows on: solid tiles (slopes included, and hex maps’ hexagons) and solid colliders (boxes, circles and polygons, as they’re turned). Triggers, one-way platforms, background, ladder and one-way tiles let light through.
Methods
Section titled “Methods”AddCasters
Section titled “AddCasters”public static void AddCasters(ReadOnlySpan<ShadowEdge> edges, Light light, List<ShadowEdge> casters)Adds the sides of edges that cast light’s shadows to casters, as CastersFor picks them, making no garbage once it has room for them.
AddEdges
Section titled “AddEdges”public static void AddEdges(Scene scene, List<ShadowEdge> edges)Adds every side of everything in the scene that blocks light to edges: the solid tilemaps’ tiles, then the colliders, each in hierarchy order. Once edges has room for them it makes no garbage, so a dark scene’s frame can work them out afresh each time.
CastersFor
Section titled “CastersFor”public static List<ShadowEdge> CastersFor(IReadOnlyList<ShadowEdge> edges, Light light)The sides that cast light’s shadows: those within its reach facing away from it, leaving out the light’s own entity (a lantern’s holder) and anything the light is inside (a torch set into a wall).
public static List<ShadowEdge> Edges(Scene scene)Every side of everything in the scene that blocks light.
Reaches
Section titled “Reaches”public static bool Reaches(IReadOnlyList<ShadowEdge> casters, Vector2 light, Vector2 point)True if nothing in casters stands between light and point.
Shadow
Section titled “Shadow”public static ValueTuple<Vector2, Vector2, Vector2, Vector2, Vector2> Shadow(ShadowEdge edge, Vector2 light, float reach)The shadow edge casts from light as a polygon, in order round it: the side’s two ends, then points reach beyond its far end, its middle and its near end. The middle point keeps the far side from cutting back towards a light right next to a long side; reach twice the light’s radius always covers the rest of the light.