import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; const reeded=await readFile(new URL('../src/shaders/reeded.frag',import.meta.url),'utf8'); const frosted=await readFile(new URL('../src/shaders/frosted.frag',import.meta.url),'utf8'); // The shaders expose a small pure GLSL helper; execute that exact arithmetic in JS. function stableUv(shader) { const body=shader.match(/vec2 patternScreenUv\(vec2 uv\)\{return ([^;]+);\}/)?.[1]; assert.ok(body,'legacy screen-pattern coordinates must compensate projection zoom'); const expression=body.replaceAll('uv','component').replaceAll('uSceneOffset','offset').replaceAll('uSceneZoom','zoom').replaceAll('max(','Math.max('); return new Function('component','zoom','offset',`return ${expression};`); } for(const shader of [reeded,frosted]) { const stable=stableUv(shader); for(const original of [.1,.25,.5,.8]) for(const zoom of [1,1.5,2,3]) for(const offset of [0,.2,-.6]) { const projected=.5+(original-.5)*zoom+offset*.5; assert.ok(Math.abs(stable(projected,zoom,offset)-original)<1e-12,'the same material point keeps its original pattern coordinate under projection zoom'); } assert.match(shader,/patternScreenUv\(vUv\)/,'actual pattern coordinate consumes the compensated helper'); } assert.match(reeded,/coord=patternScreenUv\(vUv\)\.x\*count/); assert.match(frosted,/st=patternScreenUv\(vUv\)\*/); assert.match(frosted,/rad=vec2\(\.008\)\*uSceneZoom\*/,'frosted blur footprint magnifies with the view'); console.log('Scene zoom materials: shader helper arithmetic preserves zoom1 pattern coordinates and tracks zoomed material points; Frosted footprint source contract verified (no GPU execution)');