diff --git a/components/canvas/PostFX.tsx b/components/canvas/PostFX.tsx index 16fd796..46ff390 100644 --- a/components/canvas/PostFX.tsx +++ b/components/canvas/PostFX.tsx @@ -130,10 +130,16 @@ export function PostFX() { const dprRef = useRef(1); useEffect(() => { + const t = Math.min(gl.getPixelRatio(), 2); + // Assign dpr BEFORE the composer guard: this effect only re-runs on a + // size change, and if the composer wasn't mounted on the first run the + // dpr would stay 1 forever — pointerDevRef (= uv·size·dprRef) then + // lands at HALF the real position (buffer is size·2) until the user + // resizes the window. Symptom: fluid trail offset from the pointer + // right after load, snapping into place after any resize. + dprRef.current = t; const composer = composerRef.current; if (!composer) return; - const t = Math.min(gl.getPixelRatio(), 2); - dprRef.current = t; const r = Math.max(1, Math.floor(size.width * t)); const n = Math.max(1, Math.floor(size.height * t)); composer.inputBuffer.setSize(r, n); @@ -161,6 +167,10 @@ export function PostFX() { if (!composer) return; const dprNow = Math.min(gl.getPixelRatio(), 2); + // Keep dprRef live every frame (see the resize-effect comment): the + // pointer device coords = uv · size · dprRef must always match the real + // drawing-buffer ratio, independent of effect scheduling. + dprRef.current = dprNow; const metricsKey = `${size.width}x${size.height}x${dprNow}`; if (lastMetricsKeyRef.current !== metricsKey) { lastMetricsKeyRef.current = metricsKey;