Skip to content

Instantly share code, notes, and snippets.

@hunterloftis
Last active February 24, 2020 23:07
Show Gist options
  • Save hunterloftis/69f54b24d5ba9e30f20771b8b7c30b2e to your computer and use it in GitHub Desktop.
Save hunterloftis/69f54b24d5ba9e30f20771b8b7c30b2e to your computer and use it in GitHub Desktop.

3 Ways to design the lightmap API

The purpose of the module is to create and update path-traced 2D lightmaps. For example, to create interesting dynamic top-down lighting in a 2D game.

Option 1: Trace on lightmap

lm := lightmap.New(image.Rect(0, 0, 100, 100))
light := lightmap.Light{
    RGBA: color.RGBA{255, 214, 170, 255},
    Range: 10,
    Falloff: 1.1,
}

lm.Trace(20, 25, light, 90) // x, y, light, nRays

Option 2: Trace on light

lm := lightmap.New(image.Rect(0, 0, 100, 100))
light := lightmap.Light{
    RGBA: color.RGBA{255, 214, 170, 255},
    Range: 10,
    Falloff: 1.1,
}

light.Trace(lm, 20, 25, 90) // lightmap, x, y, nRays

Option 3: Trace on package

lm := lightmap.New(image.Rect(0, 0, 100, 100))
light := lightmap.Light{
    RGBA: color.RGBA{255, 214, 170, 255},
    Range: 10,
    Falloff: 1.1,
}

lightmap.Trace(lm, 20, 25, light, 90)   // lightmap, x, y, light, nRays
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment