Lucis
Lucis 是一款轻量级的服务端光照引擎。它用更快的基于区域(region-based)的系统替换了原版 Minecraft 光照管线中开销较大的部分,旨在实现高更新吞吐量、更快的区块光照计算以及更好的多核 CPU 扩展性,从而加快世界生成并允许生成巨型结构而不会导致 TPS 大幅下降。
最初这只是一个为了学习 Minecraft 光照引擎工作原理的研究项目,但由于原版引擎对我来说太慢了,最终演变成了重写光照系统,并且我决定借此机会尝试做点有趣的事情!
我想要往世界中生成巨大的(真的非常巨大!)结构,但遇到了原版光照引擎无法处理那么多方块来计算光照并直接卡死的问题,所以我决定解决这个问题。
是的,Starlight 和 ScalableLux 已经存在,你也可以使用它们。但我希望亲自研究并深入查看内部实现,而不是直接使用现有的解决方案。因此,这里诞生了 Lucis,它将光照速度提升至原版的约 8-12 倍,比 ScalableLux/Starlight 快约 1.5 倍!
Lucis 做了什么?
Lucis 在区块准备阶段优化了世界生成过程中的区块光照,并在方块变更后运行时更新方块光照和天空光照。
与仅依赖原版每次更新的光照行为不同,Lucis 按区域分组光照变化,尽可能异步处理这些变化,然后将结果光照数据以批处理形式发布回 Minecraft 的光照引擎。
目标非常简单:降低重型方块更新、区块加载和天空光照变化期间的光照成本。
它是如何工作的?
这是另一个 Starlight 分支吗?
不,这是一种不同的方法来尽可能优化光照计算。让我尝试描述一下。
Minecraft 按区块段存储光照,并在放置、移除、生成或更改方块时进行更新。这对于一般游戏玩法来说效果良好,但当游戏必须在短时间内处理大量影响光照的方块或生成世界时,速度可能会变慢。
Lucis 通过将光照工作收集到区域中来改变这一状况。区域是可以作为一个单元处理的小块拥有区块范围。当发生方块更新时,Lucis 记录该变化,将其与附近的变化组合在一起,并将这项工作发送到其运行时光照系统。这避免了将每个小型更新视为完全独立的光照操作。
对于区块光照,Lucis 可以在世界生成期间使用自己的重新光照路径来计算光照。它读取区块和附近的光照数据,计算天空光照和方块光照,然后将完成的光照区块段发布回 Minecraft 光照线程。
至于运行时方块变更,Lucis 使用自己的光照队列。如果在同一刻或相近时间有许多方块发生变化,队列允许 Lucis 将它们作为分组的区域任务进行处理。这对于密集的方块更新、地形编辑、生成的结构以及由屋顶或大型开口引起的天空光照变化特别有用。
Lucis 还将计算与发布分离。繁重的工作可以在主光照更新路径之外完成,因此最终区块数据可以批量发布。这减少了必须逐个通过光照线程的小型光照任务数量。结果是当许多光照变化同时发生时,开销更低。
主要的技术特点是,我们仍然需要尊重 Minecraft 的区块状态和光照引擎规则,以免破坏那些以某种方式获取光照数据或实现自己系统的其他模组。Lucis 计算新光照数据,跟踪受影响的区域,然后将结果交还给引擎。
基准测试
基准测试在 Minecraft 1.21.1 和 NeoForge 21.1.234 上运行,对比 Vanilla、ScalableLux 和 Lucis,使用相同的基准测试工具集,如种子、坐标和环境。
测试平台为 AMD Ryzen 3700x,其中 4 个线程分配给 Lucis。
ScalableLux 保持默认配置,parallelism=-1。
ns/change 越低越好。
| 负载 |
Vanilla ns/change |
ScalableLux ns/change |
Lucis ns/change |
Lucis vs Vanilla |
Lucis vs ScalableLux |
block_toggle_border |
322846.1 |
43999.7 |
28881.8 |
11.18x |
1.52x |
dense_chunk_patch |
17766.0 |
3480.5 |
3002.3 |
5.92x |
1.16x |
edge_toggle |
80824.9 |
26701.6 |
18182.0 |
4.45x |
1.47x |
roof_toggle |
22076.0 |
4680.8 |
2441.8 |
9.04x |
1.92x |
sky_hole |
213509.0 |
119023.0 |
114414.0 |
1.87x |
1.04x |
兼容性
虽然 Lucis 尽力与其他模组保持兼容,且原则上不应破坏任何东西,但某些情况最终可能会出现兼容性问题。在使用大型整合包时请谨慎操作。
已知说明:
- ScalableLux(或任何 Starlight 分支)从定义上就不兼容。你应该只选择 Lucis 或只选择 ScalableLux,不能两者共存。试图同时安装两者会导致大量崩溃。不要尝试将它们都放入你的整合包中,谢谢。这样行不通。
- Sable 与 Lucis 兼容。目前 Lucis 不会为 Sable 地块注入其光照,因此它们目前使用原版光照进行投影。一旦找到更好的解决方案,未来可能会改变这一点。
- 应与大多数世界生成优化模组(如 Generator Accelerator、C2ME、Fast Noise 和 ModernFix(某些补丁可能仍会计入))基本正常工作。在不同场景下,Lucis 可将世界生成速度提升 +15-25%。不错吧?
如果某个模组也替换或重度修改了 Minecraft 光照内部机制,则极有可能与 Lucis 发生冲突。
整合包
只要遵守 LGPLv3 许可证条款,你可以在个人和公共整合包中使用此模组,包括分发包。
Lucis
Lucis is a lightweight server-side light engine. It replaces expensive parts of the vanilla Minecraft lighting pipeline with a faster region-based system designed for high update throughput, faster chunk lighting and better scaling on multi-core CPUs allowing for faster worldgen and spawning massive structures without drastic TPS drops.
Originally started as a research project to learn how Minecraft's light engine works, ended rewriting lighting because the original one was too slow for me and decided to have some fun attempting to do something with it!
I wanted to spawn huge (like really huge!) structures into the world, but got stuck that vanilla light engine just... you know haven't expected THAT much amount of blocks to calculate light and just hangs itself, so I've tried to solve that.
Yes, Starlight and ScalableLux exists, you can use them too. However, I wanted to research and look inside myself instead of using existing solutions. So, here is Lucis, that speeds up lighting up to ~8-12x than vanilla and ~1.5x faster than ScalableLux/Starlight!
What Lucis does?
Lucis optimizes chunk lighting during world generation on a chunk preparation stage and runtime block light and skylight updates after block changes.
Instead of relying only on vanilla per-update lighting behavior, Lucis groups light changes by region, processes them asynchronously where possible, then publishes the resulting light data back to Minecraft's light engine in batches.
The goal is very simple. Reduce lighting cost during heavy block updates, chunk loading and skylight changes.
How it even works?
Is this another fork of Starlight?
No, this is an another approach to optimize light calculations where possible. Let me attempt to describe that.
Minecraft stores light per section and updates it whenever blocks are placed, removed, generated or changed. While that will work well for general gameplay, but it can become slow when the game has to process many light-affecting blocks in a short time or generating the world.
Lucis changes this by collecting lighting work into regions. A region is a small owned area of chunks that can be processed as one unit. When a block update happens, Lucis records the change, groups it with nearby changes, and sends that work to its runtime lighting system. This avoids treating every small update as a fully separate lighting operation.
For chunk lighting, Lucis can compute light during world generation using its own relighting path. It reads the chunk and nearby light data, calculates skylight and block light, then publishes the finished light sections back into Minecraft light thread.
As for runtime block changes, Lucis uses it's own light queue. If many blocks change during the same tick or close together, the queue lets Lucis process them as grouped region jobs. This is especially useful for dense block updates, terrain edits, generated structures, and skylight changes caused by roofs or large openings.
Lucis also separates calculation from publishing. The heavy work can be done outside the main light update path, so the final section data can be published back in batches. This reduces the number of small light tasks that have to go through the light thread one by one. The result is lower overhead when many light changes happen together.
The main technical quirk is that we still need to respect Minecraft's chunk state and light engine rules to not break many other mods that somehow get light data or implements it's own system. Lucis computes new light data, tracks changed regions, and then hands the result back to the engine.
Benchmarks
Benchmarks were run on Minecraft 1.21.1 with NeoForge 21.1.234, comparing Vanilla, ScalableLux and Lucis on the same benchmark harness such as seed, coordinates and environment.
Tested on AMD Ryzen 3700x with 4 threads delegated to Lucis.
ScalableLux left as by default with parallelism=-1 in the config.
Lower ns/change is better.
| Workload |
Vanilla ns/change |
ScalableLux ns/change |
Lucis ns/change |
Lucis vs Vanilla |
Lucis vs ScalableLux |
block_toggle_border |
322846.1 |
43999.7 |
28881.8 |
11.18x |
1.52x |
dense_chunk_patch |
17766.0 |
3480.5 |
3002.3 |
5.92x |
1.16x |
edge_toggle |
80824.9 |
26701.6 |
18182.0 |
4.45x |
1.47x |
roof_toggle |
22076.0 |
4680.8 |
2441.8 |
9.04x |
1.92x |
sky_hole |
213509.0 |
119023.0 |
114414.0 |
1.87x |
1.04x |
Compatibility
While Lucis attempts to maintain compatability with other mods where possible and it should not break anything, something may break eventually. Proceed with a caution when it comes to a large modpack.
Known notes:
- ScalableLux (or any Starlight fork) is incompatible by definition. You should choose only Lucis or only ScalableLux, not both. Attempting to put both will lead to many crashes. Do not try to throw both into your modpack, thanks. It won't work that way.
- Sable is compatible with Lucis. Currently Lucis does not inject its light for Sable plots, so they're currently use vanilla lighting for their projections. May be changed later once a better solution is found.
- Should work mostly fine with most of worldgen optimization mods such as Generator Accelerator, C2ME, Fast Noise and ModernFix (some patches still count I guess). Lucis will speed up the world generation up to +15-25% in terms of speed in different scenarios. Neat, right?
If a mod also replaces or heavily modifies Minecraft lighting internals then it is very likely to conflict with Lucis.
Modpacks
You can use it in personal and public modpacks, including distributed packs, as long as the LGPLv3 license terms are respected.
评论 0
登录后参与评分
还没有评论,来抢沙发吧