Skip to content

Commit 24a08dc

Browse files
authored
Merge pull request #8681 from aashu2006/fix/strands-lerp
Fix: restore lerp alias to GLSL mix in p5.strands
2 parents a513b28 + 9b8a527 commit 24a08dc

File tree

6 files changed

+56
-0
lines changed

6 files changed

+56
-0
lines changed

src/strands/strands_api.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,16 @@ export function initGlobalStrandsAPI(p5, fn, strandsContext) {
284284
}
285285
}
286286

287+
// Alias lerp to GLSL mix in strands context
288+
const originalLerp = fn.lerp;
289+
augmentFn(fn, p5, 'lerp', function (...args) {
290+
if (strandsContext.active) {
291+
return fn.mix(...args);
292+
} else {
293+
return originalLerp.apply(this, args);
294+
}
295+
});
296+
287297
augmentFn(fn, p5, 'getTexture', function (...rawArgs) {
288298
if (strandsContext.active) {
289299
const { id, dimension } = strandsContext.backend.createGetTextureCall(strandsContext, rawArgs);

test/unit/visual/cases/webgl.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,46 @@ visualSuite('WebGL', function() {
10671067
screenshot();
10681068
});
10691069

1070+
visualTest('lerp maps to mix in strands context', (p5, screenshot) => {
1071+
p5.createCanvas(50, 50, p5.WEBGL);
1072+
// lerp should behave identically to mix inside strands
1073+
const shader = p5.baseColorShader().modify(() => {
1074+
p5.getFinalColor((color) => {
1075+
color = p5.lerp(
1076+
[1, 0, 0, 1],
1077+
[0, 0, 1, 1],
1078+
0.5
1079+
);
1080+
return color;
1081+
});
1082+
}, { p5 });
1083+
p5.background(0);
1084+
p5.shader(shader);
1085+
p5.noStroke();
1086+
p5.plane(50, 50);
1087+
screenshot();
1088+
});
1089+
1090+
visualTest('mix produces same result as lerp in strands', (p5, screenshot) => {
1091+
p5.createCanvas(50, 50, p5.WEBGL);
1092+
// mix directly, should produce identical output to lerp test above
1093+
const shader = p5.baseColorShader().modify(() => {
1094+
p5.getFinalColor((color) => {
1095+
color = p5.mix(
1096+
[1, 0, 0, 1],
1097+
[0, 0, 1, 1],
1098+
0.5
1099+
);
1100+
return color;
1101+
});
1102+
}, { p5 });
1103+
p5.background(0);
1104+
p5.shader(shader);
1105+
p5.noStroke();
1106+
p5.plane(50, 50);
1107+
screenshot();
1108+
});
1109+
10701110
visualSuite('auto-return for shader hooks', () => {
10711111
visualTest('auto-returns input struct when return is omitted', (p5, screenshot) => {
10721112
p5.createCanvas(50, 50, p5.WEBGL);
236 Bytes
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
236 Bytes
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}

0 commit comments

Comments
 (0)