Skip to content

Alias GLSL's mix function as lerp in p5.strands (#7875) #7887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 16, 2025
13 changes: 13 additions & 0 deletions src/webgl/ShaderGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ancestor } from 'acorn-walk';
import escodegen from 'escodegen';

function shadergenerator(p5, fn) {

let GLOBAL_SHADER;
let BRANCH;

Expand Down Expand Up @@ -1618,7 +1619,19 @@ function shadergenerator(p5, fn) {
}
}
})
// Alias GLSL's mix function as lerp in p5.strands
// Bridging p5.js lerp and GLSL mix for consistency in shader expressions
const originalLerp = fn.lerp;
fn.lerp = function (...args) {
if (GLOBAL_SHADER?.isGenerating) {
return this.mix(...args); // Use mix inside p5.strands
} else {
return originalLerp.apply(this, args); // Fallback to normal p5.js lerp
}
};
}



export default shadergenerator;

Expand Down