/** * additional import for TypeScript * @import {TextureAtlas} from "./../../texture/atlas.js"; */ /** * Lit-aware variant of `QuadBatcher` for the SpriteIlluminator workflow. * * Adds a 5th vertex attribute (`aNormalTextureId`) so each quad knows * which paired normal-map sampler to read, and bundles the per-frame * light uniforms (`uLightPos`, `uLightColor`, `uLightHeight`, `uAmbient`) * that the lit fragment shader iterates. * * Texture-slot capacity is halved relative to `QuadBatcher` because each * sprite may need a paired (color, normal) sampler — color goes to unit * `n`, normal to unit `maxBatchTextures + n`. The `WebGLRenderer` only * dispatches sprites here when the scene actually needs lighting (active * `Light2d` AND the sprite has a `normalMap`); unlit sprites stay on * `QuadBatcher` and pay nothing. * @category Rendering */ export default class LitQuadBatcher extends QuadBatcher { /** * normal-map texture per color slot — keyed by the same unit index as * `boundTextures`. Used by `addQuad` to detect when a normal-map slot * needs (re-)uploading, mirroring the color-texture cache. * @type {Array} * @ignore */ boundNormalMaps: (ImageBitmap | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | null)[] | undefined; /** * Map from a normal-map source image to its GL texture object. * @type {Map} * @ignore */ normalMapTextures: Map | undefined; _lightCount: number | undefined; _maxLights: number | undefined; /** * Bind the paired normal sampler uniforms (`uNormalSampler0..N-1`) * to texture units `maxBatchTextures..2*maxBatchTextures-1`. Called * from `init` and `reset`. * @ignore */ bindNormalSamplers(): void; /** * Upload per-frame Light2d uniforms used by the lit fragment path. * Called once per camera per frame (before the world tree walk). * Lights past `MAX_LIGHTS` are silently ignored. * * Coordinates must be supplied in the same space as the renderer's * pre-projection vertex coords (i.e. camera-local / FBO-local), * matching `Stage.drawLighting`'s convention. * @param {object} uniforms * @param {Float32Array} uniforms.positions - flat array of `[x, y, radius, intensity]` per light, length = 4 * count * @param {Float32Array} uniforms.colors - flat array of `[r, g, b]` per light, length = 3 * count * @param {Float32Array} [uniforms.heights] - flat array of per-light height, length = MAX_LIGHTS * @param {number} uniforms.count - number of lights to render (clamped to MAX_LIGHTS) * @param {number[]} [uniforms.ambient] - `[r, g, b]` ambient floor (0..1 each) */ setLightUniforms(uniforms: { positions: Float32Array; colors: Float32Array; heights?: Float32Array | undefined; count: number; ambient?: number[] | undefined; }): void; /** * Bind a normal-map image to the given GL texture unit. Uploads on * first use (via `uploadNormalMap`) and rebinds the cached * `WebGLTexture` on subsequent calls. Mirrors the * `bindTexture2D` / `createTexture2D` split used by `MaterialBatcher`, * but for normal-map textures which live outside the color * `TextureCache` (cached per-image in `normalMapTextures`). * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap} image - normal-map source * @param {number} unit - GL texture unit (already offset by `maxBatchTextures`) */ bindNormalMap(image: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap, unit: number): void; /** * Upload a normal-map image to GL and cache the resulting `WebGLTexture` * for future `bindNormalMap` calls. Not meant to be called directly — * `bindNormalMap` invokes this on the first use of a given image. * * `premultipliedAlpha = false` — normal maps store linear-encoded * surface normals; multiplying through alpha would corrupt the * encoding for any non-opaque texel. * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap} image - normal-map source * @param {number} unit - GL texture unit (already offset by `maxBatchTextures`) */ uploadNormalMap(image: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap, unit: number): void; /** * Add a textured quad with optional paired normal map. * @param {TextureAtlas} texture - Source texture atlas * @param {number} x - Destination x-coordinate * @param {number} y - Destination y-coordinate * @param {number} w - Destination width * @param {number} h - Destination height * @param {number} u0 - Texture UV (u0) value * @param {number} v0 - Texture UV (v0) value * @param {number} u1 - Texture UV (u1) value * @param {number} v1 - Texture UV (v1) value * @param {number} tint - tint color (UINT32 argb) * @param {boolean} [reupload=false] - Force the texture to be reuploaded * @param {HTMLImageElement|HTMLCanvasElement|null} [normalMap=null] - paired normal-map (SpriteIlluminator workflow) */ addQuad(texture: TextureAtlas, x: number, y: number, w: number, h: number, u0: number, v0: number, u1: number, v1: number, tint: number, reupload?: boolean, normalMap?: HTMLImageElement | HTMLCanvasElement | null): void; } import QuadBatcher from "./quad_batcher.js"; import type { TextureAtlas } from "./../../texture/atlas.js"; //# sourceMappingURL=lit_quad_batcher.d.ts.map