{"id":13525679,"url":"https://github.com/xiejiangzhi/light","last_synced_at":"2025-04-01T05:32:06.333Z","repository":{"id":147735275,"uuid":"207122499","full_name":"xiejiangzhi/light","owner":"xiejiangzhi","description":"A simple light \u0026 shadow library for love2d","archived":false,"fork":false,"pushed_at":"2019-09-17T09:19:59.000Z","size":1884,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-02T06:17:57.040Z","etag":null,"topics":["light","love2d","lua","shadow"],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xiejiangzhi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2019-09-08T14:13:22.000Z","updated_at":"2024-07-15T12:52:20.000Z","dependencies_parsed_at":"2023-05-27T08:34:14.235Z","dependency_job_id":null,"html_url":"https://github.com/xiejiangzhi/light","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/xiejiangzhi%2Flight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiejiangzhi%2Flight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiejiangzhi%2Flight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiejiangzhi%2Flight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xiejiangzhi","download_url":"https://codeload.github.com/xiejiangzhi/light/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222703719,"owners_count":17025837,"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":["light","love2d","lua","shadow"],"created_at":"2024-08-01T06:01:21.010Z","updated_at":"2024-11-02T10:30:59.408Z","avatar_url":"https://github.com/xiejiangzhi.png","language":"Lua","funding_links":[],"categories":["Lighting"],"sub_categories":[],"readme":"Light \u0026 Shadow\n==============\n\nA simple dynamic light shadow library for LOVE2D 11.2.\n\nIt's easy to use, don't need to create body for shadow, directly generate shadow from canvas/image according alpha.\nSo it's not fast, and don't support 3D shadow.\nIf you want a fast and 3D light shadow library, [Light World](https://github.com/xiejiangzhi/light_world.lua) and [Shadow](https://github.com/matiasah/shadows) is better choice.\n\n\n## Example\n\n![Example Image](./example.png)\n\n\n##Usage\n\n```\nlocal Lib = require 'light'\nlocal light_world = Lib.World.new()\nlocal light\n\nlocal lg = love.grpahics\n\nfunction love.load()\n  light = light_world:add(200, 200, 200, 1, 0, 0)\nend\n\nfunction love.update(dt)\n  light.x, light.y = love.mouse.getPosition()\nend\n\nfunction love.draw()\n  -- reset light world\n  light_world:begin()\n\n  for i = 1, 10 do\n    lg.circle('fill', 100 + i * 70, 300, 10)\n  end\n\n  -- track shadow objects\n  light_world:track_obj()\n  for i = 1, 10 do\n    lg.circle('fill', 100 + i * 70, 300 + i * 50, 30)\n  end\n  -- draw background\n  light_world:track_bg()\n\n  for i = 1, 10 do\n    lg.circle('fill', 100 + i * 70, 500 + i * 50, 30)\n  end\n\n  -- draw scene, light and shadow\n  light_world:finish()\n\n  lg.print('mouse: '..mx..','..my..' light: '..light.x..','..light.y, 50, 50)\nend\n```\n\n\n## Functions\n\n### World\n\n* `World.new({ env_light = { 0.5, 0.4, 0.5, 0.5 }, alpha_through = 0.3 })` if a object alpha less than `alpha_through`, we will not generate shadow for it\n* `World:begin()` reset light world and start track background pixels.\n* `World:track_obj()` switch to draw object mode, pixels is affected by light and has shadow.\n* `World:track_light_objs()` switch to draw object mode, pixels is always light and has shadow.\n* `World:track_bg()` switch to draw background mode, new pixels is affected by light.\n* `World:track_light_bg()` switch to draw background mode, the pixels always is light and it has no shadow\n* `World:finish()` draw bg, objects, light and shadow to screen.\n* `World:add(x, y, radius, r, g, b, a)` add a light to world, return `light`\n* `World:remove(light)` remove the light from world\n* `World:clear()` remove all lights\n* `World:setEnvLight(r, g, b, a)`\n* `World:resize(w, h)` you must call it after change window size\n* `World:setTranslate(x, y, scale)` you must call it if your applied `love.graphics.translate` or `love.graphics.scale`\n* `World.env_tex=[canvas/image]`\n* `World.pause=true` Stop light and shadow feature.\n\n\n### Light\n\n* `Light:setSize(radius)` resize the light\n\n\n## Tips\n\n* If the `env_light` is `1, 1, 1, 1`, no light and shadow can be draw. In an overly bright environment you will not see light and shadow\n* If the background alpha is too little, we will not see the light because no object can reflect this light into your eyes\n* When you have a lot of light, it will very slow. the light size and quantity will affect performance. (I will try to make it faster)\n\n\n## TODO\n\n* Fix shadow for `source_radius` argument.\n* Support shadow for semitransparent objects.(shadow map able to save four floats.)\n* Optimize according to [here](https://github.com/mattdesl/lwjgl-basics/wiki/2D-Pixel-Perfect-Shadows#optimizations)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxiejiangzhi%2Flight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxiejiangzhi%2Flight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxiejiangzhi%2Flight/lists"}