mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Occlusion test without Cesium: the depth probe moves to render/occlusion and reads depth textures too
The GPU probe behind query.occlusionTest no longer depends on Cesium: a renderer hands it the frame's depth through readSource (a DepthSource), and createDepthOcclusionTest builds the query port's test from it. Besides depth packed into RGBA8, as Cesium keeps it for picking, it reads a depth texture (encoding 'depth', on the GPU only), and log depth with no near plane decodes too. Cesium's sceneOcclusionProbe.js keeps only its scene reader. Exported as gods-eye-view/render/occlusion.
This commit is contained in:
1 parent
619c19ea67
commit
730dff53dd
10 files changed
+952
-706
No files matched your search
@@ -9,10 +9,10 @@
|
||||
* The fix compares each such contact with what the renderer actually drew: if
|
||||
* the drawn surface along the contact's ray is nearer than the contact by more
|
||||
* than a small margin, something stands in front of it and its bracket and
|
||||
* callout are not drawn. The renderer's occlusion probe (an application hook;
|
||||
* the Cesium renderer's is `src/render/cesium/sceneOcclusionProbe.js`) runs
|
||||
* that comparison on the GPU, against the frame's own depth, and hands back a yes or no per contact a
|
||||
* frame or two later without ever waiting on the GPU. This file holds the
|
||||
* callout are not drawn. The renderer's occlusion test (`query.occlusionTest`;
|
||||
* the GPU probe is `src/render/occlusion/depthProbe.js`) runs that comparison
|
||||
* on the GPU, against the frame's own depth, and hands back a yes or no per
|
||||
* contact a frame or two later without ever waiting on the GPU. This file holds the
|
||||
* arithmetic both sides share and the per-contact memory of the answers.
|
||||
*
|
||||
* Only contacts that opt in with `depthTested: true` are tested: the ones whose
|
||||
@@ -120,9 +120,12 @@ export function unpackDepth(bytes, offset) {
|
||||
*/
|
||||
export function depthToViewDistance(depth, near, far, logDepth) {
|
||||
if (!(depth > 0) || !(depth < 1)) return Number.NaN;
|
||||
if (!(near > 0) || !(far > near)) return Number.NaN;
|
||||
if (!(near >= 0) || !(far > near)) return Number.NaN;
|
||||
if (logDepth)
|
||||
return near + Math.pow(2, depth * Math.log2(far - near + 1)) - 1;
|
||||
// Standard depth needs a near plane in front of the eye; log depth does not
|
||||
// (as WebGL log depth writes it, with none).
|
||||
if (!(near > 0)) return Number.NaN;
|
||||
return (near * far) / (far - depth * (far - near));
|
||||
}
|
||||
|
||||
@@ -186,7 +189,7 @@ export function projectContact(view, tanHalfFovX, tanHalfFovY, position, out) {
|
||||
|
||||
/**
|
||||
* One frame of depth read back to memory, with the camera it was drawn from.
|
||||
* Only the synchronous fallback uses this (see `src/render/cesium/sceneOcclusionProbe.js`); the
|
||||
* Only the synchronous fallback uses this (see `src/render/occlusion/depthProbe.js`); the
|
||||
* normal path never copies depth off the GPU.
|
||||
*
|
||||
* `bytes` holds `frustums.length` stacked images of `width` x `height` RGBA8
|
||||
|
||||
@@ -107,9 +107,19 @@ test('the ends of the depth range, and a bad range, mean nothing was drawn', ()
|
||||
assert.ok(Number.isNaN(depthToViewDistance(0, 1, 100, log)));
|
||||
assert.ok(Number.isNaN(depthToViewDistance(1, 1, 100, log)));
|
||||
assert.ok(Number.isNaN(depthToViewDistance(Number.NaN, 1, 100, log)));
|
||||
assert.ok(Number.isNaN(depthToViewDistance(0.5, 0, 100, log)));
|
||||
assert.ok(Number.isNaN(depthToViewDistance(0.5, -1, 100, log)));
|
||||
assert.ok(Number.isNaN(depthToViewDistance(0.5, 100, 100, log)));
|
||||
}
|
||||
// No near plane: standard depth has nothing to decode against.
|
||||
assert.ok(Number.isNaN(depthToViewDistance(0.5, 0, 100, false)));
|
||||
});
|
||||
|
||||
test('log depth with no near plane decodes as it is written with none', () => {
|
||||
// Written as log2(1 + d) / log2(far + 1).
|
||||
const depth = Math.log2(1 + 400) / Math.log2(100_000 + 1);
|
||||
assert.ok(
|
||||
Math.abs(depthToViewDistance(depth, 0, 100_000, true) - 400) < 1e-6,
|
||||
);
|
||||
});
|
||||
|
||||
const IDENTITY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
||||
|
||||
Reference in new issue
Block a user