From f1c2596d44c1713213b8e615d5fca63f32586f79 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 12 May 2026 09:30:06 -0400 Subject: [PATCH] Make sure all p5.strands math operators are converted to strands nodes --- src/strands/strands_transpiler.js | 23 ++++++++++------------- test/unit/webgl/p5.Shader.js | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/strands/strands_transpiler.js b/src/strands/strands_transpiler.js index bf33907338..59fe718467 100644 --- a/src/strands/strands_transpiler.js +++ b/src/strands/strands_transpiler.js @@ -323,17 +323,14 @@ function transformBinaryOrLogical(node, state, ancestors) { if (ancestors.some(a => nodeIsUniform(a) || nodeIsUniformCallbackFn(a, state.uniformCallbackNames))) { return; } - const unsafeTypes = ['Literal', 'ArrayExpression', 'Identifier']; - if (unsafeTypes.includes(node.left.type)) { - node.left = { - type: 'CallExpression', - callee: { - type: 'Identifier', - name: '__p5.strandsNode', - }, - arguments: [node.left] - }; - } + node.left = { + type: 'CallExpression', + callee: { + type: 'Identifier', + name: '__p5.strandsNode', + }, + arguments: [node.left] + }; node.type = 'CallExpression'; node.callee = { type: 'MemberExpression', @@ -1240,8 +1237,8 @@ const ASTCallbacks = { delete node.update; }, - - + + } // Helper function to check if a function body contains return statements in control flow diff --git a/test/unit/webgl/p5.Shader.js b/test/unit/webgl/p5.Shader.js index 7f42d589da..fd719c73ac 100644 --- a/test/unit/webgl/p5.Shader.js +++ b/test/unit/webgl/p5.Shader.js @@ -459,6 +459,21 @@ suite('p5.Shader', function() { }).not.toThrowError(); }); + test('buildFilterShader can use numeric constants from scope', () => { + myp5.createCanvas(5, 5, myp5.WEBGL); + const constants = { val: 100 }; + const myShader = myp5.buildFilterShader(({ constants }) => { + filterColor.begin(); + let c = 0; + c += constants.val / 255; + filterColor.set([c, c, c, 1]); + filterColor.end(); + }, { constants }); + expect(() => { + myp5.filter(myShader); + }).not.toThrowError(); + }); + test('buildMaterialShader forwards scope to modify', () => { myp5.createCanvas(5, 5, myp5.WEBGL); expect(() => {