29 lines
2.0 KiB
JavaScript
29 lines
2.0 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFile } from 'node:fs/promises';
|
|
import * as THREE from 'three';
|
|
import { DEPTH_REFRACTION } from '../src/constants/depth.ts';
|
|
|
|
const shader = await readFile(new URL('../src/shaders/mosaic.frag', import.meta.url), 'utf8');
|
|
const main = await readFile(new URL('../src/main.ts', import.meta.url), 'utf8');
|
|
const media = main.slice(main.indexOf('function applyMedia('), main.indexOf('function setDepth('));
|
|
assert.doesNotMatch(media, /photo(?:Zoom|PanX|PanY)\s*=/, 'media replacement preserves manual framing');
|
|
assert.match(shader, /sceneHit=refineSceneHit\(gh,normalize\(mix\(i,curvedRay,strength\)\),sceneHit,cellWorld\)/);
|
|
assert.match(shader, /if\(!reconstructScenePoint\(projectUv\(hit\),surface\)\)return artisticHit/);
|
|
assert.match(shader, /confidence=1\.-smoothstep/);
|
|
assert.match(shader, /delta\*=min\(1\.,limit\/max\(length\(delta\),.00001\)\)/);
|
|
// Analytic planar case for the correction's geometry. GPU execution is checked in-browser.
|
|
const camera = new THREE.Vector3(.25, 0, 3), glass = new THREE.Vector3(0, 0, .6);
|
|
const ray = new THREE.Vector3(-.15, 0, -1).normalize(), baseZ = .31;
|
|
const plane = glass.clone().addScaledVector(ray, (baseZ - glass.z) / ray.z);
|
|
function projectedAt(z) {
|
|
const hit = glass.clone().addScaledVector(ray, (z - glass.z) / ray.z);
|
|
const view = hit.clone().sub(camera);
|
|
return camera.clone().addScaledVector(view, (baseZ - camera.z) / view.z);
|
|
}
|
|
assert.ok(projectedAt(baseZ).distanceTo(plane) < 1e-10, 'reference plane introduces no correction');
|
|
assert.ok(projectedAt(.55).distanceTo(plane) > .001, 'near surface changes refracted sample');
|
|
assert.ok(DEPTH_REFRACTION.blend > 0 && DEPTH_REFRACTION.blend <= 1);
|
|
assert.ok(DEPTH_REFRACTION.blend * DEPTH_REFRACTION.maxCellCorrection < .25, 'correction stays below a quarter cell');
|
|
assert.match(shader, /environmentWeight=.*glossStrength.*clamp\(uStrength,0\.,1\.\)/);
|
|
console.log('Depth correction: planar identity, nonzero near correction, bounded shift, framing and reflection gates.');
|