mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
feat(firms): add Navara renderer checkpoint
This commit is contained in:
1 parent
a9b3125a99
commit
5dd05a4a81
33 files changed
+2112
-285
No files matched your search
@@ -0,0 +1,62 @@
|
||||
/** 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 groundClipBounds(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;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// A screen grid of conservative projected volumes. Prefix-sum storage has
|
||||
// no feature/cell cap: overlapping shapes retain their source order.
|
||||
export const GRID_COLS = 64;
|
||||
export const GRID_ROWS = 40;
|
||||
export function createGroundGrid(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;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// Public depth inputs shared by actual terrain/tiles classifiers.
|
||||
import {
|
||||
DataTexture,
|
||||
FloatType,
|
||||
RGBAFormat,
|
||||
NearestFilter,
|
||||
Matrix4,
|
||||
Uniform,
|
||||
RGBADepthPacking,
|
||||
} from 'three';
|
||||
export function createGroundTexture(data, width, height) {
|
||||
const texture = new DataTexture(data, width, height, RGBAFormat, FloatType);
|
||||
texture.minFilter = NearestFilter;
|
||||
texture.magFilter = NearestFilter;
|
||||
texture.needsUpdate = true;
|
||||
return texture;
|
||||
}
|
||||
export function createGroundStorage(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: createGroundTexture(data, width, height),
|
||||
};
|
||||
}
|
||||
export function groundSurfaceUniforms() {
|
||||
return [
|
||||
['tAllDepth', new Uniform(null)],
|
||||
['tSurfaceDepth', new Uniform(null)],
|
||||
['uInverseProjection', new Uniform(new Matrix4())],
|
||||
['uLogDepthFC', new Uniform(1)],
|
||||
];
|
||||
}
|
||||
export function updateGroundSurface(effect, camera, context, mrt) {
|
||||
if (mrt?.depthBufferPacking !== RGBADepthPacking)
|
||||
throw new Error('Ground classification requires packed scene depth');
|
||||
const u = effect.uniforms;
|
||||
u.get('tAllDepth').value = mrt.depthBuffer;
|
||||
u.get('tSurfaceDepth').value = context.getRenderTarget().depthTexture;
|
||||
u.get('uInverseProjection').value.copy(camera.projectionMatrixInverse);
|
||||
u.get('uLogDepthFC').value = 2 / Math.log2(camera.far + 1);
|
||||
}
|
||||
Reference in new issue
Block a user