BlueGit

timfa questward

Files

questward / shared / lighting / lightCorners.js

lightCorners.js

lightCorners.js 909 B Download Raw
1/**
2 * Bilinear lightmap corner sample for one tile corner.
3 * Occluding neighbours reuse the home tile's lit value so they neither bleed
4 * torchlight onto the dark side of a wall nor carve daylight rims around solids.
5 *
6 * @param {{
7 * homeLit: number, homeBlocks: boolean,
8 * aLit: number, aBlocks: boolean,
9 * bLit: number, bBlocks: boolean,
10 * dLit: number, dBlocks: boolean
11 * }} samples Cardinal A/B and diagonal D around the home tile.
12 */
13export function smoothLitCorner ({
14 homeLit,
15 homeBlocks,
16 aLit,
17 aBlocks,
18 bLit,
19 bBlocks,
20 dLit,
21 dBlocks
22})
23{
24 const home = Number(homeLit) || 0;
25 if (homeBlocks)
26 { return home; }
27 let sum = home;
28 let count = 1;
29 sum += aBlocks ? home : (Number(aLit) || 0);
30 count += 1;
31 sum += bBlocks ? home : (Number(bLit) || 0);
32 count += 1;
33 if (!aBlocks && !bBlocks)
34 {
35 sum += dBlocks ? home : (Number(dLit) || 0);
36 count += 1;
37 }
38 return sum / count;
39}