Seeing It Through Ep 4: Lighting 5

Subscribe to the podcast here.

In this episode of Seeing It Through I make my first appearance to talk about lighting and how we are thinking of implementing it in Unity3D and the Flatland universe.

Unfortunately Unity3D is a 3D engine and as such does not support nice, optimised 2D lighting out of the box. Unity3D does have its own point lights which can cast shadows but only using deferred rendering, and only using a perspective view, not the orthographic view used in 2D games. Also the technique used to calculate the shadows (shadow mapping), is much too complex to be used for just 2D.

Snapshot of the guards dynamic view mesh

We also mention how we quickly got a nice view cone effect that would collide with objects in the scene using existing shape building tools.

Our Shape Tools

The Question

Do you know of any games that have done two dimensional lighting well or used it in an interesting way?

 

Your Thoughts

so far

5 thoughts on “Seeing It Through Ep 4: Lighting

  1. Conan Jun 12, 2012 9:14 pm

    One potential way to do lighting/view-cones similar to your way would be to instead have the world built with portals and convex cells, and then use techniques similar to portal rendering to create your view cones.
    Would reduce your rays, but not sure how easy it would be for you to modify your world in that way.

  2. Jez Jun 13, 2012 1:42 am

    I don’t think you need all those ray casts and you can miss some bits like between 35 and 36, you’re limited by the number of ray casts.

    But since you know where the interesting points are you can just cast to those, that way you don’t miss anything.

    http://www.java-gaming.org/index.php/topic,21301.0
    http://code.google.com/p/straightedge/
    Uses this algorithm quite nicely.

    Make an empty list of points
    Add all polygon points that have an unobstructed line to the eye (or light source)
    Add all polygon intersection points that have an unobstructed line to the eye
    Add all points on the sight polygon (or field of view) that have an unobstructed line to the eye
    Sort the list by the angle of each point relative to the eye, from the x-axis
    Search through the points and find any polygon points that are ‘end points’ which would cast a shadow.
    Cast a ray from these points away from the eye, and find the intersection of this ray with the nearest polygon or the nearest edge of the sight polygon.
    Add the intersection to the list, before or after the ‘end point’ depending on which side the end point is on.

    • Thomas Bowker Jun 13, 2012 7:35 am

      Yep, that’s close to the way I wanted to optimize this. The implementation in the post was a hacky one for sure, but we’re only targeting PC right now so wasn’t that bad on performance.
      I’ll hopefully have time next week to flesh this stuff out.

      Thanks for you post I hadn’t seen that exact code before.

  3. Paul Sztajer Jun 13, 2012 8:47 am

    Ahh, so this is why we usually put more detail into the blog post and don’t just leave it all in the podcast…