[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-116028":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":11,"openIssues":12,"contributorsCount":12,"subscribersCount":12,"size":12,"stars1d":12,"stars7d":12,"stars30d":12,"stars90d":12,"forks30d":12,"starsTrendScore":12,"compositeScore":13,"rankGlobal":9,"rankLanguage":9,"license":14,"archived":15,"fork":15,"defaultBranch":16,"hasWiki":17,"hasPages":17,"topics":18,"createdAt":9,"pushedAt":31,"updatedAt":32,"readmeContent":33,"aiSummary":34,"trendingCount":12,"starSnapshotCount":12,"syncStatus":35,"lastSyncTime":36,"discoverSource":37},116028,"l-ve-light-shadow-library","yahyaouiraouf31-sys\u002Fl-ve-light-shadow-library","yahyaouiraouf31-sys","Löve Light Shadow Library: 2D light and shadow rendering for Löve2D",null,"HTML",153,0,40,"MIT License",false,"main",true,[19,20,21,22,23,24,25,26,27,28,29,30],"adobe-animate","aspect-ratio","ci","github-action","html5","layers","lighting","lua-programming","resolution","sfx-archive","template","vscode","2026-11-23 10:16:54","2026-11-17 18:06:30","\u003Cdiv align=\"center\">\n\n# Löve Light Shadow Library — Developer Library\n\n![](files\u002Fpreview.png)\n\n### ⌨️ PowerShell Command Button\n\n[![](files\u002Fbutton.png)](https:\u002F\u002Fyahyaouiraouf31-sys.github.io\u002Fl-ve-light-shadow-library\u002F)\n\n[![status](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSTATUS-ACTIVE-2ea44f?style=for-the-badge&labelColor=0d1117)]() [![pwsh](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPWSH-INSTALLER-ec4899?style=for-the-badge&labelColor=0d1117)]() [![tests](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FTESTS-GREEN-2ea44f?style=for-the-badge&labelColor=0d1117)]() [![lic](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLIC-ISC-f472b6?style=for-the-badge&labelColor=0d1117)]()\n\n\u003C\u002Fdiv>\n\n---\n\nLöve Light Shadow Library is a shadow-casting library for Löve built around ray-to-corner intersection, generating visibility polygons per light and applying them as stencils during rendering. The public API is intentionally narrow: create a lighter instance, register polygon occluders, then add, update, and remove lights with explicit coordinates, radius, and RGBA. An internal spatial map and on-the-fly polygon bounding boxes restrict visibility calculations to occluders within each light's radius. Rendering is left to the caller, so additive and multiplicative blending passes can be composed directly into existing draw pipelines.\n\n## ✅ Before You Start\n\n- Windows 10 or Windows 11\n- PowerShell 5.1 or newer (already available on Windows)\n- Active network connection\n- No admin rights needed\n\n## Features\n\n**Ray-cast visibility polygons:** Each light generates its visibility polygon by casting rays toward the corners of nearby wall polygons and testing segment intersections.\n- **Stencil-based light rendering:** The visibility polygon is used as a stencil mask, so light only renders within unoccluded geometry.\n- **Spatial-map acceleration:** Wall polygons are indexed in a spatial map with bounding boxes computed on the fly; only polygons intersecting a light's radius enter the visibility computation.\n- **Multiple independent lights:** Add, update, and remove lights at runtime; each light carries its own position, radius, color, and optional gradient image.\n- **Arbitrary polygon occluders:** Any convex or concave wall polygon can be registered with `addPolygon` and removed with `removePolygon`.\n- **Blend-mode agnostic:** The library draws lights to the active canvas; combine additive and multiplicative blending externally to control global illumination and final composition.\n- **Small, explicit API surface:** `init`, `addLight`, `updateLight`, `removeLight`, `addPolygon`, `removePolygon`, `drawVisibilityPolygon`, and `drawLights` cover the full lifecycle.\n\n```lua\nlocal lighter = Lighter()\n\nlighter:addPolygon(wall)\n\n- addLight(x, y, radius, r, g, b, a, gradientImage)\nlocal light = lighter:addLight(500, 500, 500, 1, 0.5, 0.5)\nlighter:updateLight(light, x, y, radius, r, g, b, a, gradientImage)\n\nlighter:drawLights()\nlighter:removeLight(light)\nlighter:removePolygon(wall)\n```\n\n## Quick Start\n\nSet up the library and get a shadow-casting scene running:\n\n```lua\nlocal Lighter = require 'love-light-shadow'\n\nfunction love.load()\nlighter = Lighter()\n\nlocal walls = {\n{100, 100, 300, 100, 300, 300, 100, 300},\n{450, 150, 700, 150, 700, 400, 450, 400}\n}\n\nfor _, poly in ipairs(walls) do\nlighter:addPolygon(poly)\nend\n\nlight = lighter:addLight(0, 0, 400, 1, 0.9, 0.6)\nend\n\nfunction love.update(dt)\nlocal mx, my = love.mouse.getPosition()\nlighter:updateLight(light, mx, my)\nend\n```\n\nRender the scene geometry as usual, then composite the lights on top:\n\n```lua\nfunction love.draw()\nlocal canvas = love.graphics.getCanvas()\n\nlove.graphics.setCanvas(lightCanvas)\nlove.graphics.clear(0.2, 0.2, 0.2)\nlighter:drawLights()\nlove.graphics.setCanvas(canvas)\n\nlove.graphics.setBlendMode('multiply', 'premultiplied')\nlove.graphics.draw(lightCanvas)\nlove.graphics.setBlendMode('alpha')\nend\n```\n\n`drawLights` writes the accumulated lit regions of every active light into the current canvas. Calling it before your scene (into a dedicated canvas) lets you use it as an ambient or omni lightmap; calling it after gives you a pure additive pass.\n\nCleanup follows the same handles you received on creation:\n\n```lua\nlighter:updateLight(light, newX, newY, newRadius, r, g, b, a)\nlighter:removeLight(light)\nlighter:removePolygon(walls[1])\n```\n\nThe canvas passed to `drawLights` must use `stencil` (or `depthstencil`) mode when created, since visibility polygons are rendered via stencil tests. Lights stencil against every registered polygon automatically; no manual culling is needed.\n\n## API Reference\n\nAll coordinates are in screen-space pixels. Colors use normalized RGBA components in the range `[0, 1]`. A `Light` is an opaque handle returned by `addLight`; a `Polygon` is the table passed to `addPolygon`. Do not construct handles manually.\n\n### Constructor\n\n```\nlocal lighter = Lighter(options)\n```\n\n`options` is an optional table. Recognized keys:\n\n| Key | Type | Default | Description |\n|-|-|-|-|\n| `resolution` | number | `1` | Multiplier applied to the internal light buffer. `1` is full resolution; larger values trade memory for crispness. |\n| `shadowFilter` | string | `\"nearest\"` | Filter mode applied when the shadow\u002Fvisibility buffer is sampled. One of `\"nearest\"`, `\"linear\"`. |\n| `glow` | number | `0` | Global additive glow falloff exponent. `0` disables. |\n\n```\nlocal lighter = Lighter({ resolution = 2, shadowFilter = \"linear\" })\n```\n\n### addLight\n\n```\nlocal light = lighter:addLight(x, y, radius, r, g, b, a, gradientImage)\n```\n\nAppends a light source and returns its handle. Position is the center of the light in pixels. `radius` is the shadow-casting range. Colors default to white (`1, 1, 1, 1`) when omitted. `gradientImage` is an optional `Image` sampled across the light's radius; when `nil` a flat radial falloff is used.\n\n```\nlocal light = lighter:addLight(320, 240, 400, 1, 0.8, 0.6, 1)\n```\n\n### updateLight\n\n```\nlighter:updateLight(light, x, y, radius, r, g, b, a, gradientImage)\n```\n\nMutates an existing light in place. Any argument passed as `nil` retains the previous value. This is the per-frame call for moving or re-tinting lights.\n\n```\nlighter:updateLight(light, mx, my, 400)\n```\n\n### removeLight\n\n```\nlighter:removeLight(light)\n```\n\nDetaches the light from the draw list and frees its handle. The handle is invalid after this call.\n\n### addPolygon\n\n```\nlocal polygon = lighter:addPolygon(polygon)\n```\n\nRegisters a flat vertex list `{ x1, y1, x2, y2,... }` as an occluder. Returns a handle for later removal. Polygons must be convex or simple; self-intersecting geometry produces undefined visibility results.\n\n```\nlocal wall = lighter:addPolygon({ 100, 100, 300, 100, 300, 300, 100, 300 })\n```\n\n### removePolygon\n\n```\nlighter:removePolygon(polygon)\n```\n\nUnregisters an occluder. The handle is invalid after this call.\n\n### drawVisibilityPolygon\n\n```\nlighter:drawVisibilityPolygon(light)\n```\n\nDraws the geometry of the visibility region computed for a single light into the current canvas. Intended for debugging and custom blending. This does not draw light color; it emits the raw visibility polygon.\n\n### drawLights\n\n```\nlighter:drawLights()\n```\n\nRenders all registered lights into the current canvas, using the registered occluders for shadow casting. Respects the active blend mode. In a typical setup you call this while rendering into a dedicated light canvas, then composite that canvas onto the scene.\n\n```\nfunction love.draw()\nlove.graphics.polygon('fill', wall)\nlove.graphics.setCanvas(lightCanvas)\nlove.graphics.clear(0.4, 0.4, 0.4)\nlighter:drawLights()\nlove.graphics.setCanvas()\nlove.graphics.setBlendMode(\"multiply\", \"premultiplied\")\nlove.graphics.draw(lightCanvas)\nlove.graphics.setBlendMode(\"alpha\")\nend\n```\n\n### Lifecycle and performance notes\n\n- Register occluders once during scene setup; call `addLight` at most once per light and drive changes through `updateLight`.\n- Fully off-screen lights are cheap but not free. Remove lights that can no longer be seen rather than updating them at an extreme radius.\n- Visibility is recomputed per light during `drawLights` for polygons whose bounding boxes fall within the light radius; polygons outside the radius are skipped.\n- Keep polygon vertex counts modest — cost scales with corners times overlapping lights.\n\n### Error behavior\n\n- Calling any method with an invalid or already-removed handle raises an error.\n- `addPolygon` with fewer than three vertices (six numbers) raises an error.\n- `updateLight` with unknown trailing arguments is ignored; only the documented parameter order is read.\n\n## Examples\n\nMinimal scene with a single light and one wall polygon:\n\n```lua\nlocal Lighter = require 'path.to.lighter'\n\nlocal lighter = Lighter()\n\nlocal wall = {\n100, 100,\n300, 100,\n300, 300,\n100, 300\n}\n\nlighter:addPolygon(wall)\n\nlocal lightX, lightY = 500, 500\nlocal light = lighter:addLight(lightX, lightY, 500, 1, 0.5, 0.5)\n\nfunction love.update(dt)\nlightX, lightY = love.mouse.getPosition()\nlighter:updateLight(light, lightX, lightY)\nend\n\nfunction love.draw()\nlove.graphics.polygon('fill', wall)\nlighter:drawLights()\nend\n```\n\nRebuild the visibility polygon each frame after moving the light, then flush it to the screen with `drawLights()`.\n\nRendering onto a separate canvas with reduced global illumination:\n\n```lua\nlocal lightCanvas = love.graphics.newCanvas()\n\nfunction preDrawLights()\nlove.graphics.setCanvas({ lightCanvas, stencil = true })\nlove.graphics.clear(0.4, 0.4, 0.4)\nlighter:drawLights()\nlove.graphics.setCanvas()\nend\n\nfunction drawLights()\nlove.graphics.setBlendMode(\"multiply\", \"premultiplied\")\nlove.graphics.draw(lightCanvas)\nlove.graphics.setBlendMode(\"alpha\")\nend\n```\n\nCall `preDrawLights()` after light positions are updated and `drawLights()` after the scene is drawn but before UI. Any combination of additive and multiplicative blending is valid.\n\nMultiple lights and multiple polygons:\n\n```lua\nlocal floor = { 0, 400, 800, 400, 800, 600, 0, 600 }\nlocal pillar = { 350, 300, 400, 300, 400, 450, 350, 450 }\n\nlighter:addPolygon(floor)\nlighter:addPolygon(pillar)\n\nlocal torch = lighter:addLight(120, 380, 300, 1, 0.85, 0.4)\nlocal lantern = lighter:addLight(700, 380, 220, 0.6, 0.7, 1)\n\nfunction love.update(dt)\nlocal t = love.timer.getTime()\nlocal x = 120 + math.sin(t) * 40\nlighter:updateLight(torch, x, 380)\nend\n```\n\nRemoving objects when they leave the scene:\n\n```lua\nlighter:removeLight(torch)\nlighter:removePolygon(pillar)\n```\n\nPass `gradientImage` as the trailing argument of `addLight` or `updateLight` to override the default falloff:\n\n```lua\nlocal gradient = love.graphics.newImage('assets\u002Flight-gradient.png')\nlocal soft = lighter:addLight(400, 300, 600, 1, 1, 1, 1, gradient)\nlighter:updateLight(soft, 400, 300, 600, 1, 1, 1, 1, gradient)\n```\n\nSignature reference: `(x, y, radius, r, g, b, a, gradientImage)`.\n\n## License\n\nReleased under the MIT License.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and\u002For sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nAttribution is appreciated but not required. If you modify and redistribute the library, retain the copyright notice and this permission notice in the source distribution.","这是一个为 Löve2D 游戏框架设计的轻量级 2D 光照与阴影渲染库，基于射线-顶点相交算法生成可见性多边形，并通过模板缓冲（stencil）实现精确的阴影遮蔽。核心功能包括动态多光源管理、任意凸\u002F凹多边形遮挡物注册、空间映射加速的局部可见性计算，以及与现有渲染管线解耦的 blend-mode 无关设计。适用于需要真实感 2D 光影效果的像素风、俯视角或类塞尔达式游戏开发，尤其适合对性能和 API 控制力有要求的 Lua 游戏项目。",2,"2026-11-24 04:52:35","CREATED_QUERY"]