{"id":13525621,"url":"https://github.com/speakk/lighter","last_synced_at":"2025-04-12T08:23:18.222Z","repository":{"id":56292853,"uuid":"312410005","full_name":"speakk/lighter","owner":"speakk","description":"A Löve light/shadow library","archived":false,"fork":false,"pushed_at":"2023-09-02T05:42:17.000Z","size":181,"stargazers_count":38,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-26T03:33:12.193Z","etag":null,"topics":["dynamic-lighting","lighting","love2d","love2d-framework"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/speakk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-11-12T22:22:13.000Z","updated_at":"2025-01-23T18:51:46.000Z","dependencies_parsed_at":"2024-01-03T04:02:34.624Z","dependency_job_id":null,"html_url":"https://github.com/speakk/lighter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speakk%2Flighter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speakk%2Flighter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speakk%2Flighter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speakk%2Flighter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/speakk","download_url":"https://codeload.github.com/speakk/lighter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248537951,"owners_count":21120917,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dynamic-lighting","lighting","love2d","love2d-framework"],"created_at":"2024-08-01T06:01:20.460Z","updated_at":"2025-04-12T08:23:18.204Z","avatar_url":"https://github.com/speakk.png","language":"Lua","funding_links":[],"categories":["Lighting"],"sub_categories":[],"readme":"# Lighter\n\nA dynamic light / shadow casting library for Löve.\n\n## Installation\nClone the repo into your libs directory and require with \n\n    require 'path.to.lighter'\n\n## Usage\n    local Lighter = require 'path.to.lighter'\n\n    local lighter = Lighter()\n\n    local wall = {\n        100, 100,\n        300, 100,\n        300, 300,\n        100, 300\n    }\n\n    lighter:addPolygon(wall)\n\n    local lightX, lightY = 500, 500\n\n    -- addLight signature: (x,y,radius,r,g,b,a)\n    local light = lighter:addLight(lightX, lightY, 500, 1, 0.5, 0.5)\n\n    function love.update(dt)\n        lightX, lightY = love.mouse.getPosition()\n        lighter:updateLight(light, lightX, lightY)\n    end\n\n    function love.draw()\n        love.graphics.polygon('fill', wall)\n        lighter:drawLights()\n    end\n\n    -- Clean up\n    -- lighter:removeLight(light)\n    -- lighter:removePolygon(wall)\n\n### How to use in your game context with a darker global illumination:\n#### (remember you can use any combination of additive \u0026 multiplicative blending to achieve a result you like)\n    -- Call after your light positions have been updated\n    function preDrawLights()\n      love.graphics.setCanvas({ lightCanvas, stencil = true})\n      love.graphics.clear(0.4, 0.4, 0.4) -- Global illumination level\n      self.lighter:drawLights()\n      love.graphics.setCanvas()\n    end\n    \n    -- Call after you have drawn your scene (but before UI)\n    function drawLights()\n      love.graphics.setBlendMode(\"multiply\", \"premultiplied\")\n      love.graphics.draw(lightCanvas)\n      love.graphics.setBlendMode(\"alpha\")\n    end\n\n### Function signatures of the public API:\n```\n    init = function(self, options)\n    addLight = function(self, x, y, radius, r, g, b, a, gradientImage)\n    updateLight = function(self, light, x, y, radius, r, g, b, a, gradientImage)\n    removeLight = function(self, light)\n    addPolygon = function(self, polygon)\n    removePolygon = function(self, polygon)\n    drawVisibilityPolygon = function(self, light)\n    drawLights = function(self)\n```\n\n## Credits:\n  * Helped me understand the premise and their code provided me with tons of helpful tips for getting this implemented: [https://github.com/OneLoneCoder](https://github.com/OneLoneCoder)\n  * The actual page I ended up following to really get the idea: [https://ncase.me/sight-and-light/](https://ncase.me/sight-and-light/)\n\n\n### Screenshot of the library in use in a game\n![Screenshot of the library in use in a game](./screenshot.jpg)\n\n\n## How it works under the hood\nFor each light we cast rays towards wall polygon corners (aka map features). Checks intersections.\nBuilds a visibility polygon and uses it as the stencil for drawing the light.\n\nAs an optimization it uses a spatial map and calculates polygon bounding boxes on the fly so that only polygons within light radius get included in the visibility polygon calculations.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspeakk%2Flighter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspeakk%2Flighter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspeakk%2Flighter/lists"}