/** * Bilinear lightmap corner sample for one tile corner. * Occluding neighbours reuse the home tile's lit value so they neither bleed * torchlight onto the dark side of a wall nor carve daylight rims around solids. * * @param {{ * homeLit: number, homeBlocks: boolean, * aLit: number, aBlocks: boolean, * bLit: number, bBlocks: boolean, * dLit: number, dBlocks: boolean * }} samples Cardinal A/B and diagonal D around the home tile. */ export function smoothLitCorner ({ homeLit, homeBlocks, aLit, aBlocks, bLit, bBlocks, dLit, dBlocks }) { const home = Number(homeLit) || 0; if (homeBlocks) { return home; } let sum = home; let count = 1; sum += aBlocks ? home : (Number(aLit) || 0); count += 1; sum += bBlocks ? home : (Number(bLit) || 0); count += 1; if (!aBlocks && !bBlocks) { sum += dBlocks ? home : (Number(dLit) || 0); count += 1; } return sum / count; }