import { type SampleField } from './grid'; /** Channels one normal pixel carries: the WORLD-space unit normal, `rgb = n * 0.5 + 0.5`, +Y up and no tangent frame. */ export declare const NORMAL_CHANNELS = 3; export interface TerrainNormalMap { width: number; height: number; png: Uint8Array; } /** The pixel window a normal map covers, in samples of the field it is taken from. */ export interface NormalRegion { originI: number; originJ: number; pixels: number; } /** * Encodes one RGB8 normal per sample cell. The runtime derives its normals from the u16 heights, which terraces a * gentle slope into a handful of directions; these come from the float field, so the shader reads a smooth one. */ export declare function encodeNormalPixels(field: SampleField, region: NormalRegion): Uint8Array; /** * The largest per-channel error the near-lossless step allows: a value is moved at most 2 of 255 (about 0.9 degrees of the * normal's lean), the size of the 8-bit encoding's own rounding twice over. See {@link quantizeUpResiduals}. */ export declare const NORMAL_NEAR_LOSSLESS_STEP = 5; /** * NEAR-LOSSLESS, BY THE FILTER PNG ALREADY USES. Each channel is replaced, row by row, by the value nearest to it whose difference * from the (already replaced) pixel straight above is a multiple of `step`; row 0 is kept exact, so ground that does not change * from row to row (flat land, a uniform slope) is written exactly as before. PNG's Up filter then * sees a handful of residual values instead of a noisy spread, and deflate packs them several times tighter. The resolution, the * channels and the decoded format are unchanged (still an RGB8 PNG, read by every runtime the same way); no channel moves by more * than `floor(step / 2)`. Pacifica's 2048^2 coarse map: 3.82 MB -> ~2.1 MB at step 5. Deterministic. */ export declare function quantizeUpResiduals(pixels: Uint8Array, width: number, height: number, channels: number, step: number): Uint8Array; /** * An RGB8 normal map as the PNG the source folder and the scene resource ship: near-lossless, then every row Up-filtered and * deflated with the FILTERED strategy. Up is the predictor the step made exact, so it is used on every row rather than left to a * per-row heuristic (sharp/libpng's adaptive choice picked other filters and kept the file ~25% larger: 2.82 against 2.22 MB on * Pacifica's coarse map). A standard PNG any decoder reads; deterministic for a given zlib. */ export declare function encodeNormalPng(rgb: Uint8Array, width: number, height: number, step?: number): Promise; /** An 8-bit RGB (3 channels) or RGBA (4) PNG with filter type 2 (Up) on every row. */ export declare function encodeUpFilteredPng(pixels: Uint8Array, width: number, height: number, channels: 3 | 4): Uint8Array; /** An 8-bit RGB (3 channels) or RGBA (4) PNG with filter type 0 (None) on every row, deflated at level 9: the splat maps' form, which libpng writes the same way (filtering measured larger on their flat runs). */ export declare function encodeUnfilteredPng(pixels: Uint8Array, width: number, height: number, channels: 3 | 4): Uint8Array; /** * One tile's or the coarse layer's normal map as the PNG the source folder and the scene resource both ship. * * PNG ROW FILTERS ON. A normal map is a smooth gradient, which is exactly what PNG's predictive filters (Sub, Up, Paeth) * turn into near-zero residuals; with filtering off, deflate sees the raw bytes and does far worse. On mountainous * terrain the difference is large: Pacifica's 2048^2 coarse map is 5.21 MB unfiltered and 3.82 MB filtered (-27%), a * 512^2 tile 397 KB -> 234 KB (-41%), ~63 MB of tile normals across the map. The splat maps keep filtering off: they are * mostly flat runs, where it measured 4-10% LARGER. * * NEAR-LOSSLESS ON TOP (see {@link quantizeUpResiduals}): the filtered residuals of rough ground are still noise, and that noise * was ~3.8 MB on a phone's critical path for detail below what the 8-bit encoding resolves. Every channel stays within 2/255 of the * float field's normal, at the same resolution. */ export declare function bakeNormalMap(field: SampleField, region: NormalRegion): Promise;