Skip to content

Commit 3c180eb

Browse files
committed
Merge branch 'auto-return-shader-hooks' into flat-strands
2 parents 5979305 + 82e9997 commit 3c180eb

14 files changed

Lines changed: 124 additions & 1 deletion

File tree

src/strands/strands_api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ export function createShaderHooksFunctions(strandsContext, fn, shader) {
437437
for (const hookType of hookTypes) {
438438
const hook = function(hookUserCallback) {
439439
const args = setupHook();
440-
hook._result = hookUserCallback(...args);
440+
hook._result = hookUserCallback(...args) ?? hook._result;
441441
finishHook();
442442
}
443443

test/unit/visual/cases/webgl.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,111 @@ visualSuite('WebGL', function() {
10211021
p5.circle(p5.noise(0), p5.noise(0), 20);
10221022
screenshot();
10231023
});
1024+
1025+
visualSuite('auto-return for shader hooks', () => {
1026+
visualTest('auto-returns input struct when return is omitted', (p5, screenshot) => {
1027+
p5.createCanvas(50, 50, p5.WEBGL);
1028+
const shader = p5.baseMaterialShader().modify(() => {
1029+
p5.getWorldInputs((inputs) => {
1030+
inputs.position.x += 10;
1031+
// No explicit return - should auto-return inputs
1032+
});
1033+
}, { p5 });
1034+
p5.background(255);
1035+
p5.noStroke();
1036+
p5.shader(shader);
1037+
p5.sphere(20);
1038+
screenshot();
1039+
});
1040+
1041+
visualTest('explicit return still works', (p5, screenshot) => {
1042+
p5.createCanvas(50, 50, p5.WEBGL);
1043+
const shader = p5.baseMaterialShader().modify(() => {
1044+
p5.getWorldInputs((inputs) => {
1045+
inputs.position.x += 10;
1046+
return inputs; // Explicit return should still work
1047+
});
1048+
}, { p5 });
1049+
p5.background(255);
1050+
p5.noStroke();
1051+
p5.shader(shader);
1052+
p5.sphere(20);
1053+
screenshot();
1054+
});
1055+
1056+
visualTest('auto-return works with getObjectInputs', (p5, screenshot) => {
1057+
p5.createCanvas(50, 50, p5.WEBGL);
1058+
const shader = p5.baseMaterialShader().modify(() => {
1059+
p5.getObjectInputs((inputs) => {
1060+
inputs.position.x += 0.25;
1061+
// No explicit return
1062+
});
1063+
}, { p5 });
1064+
p5.background(255);
1065+
p5.lights();
1066+
p5.fill('red');
1067+
p5.noStroke();
1068+
p5.rotateY(p5.PI / 2);
1069+
p5.camera(-800, 0, 0, 0, 0, 0);
1070+
p5.shader(shader);
1071+
p5.sphere(20);
1072+
screenshot();
1073+
});
1074+
1075+
visualTest('auto-return works with getCameraInputs', (p5, screenshot) => {
1076+
p5.createCanvas(50, 50, p5.WEBGL);
1077+
const shader = p5.baseMaterialShader().modify(() => {
1078+
p5.getCameraInputs((inputs) => {
1079+
inputs.position.x += 10;
1080+
// No explicit return
1081+
});
1082+
}, { p5 });
1083+
p5.background(255);
1084+
p5.lights();
1085+
p5.fill('red');
1086+
p5.noStroke();
1087+
p5.rotateY(p5.PI / 2);
1088+
p5.camera(-800, 0, 0, 0, 0, 0);
1089+
p5.shader(shader);
1090+
p5.sphere(20);
1091+
screenshot();
1092+
});
1093+
1094+
visualTest('auto-return preserves multiple property modifications', (p5, screenshot) => {
1095+
p5.createCanvas(50, 50, p5.WEBGL);
1096+
const shader = p5.baseMaterialShader().modify(() => {
1097+
p5.getWorldInputs((inputs) => {
1098+
inputs.position.x += 5;
1099+
inputs.position.y += 5;
1100+
inputs.normal.x += 0.5;
1101+
inputs.normal = p5.normalize(inputs.normal);
1102+
// No explicit return - all modifications should be preserved
1103+
});
1104+
}, { p5 });
1105+
p5.background(255);
1106+
p5.lights();
1107+
p5.fill('red');
1108+
p5.noStroke();
1109+
p5.shader(shader);
1110+
p5.sphere(20);
1111+
screenshot();
1112+
});
1113+
1114+
visualTest('auto-return works with getPixelInputs', (p5, screenshot) => {
1115+
p5.createCanvas(50, 50, p5.WEBGL);
1116+
const shader = p5.baseMaterialShader().modify(() => {
1117+
p5.getPixelInputs((inputs) => {
1118+
inputs.color = p5.vec4(1.0, 0.0, 0.0, 1.0); // Red
1119+
// No explicit return
1120+
});
1121+
}, { p5 });
1122+
p5.background(255);
1123+
p5.noStroke();
1124+
p5.shader(shader);
1125+
p5.circle(0, 0, 40);
1126+
screenshot();
1127+
});
1128+
});
10241129
});
10251130

10261131
visualSuite('background()', function () {
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
760 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
946 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
619 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}

0 commit comments

Comments
 (0)