| Server IP : 217.154.3.148 / Your IP : 216.73.216.90 Web Server : Apache System : Linux blissful-wright.217-154-3-148.plesk.page 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : gracious-boyd_hfhh1h8vo9n ( 10000) PHP Version : 8.3.31 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/vhosts/gracious-boyd.217-154-3-148.plesk.page/nextjs/lib/render/ |
Upload File : |
export type CompositeParams = {
groutOpacity?: number // 0..1
groutColor?: [number, number, number]
specStrength?: number // 0..1
}
function clampByte(v: number): number {
if (!Number.isFinite(v)) return 0
if (v < 0) return 0
if (v > 255) return 255
return v | 0
}
/**
* Applies light/shadow/spec maps to a tile overlay ImageData in-place.
* Only affects pixels where overlay alpha > 0.
*/
export function shadeTileOverlayInPlace(opts: {
overlay: ImageData
lightMap?: Uint8Array | null // 0..255
shadowMap?: Uint8Array | null // 0..255 (already strength-scaled)
specMap?: Uint8Array | null // 0..255
params?: CompositeParams
}) {
const { overlay, lightMap, shadowMap, specMap } = opts
const data = overlay.data
const groutOpacity = Math.max(0, Math.min(1, opts.params?.groutOpacity ?? 0.9))
const specStrength = Math.max(0, Math.min(1, opts.params?.specStrength ?? 0.25))
void groutOpacity
for (let i = 0, p = 0; i < data.length; i += 4, p++) {
const a = data[i + 3]
if (a === 0) continue
const lm = lightMap ? lightMap[p] / 255 : 0.5 // 0..1
const sm = shadowMap ? shadowMap[p] / 255 : 0 // 0..1, already strength scaled upstream
const sp = specMap ? specMap[p] / 255 : 0 // 0..1
// Light map: multiply in ~[0.85..1.10]
const lightMul = 0.85 + 0.25 * lm
// Shadow map: only darken; clamp to keep within ~[0.7..1.0]
const shadowMul = Math.max(0.7, 1.0 - sm)
const add = sp * 255 * specStrength
const r = data[i] * lightMul * shadowMul + add
const g = data[i + 1] * lightMul * shadowMul + add
const b = data[i + 2] * lightMul * shadowMul + add
data[i] = clampByte(r)
data[i + 1] = clampByte(g)
data[i + 2] = clampByte(b)
}
}