Implement BSP leaf ambient cube lighting for entities #22
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Entities currently use a flat
ambient + sun * NdotLlighting model (useSunLightingpath in the uber-shader), which means they're always fully sunlit regardless of whether they're indoors, under a roof, or in shadow. The Source engine uses leaf ambient cubes — pre-computed 6-directional light samples baked into BSP leaves by VRAD — to properly light entities with occlusion.How Source does it
LUMP_LEAF_AMBIENT_LIGHTING) and indexed by lumps 51/52 (LUMP_LEAF_AMBIENT_INDEX)CompressedLightCube— 6ColorRGBExp32values for ±X, ±Y, ±Z directions — plus an xyz position within the leafnSquared.x * cube[±X] + nSquared.y * cube[±Y] + nSquared.z * cube[±Z]— a weighted blend based on the surface normalRequirements
BSP parsing
LUMP_LEAFS) for leaf bounding boxesLUMP_NODES) for the BSP node tree (plane splits + children)ColorRGBExp32:channel * 2^exponentfor each RGB componentLeaf lookup
~leafIndex(bitwise NOT) when negativePer-entity ambient sampling
leafAmbientIndex[leafIndex]to get the sample rangedleafambientlighting_tsample by converting fractional xyz coords to world spaceCompressedLightCubeinto 6 linear RGB valuesShader changes
useSunLightingpath with ambient cube evaluationuniform vec3 ambientCube[6]to the uber-shadernSq.x * cube[neg.x] + nSq.y * cube[2+neg.y] + nSq.z * cube[4+neg.z]Scene manager integration
Group.clone()shares materials, entities sharing a model template will need their own material instances (or a different uniform strategy)Data structures
Context
client/src/bsp/material.js(uber-shaderuseSunLightingpath)client/src/bsp/parser.jsclient/src/scene.js(_replaceWithModel,_updateEntity)