Test layers on one engine and share selection and shader helpers

Layer display tests no longer re-check Cesium primitives in every layer:
they run on the fake engine, and one Cesium translation check per ground
kind lives in the Cesium engine's ground tests. Their harnesses are shared,
and the fake-engine, Cesium-engine and flights tests that repeated the
contract suite are gone, 340 tests in all.

The press-travel measurement is shared by the selection dispatcher and
CCTV, which loses its ScreenSpaceEventHandler shim and world-click module.
ALPR, installations and bikeshare share one selection keeper and selected
marker write. Layers with their own click rules keep their handlers.

Navara's pulse is a class like the ground pass, the ground and imagery
passes share the surface uniforms, and the colour, log-depth and occlusion
GLSL lives in one chunk module, each caller keeping its depth bias. The
ground suite runs inside the contract suite (--only=ground:), and fixture
and script names say what they test.

Behaviour is unchanged on both engines.
This commit is contained in:
German Khokhlov committed 2026-11-08 17:06:10 +04:00
1 parent 7f478e3815
commit b4556f9763
101 files changed
+1095 -4071

No files matched your search

+3
View File
@@ -16,6 +16,9 @@ import * as geo from '../../../geo/index.js';
const { cartesian3, ellipsoid } = geo;
const DEG = Math.PI / 180;
/** Reveal fraction within a packed corridor item. */
export const REVEAL_OFFSET = 20;
/** Pieces a tile holds before it splits. */
export const TILE_PIECES = 20000;
/** A piece's longest arc, degrees. */
-61
View File
@@ -1,61 +0,0 @@
import { Effect, EffectAttribute } from 'postprocessing';
import { withFrameUpdates, withPassDisposal } from '../frameDescriptor.js';
/**
* A screen-space pass on a Navara view, registered once per view under `key`.
* `insertAfter` and `insertBefore` place it in the view's effect chain.
* `uniforms()` lists the pass's [name, Uniform] entries; `update` and
* `destroy` run as the descriptor's updateFrame and onDestroy, with the
* descriptor as `this` (its `effect`, `owner`, `view`, `ctx` and `find`).
* The owner is the `owner` of the config added with `view.addEffect`.
*/
export function defineGroundEffect({
key,
name,
fragmentShader,
uniforms,
insertAfter,
insertBefore,
update,
destroy,
}) {
const registered = new WeakSet();
const descriptor = (EffectDesc, NavaraEffect) =>
class GroundEffectDesc extends withPassDisposal(
withFrameUpdates(EffectDesc),
) {
static allowDuplication = true;
static key = key;
static insertAfter = insertAfter;
static insertBefore = insertBefore;
constructor(view, context, config) {
super(view, context, config);
this.owner = config[key].owner;
}
createPass() {
this.effect = new Effect(name, fragmentShader, {
// Keep a separate pass: inputColor is the already tone-mapped frame.
attributes: EffectAttribute.CONVOLUTION,
uniforms: uniforms && new Map(uniforms()),
});
return new NavaraEffect(this.view.camera.raw, this.effect);
}
updateFrame() {
update.call(this);
}
onDestroy() {
destroy?.call(this);
this.effect?.dispose();
super.onDestroy();
}
};
return {
key,
/** Register the pass on `view` the first time it is used there. */
register(view, { EffectDesc, NavaraEffect }) {
if (registered.has(view)) return;
view.registerEffect(key, descriptor(EffectDesc, NavaraEffect));
registered.add(view);
},
};
}
+11 -3
View File
@@ -12,7 +12,7 @@
import { createGroundRegistry } from '../../ground.js';
import { composeGround, packHeights, packSet } from './pack.js';
import { ITEM_TEXELS } from './corridors.js';
import { REVEAL_OFFSET, ITEM_TEXELS } from './corridors.js';
// Frames before the first new try at a set's missing terrain heights; each
// later try waits twice as long, up to RETRIES tries.
@@ -61,7 +61,11 @@ export function createNavaraGround(
};
const pack = (entry) => {
entry.pack = packSet(entry.options.kind, entry.items, { terrainHeight });
for (let at = 20; at < entry.pack.items.length; at += ITEM_TEXELS * 4)
for (
let at = REVEAL_OFFSET;
at < entry.pack.items.length;
at += ITEM_TEXELS * 4
)
entry.pack.items[at] = entry.fraction;
entry.wait = entry.pack.heights.some(Number.isNaN) ? RETRY_FRAMES : 0;
};
@@ -122,7 +126,11 @@ export function createNavaraGround(
if (entry.fraction === fraction) return;
entry.fraction = fraction;
if (entry.pack) {
for (let at = 20; at < entry.pack.items.length; at += ITEM_TEXELS * 4)
for (
let at = REVEAL_OFFSET;
at < entry.pack.items.length;
at += ITEM_TEXELS * 4
)
entry.pack.items[at] = fraction;
if (entry.offset !== null)
pass.reveal(
+11 -21
View File
@@ -13,6 +13,7 @@
// materials, from the time uniform (src/globe/ground.js groundSeconds).
// No effect remains in the chain while no item is drawn.
import { DISPLAY_COLOR_GLSL, VIEW_POSITION_GLSL } from '../shaderChunks.js';
import { EffectDesc, Effect as NavaraEffect } from '@navaramap/three';
import { Effect, EffectAttribute } from 'postprocessing';
import {
@@ -20,13 +21,13 @@ import {
FloatType,
Matrix4,
NearestFilter,
RGBADepthPacking,
RGBAFormat,
Uniform,
} from 'three';
import { DASH_EDGE, groundSeconds } from '../../ground.js';
import { groundSurfaceUniforms, updateGroundSurface } from './surface.js';
import { withFrameUpdates, withPassDisposal } from '../frameDescriptor.js';
import { ITEM_TEXELS, LOOK, MARGIN_RATIO } from './corridors.js';
import { REVEAL_OFFSET, ITEM_TEXELS, LOOK, MARGIN_RATIO } from './corridors.js';
import {
GRID_COLS,
GRID_ROWS,
@@ -60,12 +61,8 @@ uniform float uPixelRatio;
vec4 atSlot(highp sampler2D image, int slot) {
return texelFetch(image, ivec2(slot & ${ROW - 1}, slot >> ${Math.log2(ROW)}), 0);
}
vec3 toDisplay(vec3 c) {
return mix(12.92*c,1.055*pow(max(c,vec3(0.0)),vec3(1.0/2.4))-0.055,step(vec3(0.0031308),c));
}
vec3 toLinear(vec3 c) {
return mix(c/12.92,pow(max((c+0.055)/1.055,vec3(0.0)),vec3(2.4)),step(vec3(0.04045),c));
}
${DISPLAY_COLOR_GLSL}
${VIEW_POSITION_GLSL}
// A corridor item over the colour, nearest metres from its line and along
// metres from its start: its width, glow, pulse and dash, in LDR and
// premultiplied, as Cesium writes ground polylines.
@@ -122,9 +119,9 @@ vec3 blendCorridor(vec3 color, int item, float nearest, vec2 normal, float along
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
outputColor = inputColor;
float depth = unpackRGBAToDepth(texture2D(tAllDepth, uv));
float distance = exp2(2.0 * depth / uLogDepthFC) - 1.0;
float distance = viewDistance(depth, uLogDepthFC);
vec4 ray = uInverseProjection * vec4(uv * 2.0 - 1.0, -1.0, 1.0);
vec3 point = ray.xyz * (distance / -ray.z);
vec3 point = viewPosition(ray, distance);
// Derivatives before any divergent branch: neighbours test other items.
vec3 pointDx = dFdx(point);
vec3 pointDy = dFdy(point);
@@ -403,8 +400,7 @@ class GroundEffectDesc extends withPassDisposal(withFrameUpdates(EffectDesc)) {
// Its own pass: inputColor is the tone-mapped frame.
attributes: EffectAttribute.CONVOLUTION,
uniforms: new Map([
['tAllDepth', new Uniform(null)],
['tSurfaceDepth', new Uniform(null)],
...groundSurfaceUniforms(),
['tFrames', new Uniform(null)],
['tStyles', new Uniform(null)],
['tSegments', new Uniform(null)],
@@ -413,9 +409,7 @@ class GroundEffectDesc extends withPassDisposal(withFrameUpdates(EffectDesc)) {
['tItems', new Uniform(null)],
['tGrid', new Uniform(null)],
['tCandidates', new Uniform(null)],
['uInverseProjection', new Uniform(new Matrix4())],
['uViewToWorld', new Uniform(new Matrix4())],
['uLogDepthFC', new Uniform(1)],
['uTime', new Uniform(0)],
['uPixelRatio', new Uniform(1)],
]),
@@ -428,8 +422,7 @@ class GroundEffectDesc extends withPassDisposal(withFrameUpdates(EffectDesc)) {
const owner = this.owner;
if (!this.effect || !camera || !owner.state) return;
const mrt = this.find('mrt');
if (mrt?.depthBufferPacking !== RGBADepthPacking)
throw new Error('The ground pass needs packed scene depth');
updateGroundSurface(this.effect, camera, this.ctx, mrt);
const input = this.ctx.getInputBuffer();
const { state } = owner;
if (
@@ -451,11 +444,7 @@ class GroundEffectDesc extends withPassDisposal(withFrameUpdates(EffectDesc)) {
textures.candidates.needsUpdate = true;
}
const u = this.effect.uniforms;
u.get('tAllDepth').value = mrt.depthBuffer;
u.get('tSurfaceDepth').value = this.ctx.getRenderTarget().depthTexture;
u.get('uInverseProjection').value.copy(camera.projectionMatrixInverse);
u.get('uViewToWorld').value.copy(camera.matrixWorld);
u.get('uLogDepthFC').value = 2 / Math.log2(camera.far + 1);
u.get('uTime').value = groundSeconds();
const cssWidth = this.view.canvas?.clientWidth;
u.get('uPixelRatio').value = cssWidth > 0 ? input.width / cssWidth : 1;
@@ -504,7 +493,8 @@ export function createGroundPass(view) {
reveal(offset, count, fraction) {
if (!owner.state) return;
for (let i = 0; i < count; i++)
owner.state.items.data[offset + i * ITEM_TEXELS * 4 + 20] = fraction;
owner.state.items.data[offset + i * ITEM_TEXELS * 4 + REVEAL_OFFSET] =
fraction;
owner.textures.items.needsUpdate = true;
},
textureBytes: () => textureBytes(owner.state),
+59 -38
View File
@@ -1,13 +1,15 @@
// Ground pulse fields over the visible globe, after tone mapping.
import { DISPLAY_COLOR_GLSL, VIEW_POSITION_GLSL } from '../shaderChunks.js';
import { Matrix4, Uniform, Vector3, Vector4 } from 'three';
import { groundSurfaceUniforms, updateGroundSurface } from './surface.js';
import { defineGroundEffect } from './effect.js';
import { EffectDesc, Effect as NavaraEffect } from '@navaramap/three';
import { Effect, EffectAttribute } from 'postprocessing';
import { withFrameUpdates, withPassDisposal } from '../frameDescriptor.js';
const KEY = 'gevGroundPulses';
const fragmentShader = /* glsl */ `
uniform sampler2D tAllDepth;
uniform sampler2D tSurfaceDepth;
uniform mat4 uInverseProjection;
uniform mat4 uInverseView;
uniform float uLogDepthFC;
@@ -23,12 +25,8 @@ uniform float uDepth;
uniform float uLineWidth;
uniform float uHaloWidth;
uniform float uPixelRatio;
vec3 toDisplay(vec3 c) {
return mix(12.92*c,1.055*pow(max(c,vec3(0.0)),vec3(1.0/2.4))-0.055,step(vec3(0.0031308),c));
}
vec3 toLinear(vec3 c) {
return mix(c/12.92,pow(max((c+0.055)/1.055,vec3(0.0)),vec3(2.4)),step(vec3(0.04045),c));
}
${DISPLAY_COLOR_GLSL}
${VIEW_POSITION_GLSL}
vec4 over(vec4 top, vec4 under) {
float a = top.a + under.a * (1.0 - top.a);
if (a <= 0.0) return vec4(0.0);
@@ -37,9 +35,9 @@ vec4 over(vec4 top, vec4 under) {
void mainImage(const in vec4 inputColor,const in vec2 uv,out vec4 outputColor) {
outputColor=inputColor;
float depth=unpackRGBAToDepth(texture2D(tAllDepth,uv));
float distance=exp2(2.0*depth/uLogDepthFC)-1.0;
float distance=viewDistance(depth, uLogDepthFC);
vec4 ray=uInverseProjection*vec4(uv*2.0-1.0,-1.0,1.0);
vec3 point=ray.xyz*(distance/-ray.z);
vec3 point=viewPosition(ray, distance);
vec3 origin=uInverseView[3].xyz;
vec3 direction=normalize((uInverseView*vec4(ray.xyz,0.0)).xyz);
vec3 o=origin/uRadiiM;
@@ -81,36 +79,49 @@ void mainImage(const in vec4 inputColor,const in vec2 uv,out vec4 outputColor) {
}
`;
const pulseEffect = defineGroundEffect({
key: KEY,
name: 'GevGroundPulses',
fragmentShader,
insertAfter: ['gevGround', 'gevImagery', 'toneMapping'],
insertBefore: [
class PulseEffectDesc extends withPassDisposal(withFrameUpdates(EffectDesc)) {
static allowDuplication = true;
static key = KEY;
static insertAfter = ['gevGround', 'gevImagery', 'toneMapping'];
static insertBefore = [
'gevPreSharpenOverlay',
'gevSharpen',
'smaa',
'fxaa',
'gevOverlay',
'final',
],
uniforms: () => [
...groundSurfaceUniforms(),
['uInverseView', new Uniform(new Matrix4())],
['uCenter', new Uniform(new Vector3(1, 0, 0))],
['uRadiusAngle', new Uniform(1)],
['uRadiiM', new Uniform(new Vector3())],
['uColor', new Uniform(new Vector4())],
['uLineColor', new Uniform(new Vector4())],
['uHaloColor', new Uniform(new Vector4())],
['uRadii', new Uniform(new Vector4())],
['uAlphas', new Uniform(new Vector4())],
['uDepth', new Uniform(0.35)],
['uLineWidth', new Uniform(3)],
['uHaloWidth', new Uniform(1)],
['uPixelRatio', new Uniform(1)],
],
update() {
];
constructor(view, context, config) {
super(view, context, config);
this.owner = config[KEY].owner;
}
createPass() {
this.effect = new Effect('GevGroundPulses', fragmentShader, {
// Input color is the tone-mapped frame.
attributes: EffectAttribute.CONVOLUTION,
uniforms: new Map([
...groundSurfaceUniforms({ surface: false }),
['uInverseView', new Uniform(new Matrix4())],
['uCenter', new Uniform(new Vector3(1, 0, 0))],
['uRadiusAngle', new Uniform(1)],
['uRadiiM', new Uniform(new Vector3())],
['uColor', new Uniform(new Vector4())],
['uLineColor', new Uniform(new Vector4())],
['uHaloColor', new Uniform(new Vector4())],
['uRadii', new Uniform(new Vector4())],
['uAlphas', new Uniform(new Vector4())],
['uDepth', new Uniform(0.35)],
['uLineWidth', new Uniform(3)],
['uHaloWidth', new Uniform(1)],
['uPixelRatio', new Uniform(1)],
]),
});
return new NavaraEffect(this.view.camera.raw, this.effect);
}
updateFrame() {
const owner = this.owner,
camera = this.view.camera.raw;
if (!this.effect || !camera) return;
@@ -139,8 +150,15 @@ const pulseEffect = defineGroundEffect({
cssWidth > 0
? this.ctx.getInputBuffer().width / cssWidth
: globalThis.devicePixelRatio || 1;
},
});
}
onDestroy() {
this.effect?.dispose();
super.onDestroy();
}
}
const registered = new WeakSet();
/**
* The pulse disc on one Navara view around `center` (Earth-fixed metres):
@@ -149,7 +167,7 @@ const pulseEffect = defineGroundEffect({
* rgba arrays in 0..1: the band, the pulse line and its halo.
*/
export function createNavaraPulseField(
{ view, EffectDesc, NavaraEffect, canvas },
{ view, canvas },
{
center,
radiusM,
@@ -162,7 +180,10 @@ export function createNavaraPulseField(
haloWidth,
},
) {
pulseEffect.register(view, { EffectDesc, NavaraEffect });
if (!registered.has(view)) {
view.registerEffect(KEY, PulseEffectDesc);
registered.add(view);
}
const owner = {
cssWidth: () => canvas?.clientWidth ?? 0,
center: new Vector3(),
+22 -2
View File
@@ -1,7 +1,27 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import * as geo from '../../../geo/index.js';
import { createNavaraPulseField } from './pulse.js';
import { registerHooks } from 'node:module';
const hook = registerHooks({
resolve(specifier, context, next) {
if (
specifier === '@navaramap/three' &&
context.parentURL?.endsWith('/ground/pulse.js')
)
return {
url: 'data:text/javascript,export class EffectDesc {} export class Effect {}',
shortCircuit: true,
};
return next(specifier, context);
},
});
let createNavaraPulseField;
try {
({ createNavaraPulseField } = await import('./pulse.js'));
} finally {
hook.deregister();
}
test('the Navara pulse disc draws only while the pulses run', () => {
const effects = [];
@@ -25,7 +45,7 @@ test('the Navara pulse disc draws only while the pulses run', () => {
},
};
const disc = createNavaraPulseField(
{ view, EffectDesc: class {}, NavaraEffect: class {} },
{ view },
{
center: geo.cartesian3.fromDegrees(3, 27, 0),
radiusM: 250_000,
+4 -3
View File
@@ -1,9 +1,9 @@
// Public depth inputs shared by actual terrain/tiles classifiers.
import { Matrix4, Uniform, RGBADepthPacking } from 'three';
export function groundSurfaceUniforms() {
export function groundSurfaceUniforms({ surface = true } = {}) {
return [
['tAllDepth', new Uniform(null)],
['tSurfaceDepth', new Uniform(null)],
...(surface ? [['tSurfaceDepth', new Uniform(null)]] : []),
['uInverseProjection', new Uniform(new Matrix4())],
['uLogDepthFC', new Uniform(1)],
];
@@ -13,7 +13,8 @@ export function updateGroundSurface(effect, camera, context, mrt) {
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;
if (u.has('tSurfaceDepth'))
u.get('tSurfaceDepth').value = context.getRenderTarget().depthTexture;
u.get('uInverseProjection').value.copy(camera.projectionMatrixInverse);
u.get('uLogDepthFC').value = 2 / Math.log2(camera.far + 1);
}
+12 -19
View File
@@ -15,9 +15,14 @@
// slot's position, taken outside any divergent branch. Costs nothing while
// no layer is drawn (the effect is hidden).
import { DISPLAY_COLOR_GLSL, VIEW_POSITION_GLSL } from '../shaderChunks.js';
import { EffectDesc, Effect as NavaraEffect } from '@navaramap/three';
import { Effect, EffectAttribute } from 'postprocessing';
import { DataTexture, Matrix4, RGBADepthPacking, Uniform } from 'three';
import { DataTexture, Matrix4, Uniform } from 'three';
import {
groundSurfaceUniforms,
updateGroundSurface,
} from '../ground/surface.js';
import { withFrameUpdates, withPassDisposal } from '../frameDescriptor.js';
import { MAX_IMAGERY_SLOTS } from './index.js';
@@ -39,12 +44,8 @@ uniform vec4 uBounds${i};
uniform vec4 uLook${i};
uniform float uRaise${i};`,
).join('\n')}
vec3 toDisplay(vec3 c) {
return mix(12.92*c,1.055*pow(max(c,vec3(0.0)),vec3(1.0/2.4))-0.055,step(vec3(0.0031308),c));
}
vec3 toLinear(vec3 c) {
return mix(c/12.92,pow(max((c+0.055)/1.055,vec3(0.0)),vec3(2.4)),step(vec3(0.04045),c));
}
${DISPLAY_COLOR_GLSL}
${VIEW_POSITION_GLSL}
// Geodetic longitude and latitude (Bowring) of a world point, degrees.
vec2 geodetic(vec3 point) {
float p = length(point.xy);
@@ -130,9 +131,9 @@ void derivatives(vec2 geo, vec2 merc, float drawn, out vec2 geoDx, out vec2 geoD
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
outputColor = inputColor;
float depth = unpackRGBAToDepth(texture2D(tAllDepth, uv));
float distance = exp2(2.0 * depth / uLogDepthFC) - 1.0;
float distance = viewDistance(depth, uLogDepthFC);
vec4 ray = uInverseProjection * vec4(uv * 2.0 - 1.0, -1.0, 1.0);
vec3 point = (uWorld * vec4(ray.xyz * (distance / -ray.z), 1.0)).xyz;
vec3 point = (uWorld * vec4(viewPosition(ray, distance), 1.0)).xyz;
// The ground: the scene depth where it is the surface (the packed depth
// also holds forward meshes, which are not ground).
float ground = (1.0 - step(1.0, depth)) *
@@ -201,11 +202,8 @@ class ImageryEffectDesc extends withPassDisposal(withFrameUpdates(EffectDesc)) {
// Its own pass: inputColor is the tone-mapped frame.
attributes: EffectAttribute.CONVOLUTION,
uniforms: new Map([
['tAllDepth', new Uniform(null)],
['tSurfaceDepth', new Uniform(null)],
['uInverseProjection', new Uniform(new Matrix4())],
...groundSurfaceUniforms(),
['uWorld', new Uniform(new Matrix4())],
['uLogDepthFC', new Uniform(1)],
['uSplit', new Uniform(0.5)],
...SLOTS.flatMap((i) => [
[`tImage${i}`, new Uniform(null)],
@@ -224,14 +222,9 @@ class ImageryEffectDesc extends withPassDisposal(withFrameUpdates(EffectDesc)) {
const owner = this.owner;
if (!this.effect || !camera) return;
const mrt = this.find('mrt');
if (mrt?.depthBufferPacking !== RGBADepthPacking)
throw new Error('The imagery pass needs packed scene depth');
updateGroundSurface(this.effect, camera, this.ctx, mrt);
const u = this.effect.uniforms;
u.get('tAllDepth').value = mrt.depthBuffer;
u.get('tSurfaceDepth').value = this.ctx.getRenderTarget().depthTexture;
u.get('uInverseProjection').value.copy(camera.projectionMatrixInverse);
u.get('uWorld').value.copy(camera.matrixWorld);
u.get('uLogDepthFC').value = 2 / Math.log2(camera.far + 1);
u.get('uSplit').value = owner.split;
for (const i of SLOTS) {
const slot = owner.slots[i];
+2 -10
View File
@@ -2,12 +2,7 @@
// the product way (viewOptions.js) and the GlobeEngine on it. Load it with a
// dynamic import() so Navara stays out of the Cesium-mode bundle.
import ThreeView, {
Color as NavaraColor,
MeshDesc,
EffectDesc,
Effect as NavaraEffect,
} from '@navaramap/three';
import ThreeView, { Color as NavaraColor, MeshDesc } from '@navaramap/three';
import * as geo from '../../geo/index.js';
import { DefaultPlugin } from '@navaramap/three-default-plugin';
import { Pass } from 'postprocessing';
@@ -177,10 +172,7 @@ export async function createNavaraGlobe({ container, search, hd = false }) {
ground: createNavaraGround(view, {
createPass: createGroundPass,
pulseField: (options) =>
createNavaraPulseField(
{ view, EffectDesc, NavaraEffect, canvas },
options,
),
createNavaraPulseField({ view, canvas }, options),
}),
imagery: (parts) =>
createNavaraImagery(view, { ...parts, createPass: createImageryPass }),
+3 -1
View File
@@ -1,3 +1,4 @@
import { PACKED_DEPTH_GLSL } from './shaderChunks.js';
// The depth test of gev's screen overlays on Navara (sprites, points and
// lines drawn after tone mapping, overlay.js): there is no depth buffer in
// the post-processing chain, so each fragment compares its own logarithmic
@@ -15,6 +16,7 @@ export const OVERLAY_DEPTH_MODES = Object.freeze({
/** Fragment declarations: uniforms, the varying and gevOverlayHidden(). */
export const OVERLAY_DEPTH_FRAGMENT = /* glsl */ `
${PACKED_DEPTH_GLSL}
uniform sampler2D tGevSceneDepth;
uniform vec2 uGevResolution;
uniform float uGevDepthMode;
@@ -36,7 +38,7 @@ bool gevOverlayHidden() {
#else
float mine = gl_FragCoord.z;
#endif
bool occluded = mine > scene + 2e-6;
bool occluded = packedDepthOccluded(mine, scene, 2e-6);
return uGevDepthMode < 1.5 ? occluded : !occluded;
}
`;
+3 -1
View File
@@ -1,3 +1,4 @@
import { PACKED_DEPTH_GLSL } from './shaderChunks.js';
// Navara draws its transparent scene after the post effects, into a target
// that does not hold the scene's depth, so a transparent mesh behind a wall,
// terrain or the Earth painted through them. Moving such a mesh into the
@@ -15,6 +16,7 @@ const KEY = 'gevSceneDepth';
export const SCENE_DEPTH_BIAS = 5e-6;
const PARS = /* glsl */ `
${PACKED_DEPTH_GLSL}
uniform sampler2D tGevSceneDepth;
uniform vec2 uGevTargetSize;
uniform float uGevSceneDepthOn;
@@ -32,7 +34,7 @@ if (uGevSceneDepthOn > 0.5) {
#else
float gevDepth = gl_FragCoord.z;
#endif
if (gevScene < 1.0 && gevDepth > gevScene + ${SCENE_DEPTH_BIAS.toExponential()})
if (gevScene < 1.0 && packedDepthOccluded(gevDepth, gevScene, ${SCENE_DEPTH_BIAS.toExponential()}))
discard;
}
`;
+4 -1
View File
@@ -32,7 +32,10 @@ test('the scene-depth test goes after the log depth and brings packing once', ()
patched.indexOf('uniform float uGevSceneDepthOn;') <
patched.indexOf('void main() {'),
);
assert.match(patched, /gevDepth > gevScene \+ 5e-6\)\s*discard;/);
assert.match(
patched,
/packedDepthOccluded\(gevDepth, gevScene, 5e-6\)\)\s*discard;/,
);
}
assert.ok(SCENE_DEPTH_BIAS > 0 && SCENE_DEPTH_BIAS < 1e-4);
assert.throws(() => withSceneDepthTest('void main() {}'), /logdepthbuf/);
+24
View File
@@ -0,0 +1,24 @@
// Shader functions shared by the surface passes and depth tests.
export const DISPLAY_COLOR_GLSL = /* glsl */ `
vec3 toDisplay(vec3 c) {
return mix(12.92*c,1.055*pow(max(c,vec3(0.0)),vec3(1.0/2.4))-0.055,step(vec3(0.0031308),c));
}
vec3 toLinear(vec3 c) {
return mix(c/12.92,pow(max((c+0.055)/1.055,vec3(0.0)),vec3(2.4)),step(vec3(0.04045),c));
}
`;
export const VIEW_POSITION_GLSL = /* glsl */ `
vec3 viewPosition(vec4 ray, float distance) {
return ray.xyz * (distance / -ray.z);
}
float viewDistance(float depth, float logDepthFC) {
return exp2(2.0 * depth / logDepthFC) - 1.0;
}
`;
export const PACKED_DEPTH_GLSL = /* glsl */ `
bool packedDepthOccluded(float mine, float scene, float bias) {
return mine > scene + bias;
}
`;