Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/strands/strands_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 40 additions & 0 deletions test/unit/visual/cases/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"numScreenshots": 1
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"numScreenshots": 1
}
Loading