🎥 Make videos programmatically with React
`@remotion/effects`: Preserve pixels outside fisheye radius
Jonny Burger60690a1c9965
diff --git a/packages/effects/src/fisheye/fisheye-shaders.ts b/packages/effects/src/fisheye/fisheye-shaders.tsindex 2b2fb3fdc9..64658c5903 100644--- a/packages/effects/src/fisheye/fisheye-shaders.ts+++ b/packages/effects/src/fisheye/fisheye-shaders.ts@@ -28,7 +28,7 @@ void main() {float r = dist / max(uRadius, 0.0001);if (r > 1.0 || uFieldOfView <= 0.0001) {- fragColor = vec4(0.0);+ fragColor = texture(uSource, vUv);return;}diff --git a/packages/effects/src/visual-test/effects-visual.test.ts b/packages/effects/src/visual-test/effects-visual.test.tsindex 8ddf5bb008..62efdab099 100644--- a/packages/effects/src/visual-test/effects-visual.test.ts+++ b/packages/effects/src/visual-test/effects-visual.test.ts@@ -4,6 +4,7 @@ import {colorCorrection} from '../color-correction.js';import {contrast} from '../contrast.js';import {evolve} from '../evolve.js';import {exposure} from '../exposure.js';+import {fisheye} from '../fisheye.js';import {levels} from '../levels.js';import {noise} from '../noise.js';import {outline} from '../outline.js';@@ -37,6 +38,56 @@ test('stacks repeated WebGL effects without blanking or flipping the image', asy});});+test('fisheye() preserves pixels outside the lens radius and at zero field of view', async () => {+ const width = 64;+ const height = 64;+ const source = document.createElement('canvas');+ source.width = width;+ source.height = height;+ const sourceContext = source.getContext('2d');+ if (!sourceContext) {+ throw new Error('Could not get source context');+ }++ sourceContext.fillStyle = 'rgb(12, 34, 56)';+ sourceContext.fillRect(0, 0, width, height);++ const canvas = await renderEffectChainToCanvas({+ source,+ width,+ height,+ effects: descriptorsToMemoizedEffects([+ fisheye({fieldOfView: 1, radius: 0.25}),+ ]),+ });+ const context = canvas.getContext('2d');+ if (!context) {+ throw new Error('Could not get output context');+ }++ const pixelOutsideLens = context.getImageData(2, 2, 1, 1).data;+ expect([...pixelOutsideLens]).toEqual([12, 34, 56, 255]);++ const zeroFieldOfViewCanvas = await renderEffectChainToCanvas({+ source,+ width,+ height,+ effects: descriptorsToMemoizedEffects([fisheye({fieldOfView: 0})]),+ });+ const zeroFieldOfViewContext = zeroFieldOfViewCanvas.getContext('2d');+ if (!zeroFieldOfViewContext) {+ throw new Error('Could not get zero field of view output context');+ }++ const zeroFieldOfViewPixel = zeroFieldOfViewContext.getImageData(+ 32,+ 32,+ 1,+ 1,+ ).data;+ expect([...zeroFieldOfViewPixel]).toEqual([12, 34, 56, 255]);+});+test('outline() draws around alpha while preserving the source', async () => {const width = 64;const height = 64;