zero's a life

An extra chance.

Raycast Lighting in Skytorn

| Comments

@NoelFB posted a screenshot showing how dynamic lighting works in Skytorn.

The algorithm

From what I can tell, the algorithm looks something like this:

  1. Raycast out for 360° around the light source, starting in a clockwise direction. If the rays encounter a collidable object, add it to the list of pink lines defining the polygonal shape of the lit area. If the ray exceeds the distance of the light gradient, clamp the triangle edge defining the pink line at that distance.

  2. For each of the collidable objects encountered, extend a ray past their vertices until it hits another collidable to create the obscured lighting effect visible to down and to the right of the light source.

  3. Finally construct a set of triangles by starting from the closest edge in the list defining the pink lines to form the polygon.

That’s all

That’s it for this week. Let me know if you have any insight into this or other lighting algorithms in the comments or on the tweets.


After some feedback from @NoelFB, I’ve updated the algorithm in the following post.