feat(firms): add Navara renderer checkpoint

This commit is contained in:
German Khokhlov committed 2026-10-28 09:36:50 +04:00
1 parent a9b3125a99
commit 5dd05a4a81
33 files changed
+2112 -285

No files matched your search

+8 -33
View File
@@ -2,15 +2,13 @@
// Navara post-effect. Native ground colour blends in display space; doing
// it explicitly preserves translucent colours and overlap order.
import { Effect, EffectAttribute } from 'postprocessing';
import { Uniform } from 'three';
import {
DataTexture,
FloatType,
RGBAFormat,
NearestFilter,
Matrix4,
Uniform,
RGBADepthPacking,
} from 'three';
createGroundTexture as texture,
createGroundStorage as storage,
groundSurfaceUniforms,
updateGroundSurface,
} from '../../shared/render/navaraGroundSurface.js';
import * as geo from '../../../geo/index.js';
import {
DISC_EDGES,
@@ -103,19 +101,6 @@ void mainImage(const in vec4 inputColor,const in vec2 uv,out vec4 outputColor) {
outputColor=vec4(toLinear(color),inputColor.a);
}
`;
function texture(data, width, height) {
const t = new DataTexture(data, width, height, RGBAFormat, FloatType);
t.minFilter = NearestFilter;
t.magFilter = NearestFilter;
t.needsUpdate = true;
return t;
}
function storage(texels) {
const width = Math.min(1024, Math.max(1, texels));
const height = Math.max(1, Math.ceil(texels / width));
const data = new Float32Array(width * height * 4);
return { data, width, height, texture: texture(data, width, height) };
}
function buildState(discs) {
const frames = discs.map(discFrame);
const edges = storage(discs.length * DISC_EDGES);
@@ -225,8 +210,7 @@ function groundEffectClass(EffectDesc, NavaraEffect) {
// Keep a separate pass: inputColor is the already tone-mapped frame.
attributes: EffectAttribute.CONVOLUTION,
uniforms: new Map([
['tAllDepth', new Uniform(null)],
['tSurfaceDepth', new Uniform(null)],
...groundSurfaceUniforms(),
['tEdges', new Uniform(null)],
['tFrames', new Uniform(null)],
['tGrid', new Uniform(null)],
@@ -234,8 +218,6 @@ function groundEffectClass(EffectDesc, NavaraEffect) {
['uEdgeSize', new Uniform([1, 1])],
['uFrameSize', new Uniform([1, 1])],
['uCandidateSize', new Uniform([1, 1])],
['uInverseProjection', new Uniform(new Matrix4())],
['uLogDepthFC', new Uniform(1)],
]),
});
return new NavaraEffect(this.view.camera.raw, this.effect);
@@ -245,14 +227,9 @@ function groundEffectClass(EffectDesc, NavaraEffect) {
camera = this.view.camera.raw,
mrt = this.find('mrt');
if (!this.effect || !camera || !state) return;
if (mrt?.depthBufferPacking !== RGBADepthPacking)
throw new Error(
'Earthquake classification requires packed scene depth',
);
updateGroundSurface(this.effect, camera, this.ctx, mrt);
state.update(camera, this.ctx);
const u = this.effect.uniforms;
u.get('tAllDepth').value = mrt.depthBuffer;
u.get('tSurfaceDepth').value = this.ctx.getRenderTarget().depthTexture;
u.get('tEdges').value = state.edges.texture;
u.get('uEdgeSize').value = [state.edges.width, state.edges.height];
u.get('tFrames').value = state.packed.texture;
@@ -263,8 +240,6 @@ function groundEffectClass(EffectDesc, NavaraEffect) {
state.candidates.width,
state.candidates.height,
];
u.get('uInverseProjection').value.copy(camera.projectionMatrixInverse);
u.get('uLogDepthFC').value = 2 / Math.log2(camera.far + 1);
}
onDestroy() {
this.effect?.dispose();
@@ -78,65 +78,7 @@ export function discFrame(disc) {
};
}
/** Camera-relative transforms in JS float64; only nearby metres enter GLSL. */
export function viewFrame(frame, matrix, out) {
const m = matrix.elements;
const transform = (p, offset, translate) => {
out[offset] =
m[0] * p.x + m[4] * p.y + m[8] * p.z + (translate ? m[12] : 0);
out[offset + 1] =
m[1] * p.x + m[5] * p.y + m[9] * p.z + (translate ? m[13] : 0);
out[offset + 2] =
m[2] * p.x + m[6] * p.y + m[10] * p.z + (translate ? m[14] : 0);
};
transform(frame.center, 0, true);
transform(frame.east, 3, false);
transform(frame.north, 6, false);
transform(frame.up, 9, false);
return out;
}
/** Conservative clip bounds, including a camera inside/crossing the volume. */
export function discClipBounds(frame, view, projection, out) {
const p = projection.elements;
let x0 = 1,
y0 = 1,
x1 = -1,
y1 = -1,
front = 0,
behind = 0;
for (let i = 0; i < 8; i++) {
const x = (i & 1 ? 1 : -1) * frame.radius;
const y = (i & 2 ? 1 : -1) * frame.radius;
const z = i & 4 ? frame.ceiling : frame.floor;
const vx = view[0] + view[3] * x + view[6] * y + view[9] * z;
const vy = view[1] + view[4] * x + view[7] * y + view[10] * z;
const vz = view[2] + view[5] * x + view[8] * y + view[11] * z;
const w = p[3] * vx + p[7] * vy + p[11] * vz + p[15];
if (w <= 0) {
behind++;
continue;
}
front++;
const cx = (p[0] * vx + p[4] * vy + p[8] * vz + p[12]) / w;
const cy = (p[1] * vx + p[5] * vy + p[9] * vz + p[13]) / w;
x0 = Math.min(x0, cx);
y0 = Math.min(y0, cy);
x1 = Math.max(x1, cx);
y1 = Math.max(y1, cy);
}
if (front && behind) {
x0 = -1;
y0 = -1;
x1 = 1;
y1 = 1;
}
if (!front || x1 < -1 || y1 < -1 || x0 > 1 || y0 > 1) out.fill(2);
else {
out[0] = Math.max(-1, x0);
out[1] = Math.max(-1, y0);
out[2] = Math.min(1, x1);
out[3] = Math.min(1, y1);
}
return out;
}
export {
viewFrame,
groundClipBounds as discClipBounds,
} from '../../shared/render/navaraGroundGeometry.js';
+5 -69
View File
@@ -1,69 +1,5 @@
// A screen grid of conservative projected volumes. Prefix-sum storage has
// no feature/cell cap: overlapping discs retain their source order.
export const GRID_COLS = 32;
export const GRID_ROWS = 20;
export function createDiscGrid(count) {
const counts = new Uint32Array(GRID_COLS * GRID_ROWS);
const offsets = new Uint32Array(counts.length);
const cursor = new Uint32Array(counts.length);
const bounds = new Float64Array(count * 4);
const ranges = new Int32Array(count * 4);
let indices = new Uint32Array(0);
const clamp = (value, max) => Math.min(max - 1, Math.max(0, value));
return {
bounds,
counts,
offsets,
get indices() {
return indices;
},
pack() {
counts.fill(0);
for (let i = 0; i < count; i++) {
const b = i * 4;
const valid =
bounds[b] <= bounds[b + 2] &&
bounds[b + 1] <= bounds[b + 3] &&
bounds[b] <= 1 &&
bounds[b + 1] <= 1 &&
bounds[b + 2] >= -1 &&
bounds[b + 3] >= -1;
ranges[b] = valid
? clamp(Math.floor((bounds[b] * 0.5 + 0.5) * GRID_COLS), GRID_COLS)
: -1;
ranges[b + 1] = clamp(
Math.floor((bounds[b + 1] * 0.5 + 0.5) * GRID_ROWS),
GRID_ROWS,
);
ranges[b + 2] = clamp(
Math.floor((bounds[b + 2] * 0.5 + 0.5) * GRID_COLS),
GRID_COLS,
);
ranges[b + 3] = clamp(
Math.floor((bounds[b + 3] * 0.5 + 0.5) * GRID_ROWS),
GRID_ROWS,
);
if (!valid) continue;
for (let y = ranges[b + 1]; y <= ranges[b + 3]; y++)
for (let x = ranges[b]; x <= ranges[b + 2]; x++)
counts[y * GRID_COLS + x]++;
}
let total = 0;
for (let i = 0; i < counts.length; i++) {
offsets[i] = total;
total += counts[i];
cursor[i] = offsets[i];
}
if (indices.length < total)
indices = new Uint32Array(Math.max(total, indices.length * 2));
for (let i = 0; i < count; i++) {
const b = i * 4;
if (ranges[b] < 0) continue;
for (let y = ranges[b + 1]; y <= ranges[b + 3]; y++)
for (let x = ranges[b]; x <= ranges[b + 2]; x++)
indices[cursor[y * GRID_COLS + x]++] = i;
}
return total;
},
};
}
export {
GRID_COLS,
GRID_ROWS,
createGroundGrid as createDiscGrid,
} from '../../shared/render/navaraGroundGrid.js';