Skip to content

Commit 6b8e46b

Browse files
Add visual tests for auto-return shader hooks
1 parent 0571ced commit 6b8e46b

13 files changed

Lines changed: 123 additions & 0 deletions

File tree

test/unit/visual/cases/webgl.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,5 +807,110 @@ visualSuite('WebGL', function() {
807807
p5.circle(p5.noise(0), p5.noise(0), 20);
808808
screenshot();
809809
});
810+
811+
visualSuite('auto-return for shader hooks', () => {
812+
visualTest('auto-returns input struct when return is omitted', (p5, screenshot) => {
813+
p5.createCanvas(50, 50, p5.WEBGL);
814+
const shader = p5.baseMaterialShader().modify(() => {
815+
p5.getWorldInputs((inputs) => {
816+
inputs.position.x += 10;
817+
// No explicit return - should auto-return inputs
818+
});
819+
}, { p5 });
820+
p5.background(255);
821+
p5.noStroke();
822+
p5.shader(shader);
823+
p5.sphere(20);
824+
screenshot();
825+
});
826+
827+
visualTest('explicit return still works', (p5, screenshot) => {
828+
p5.createCanvas(50, 50, p5.WEBGL);
829+
const shader = p5.baseMaterialShader().modify(() => {
830+
p5.getWorldInputs((inputs) => {
831+
inputs.position.x += 10;
832+
return inputs; // Explicit return should still work
833+
});
834+
}, { p5 });
835+
p5.background(255);
836+
p5.noStroke();
837+
p5.shader(shader);
838+
p5.sphere(20);
839+
screenshot();
840+
});
841+
842+
visualTest('auto-return works with getObjectInputs', (p5, screenshot) => {
843+
p5.createCanvas(50, 50, p5.WEBGL);
844+
const shader = p5.baseMaterialShader().modify(() => {
845+
p5.getObjectInputs((inputs) => {
846+
inputs.position.x += 0.25;
847+
// No explicit return
848+
});
849+
}, { p5 });
850+
p5.background(255);
851+
p5.lights();
852+
p5.fill('red');
853+
p5.noStroke();
854+
p5.rotateY(p5.PI / 2);
855+
p5.camera(-800, 0, 0, 0, 0, 0);
856+
p5.shader(shader);
857+
p5.sphere(20);
858+
screenshot();
859+
});
860+
861+
visualTest('auto-return works with getCameraInputs', (p5, screenshot) => {
862+
p5.createCanvas(50, 50, p5.WEBGL);
863+
const shader = p5.baseMaterialShader().modify(() => {
864+
p5.getCameraInputs((inputs) => {
865+
inputs.position.x += 10;
866+
// No explicit return
867+
});
868+
}, { p5 });
869+
p5.background(255);
870+
p5.lights();
871+
p5.fill('red');
872+
p5.noStroke();
873+
p5.rotateY(p5.PI / 2);
874+
p5.camera(-800, 0, 0, 0, 0, 0);
875+
p5.shader(shader);
876+
p5.sphere(20);
877+
screenshot();
878+
});
879+
880+
visualTest('auto-return preserves multiple property modifications', (p5, screenshot) => {
881+
p5.createCanvas(50, 50, p5.WEBGL);
882+
const shader = p5.baseMaterialShader().modify(() => {
883+
p5.getWorldInputs((inputs) => {
884+
inputs.position.x += 5;
885+
inputs.position.y += 5;
886+
inputs.normal.x += 0.5;
887+
inputs.normal = p5.normalize(inputs.normal);
888+
// No explicit return - all modifications should be preserved
889+
});
890+
}, { p5 });
891+
p5.background(255);
892+
p5.lights();
893+
p5.fill('red');
894+
p5.noStroke();
895+
p5.shader(shader);
896+
p5.sphere(20);
897+
screenshot();
898+
});
899+
900+
visualTest('auto-return works with getPixelInputs', (p5, screenshot) => {
901+
p5.createCanvas(50, 50, p5.WEBGL);
902+
const shader = p5.baseMaterialShader().modify(() => {
903+
p5.getPixelInputs((inputs) => {
904+
inputs.color = p5.vec4(1.0, 0.0, 0.0, 1.0); // Red
905+
// No explicit return
906+
});
907+
}, { p5 });
908+
p5.background(255);
909+
p5.noStroke();
910+
p5.shader(shader);
911+
p5.circle(0, 0, 40);
912+
screenshot();
913+
});
914+
});
810915
});
811916
});
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+
}
232 Bytes
Loading

0 commit comments

Comments
 (0)