| 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 : |
import { boxBlur, morphDilate } from '@/utils/maskOps'
export type MapU8 = { data: Uint8Array; width: number; height: number }
/**
* Builds a soft shadow map from the occluder mask:
* shadow = blur(dilate(occluder))
* Output is 0..255, masked to tilesMask if provided.
*/
export function buildShadowMap(opts: {
occluderMask: Uint8Array // 0/255
tilesMask?: Uint8Array | null // 0/255
width: number
height: number
dilatePx?: number
blurRadiusPx?: number
strength?: number // 0..1 (applied as scalar to output)
}): MapU8 {
const width = Math.max(1, Math.round(opts.width))
const height = Math.max(1, Math.round(opts.height))
const dilatePx = Math.max(0, Math.round(opts.dilatePx ?? 6))
const blurRadiusPx = Math.max(0, Math.round(opts.blurRadiusPx ?? 14))
const strength = Math.max(0, Math.min(1, opts.strength ?? 0.35))
const tilesMask = opts.tilesMask ?? null
const base = dilatePx ? morphDilate(opts.occluderMask, width, height, dilatePx) : opts.occluderMask
const blurred = blurRadiusPx ? boxBlur(base, width, height, blurRadiusPx) : null
const out = new Uint8Array(width * height)
for (let i = 0; i < out.length; i++) {
if (tilesMask && !tilesMask[i]) {
out[i] = 0
continue
}
const v = blurred ? blurred[i] : base[i]
const vv = Number.isFinite(v) ? v : 0
out[i] = Math.max(0, Math.min(255, Math.round(vv * strength)))
}
return { data: out, width, height }
}