bake-lighting
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePrecompute static lighting
预计算静态光照
Static geometry lit by static lights can bake into lightmap textures once, removing per-frame
shadow-map rendering and per-pixel dynamic lighting for that light entirely.
静态几何体受静态光源照射时,可一次性烘焙到光照贴图纹理中,完全消除该光源每帧的阴影贴图渲染和逐像素动态光照计算。
Engine Lightmapper
flags
Lightmapper引擎Lightmapper
标记
Lightmapper- Engine-only bootstraps must register it: .
AppOptions.lightmapper = Lightmapperwires this by default; only a manualApplicationassembly needs the explicit line.AppOptions - Per light: , then
light.bake = trueonce every mesh it lights is lightmapped, so it stops contributing to the real-time pass.light.affectDynamic = false - Per mesh: — required for the mesh to receive any light once
render.lightmapped = trueis false, a correctness requirement, not just an optimization —affectDynamicto size its lightmap,render.lightmapSizeMultiplierso lightmapped meshes still shadow each other in the bake.render.castShadowsLightmap - Bake mode: for flat diffuse materials;
BAKE_COLORadds a dominant-light-direction pass for normal- or specular-mapped materials that need one.BAKE_COLORDIR - Baked ambient occlusion, independent of any light: plus
scene.ambientBake,ambientBakeNumSamples/ambientBakeOcclusionBrightness.OcclusionContrast - Run once the scene exists;
app.lightmapper.bake(null, mode)bakes every lightmapped node.null
- 仅使用引擎初始化的项目必须注册它:。
AppOptions.lightmapper = Lightmapper默认会自动配置;只有手动组装Application时才需要显式添加该行代码。AppOptions - 每个光源:设置,然后在它照射的所有网格都完成光照贴图烘焙后,设置
light.bake = true,使其不再参与实时渲染流程。light.affectDynamic = false - 每个网格:设置——这是网格在
render.lightmapped = true设为false后能接收光照的必要条件,不仅是优化,更是正确性要求;设置affectDynamic调整其光照贴图尺寸;设置render.lightmapSizeMultiplier使烘焙后的网格在烘焙过程中仍能互相投射阴影。render.castShadowsLightmap - 烘焙模式:适用于平面漫反射材质;
BAKE_COLOR会添加主光源方向通道,适用于需要该信息的法线贴图或高光贴图材质。BAKE_COLORDIR - 独立于任何光源的烘焙环境光遮蔽:设置,同时配置
scene.ambientBake、ambientBakeNumSamples/ambientBakeOcclusionBrightness。OcclusionContrast - 场景加载完成后运行;
app.lightmapper.bake(null, mode)表示烘焙所有开启光照贴图的节点。null
Verify UVs before trusting this on real assets
在实际资源中使用前先验证UV
Procedural primitives auto-generate a usable UV set; imported GLB models often do not ship a second,
non-overlapping UV channel suitable for a lightmap atlas. Read the installed engine's source for
what its actually requires — which UV set it samples, whether it unwraps one for you —
before assuming a real model will bake correctly. Do not carry a primitive-only test result into
production assets unchecked.
Lightmapper程序生成的图元会自动生成可用的UV集;但导入的GLB模型通常没有第二个适合光照贴图图集的非重叠UV通道。在假设实际模型能正确烘焙之前,请查看已安装引擎的源代码,了解实际要求的条件——它采样哪个UV集,是否会自动为你展开UV。不要未经检查就将仅针对图元的测试结果直接应用到生产资源中。
LightmapperChoose the rung by budget, not by default
根据预算选择方案,而非默认选项
On-device bake cost scales with baked-node count and lightmap resolution; estimate it against the
startup budget before choosing a rung. Stay on-device unless:
- the estimated bake time does not fit the startup or first-paint budget on the target device, or
- the result needs stylized material detail beyond lighting that the runtime cannot produce.
Lightmapper
Only then move to an offline bake shipped as assets, following the same shape as any other
generated-asset pipeline: registry-keyed per-asset configs (a new asset is a config change, not new
pipeline code), a CLI with per-target fast paths, staged size logging, worker-thread parallelism for
build time, and a coverage self-audit that fails the bake when an expected output is missing or
empty.
设备端的烘焙开销与烘焙节点数量和光照贴图分辨率成正比;在选择方案前,请根据目标设备的启动预算估算开销。除非满足以下条件,否则优先在设备端烘焙:
- 预估的烘焙时间超出目标设备的启动时间或首次渲染预算,或者
- 需要实现超出运行时能力的风格化材质细节,而不仅仅是光照效果。
Lightmapper
只有在上述情况下,才转为使用离线烘焙并将结果作为资源交付,遵循与其他生成资源流水线相同的流程:基于注册表键的每个资源配置(新增资源只需修改配置,而非新增流水线代码)、针对不同目标的快速路径CLI、分阶段的尺寸日志记录、构建时的工作线程并行处理,以及当预期输出缺失或为空时会终止烘焙的覆盖范围自我审核。
Keep dynamic objects consistent
保持动态对象的一致性
Whichever rung you use, dynamic objects moving through baked lighting must not read as ignoring it:
sample or approximate the baked occlusion/shadow field for them and their attachments so they dim to
the same levels as the static geometry around them, and ground them with a contact shadow. A
dynamic object whose custom shading must meet baked maps is territory.
override-shader-chunks无论采用哪种方案,在烘焙光照中移动的动态对象都不能看起来完全不受光照影响:为它们及其附属物采样或近似烘焙的遮蔽/阴影区域,使它们的亮度与周围静态几何体保持一致,并通过接触阴影让它们贴合地面。如果动态对象的自定义着色必须匹配烘焙贴图,则需要使用来实现。
override-shader-chunksProve it
验证效果
Capture -style frames both in and out of the baked shadow, before and after the
change, and compare them. A screenshot glanced at once is not proof the bake reproduced the lighting
it removed.
verify-pixels分别捕获烘焙阴影内外、变更前后的风格帧并进行对比。仅快速查看一次截图不足以证明烘焙效果还原了它所替代的光照。
verify-pixels