diff --git a/src/strands/strands_api.js b/src/strands/strands_api.js index f08aa3bc15..d145cf7298 100644 --- a/src/strands/strands_api.js +++ b/src/strands/strands_api.js @@ -284,6 +284,16 @@ export function initGlobalStrandsAPI(p5, fn, strandsContext) { } } + // Alias lerp to GLSL mix in strands context + const originalLerp = fn.lerp; + augmentFn(fn, p5, 'lerp', function (...args) { + if (strandsContext.active) { + return fn.mix(...args); + } else { + return originalLerp.apply(this, args); + } + }); + augmentFn(fn, p5, 'getTexture', function (...rawArgs) { if (strandsContext.active) { const { id, dimension } = strandsContext.backend.createGetTextureCall(strandsContext, rawArgs); diff --git a/test/unit/visual/cases/webgl.js b/test/unit/visual/cases/webgl.js index 1893e40252..b83b9748b7 100644 --- a/test/unit/visual/cases/webgl.js +++ b/test/unit/visual/cases/webgl.js @@ -1067,6 +1067,46 @@ visualSuite('WebGL', function() { screenshot(); }); + visualTest('lerp maps to mix in strands context', (p5, screenshot) => { + p5.createCanvas(50, 50, p5.WEBGL); + // lerp should behave identically to mix inside strands + const shader = p5.baseColorShader().modify(() => { + p5.getFinalColor((color) => { + color = p5.lerp( + [1, 0, 0, 1], + [0, 0, 1, 1], + 0.5 + ); + return color; + }); + }, { p5 }); + p5.background(0); + p5.shader(shader); + p5.noStroke(); + p5.plane(50, 50); + screenshot(); + }); + + visualTest('mix produces same result as lerp in strands', (p5, screenshot) => { + p5.createCanvas(50, 50, p5.WEBGL); + // mix directly, should produce identical output to lerp test above + const shader = p5.baseColorShader().modify(() => { + p5.getFinalColor((color) => { + color = p5.mix( + [1, 0, 0, 1], + [0, 0, 1, 1], + 0.5 + ); + return color; + }); + }, { p5 }); + p5.background(0); + p5.shader(shader); + p5.noStroke(); + p5.plane(50, 50); + screenshot(); + }); + visualSuite('auto-return for shader hooks', () => { visualTest('auto-returns input struct when return is omitted', (p5, screenshot) => { p5.createCanvas(50, 50, p5.WEBGL); diff --git a/test/unit/visual/screenshots/WebGL/p5.strands/lerp maps to mix in strands context/000.png b/test/unit/visual/screenshots/WebGL/p5.strands/lerp maps to mix in strands context/000.png new file mode 100644 index 0000000000..223241d6cd Binary files /dev/null and b/test/unit/visual/screenshots/WebGL/p5.strands/lerp maps to mix in strands context/000.png differ diff --git a/test/unit/visual/screenshots/WebGL/p5.strands/lerp maps to mix in strands context/metadata.json b/test/unit/visual/screenshots/WebGL/p5.strands/lerp maps to mix in strands context/metadata.json new file mode 100644 index 0000000000..2d4bfe30da --- /dev/null +++ b/test/unit/visual/screenshots/WebGL/p5.strands/lerp maps to mix in strands context/metadata.json @@ -0,0 +1,3 @@ +{ + "numScreenshots": 1 +} \ No newline at end of file diff --git a/test/unit/visual/screenshots/WebGL/p5.strands/mix produces same result as lerp in strands/000.png b/test/unit/visual/screenshots/WebGL/p5.strands/mix produces same result as lerp in strands/000.png new file mode 100644 index 0000000000..223241d6cd Binary files /dev/null and b/test/unit/visual/screenshots/WebGL/p5.strands/mix produces same result as lerp in strands/000.png differ diff --git a/test/unit/visual/screenshots/WebGL/p5.strands/mix produces same result as lerp in strands/metadata.json b/test/unit/visual/screenshots/WebGL/p5.strands/mix produces same result as lerp in strands/metadata.json new file mode 100644 index 0000000000..2d4bfe30da --- /dev/null +++ b/test/unit/visual/screenshots/WebGL/p5.strands/mix produces same result as lerp in strands/metadata.json @@ -0,0 +1,3 @@ +{ + "numScreenshots": 1 +} \ No newline at end of file