Skip to content

Auto return shader hooks#8384

Merged
davepagurek merged 3 commits intoprocessing:dev-2.0from
vietnguyen2358:auto-return-shader-hooks
Jan 22, 2026
Merged

Auto return shader hooks#8384
davepagurek merged 3 commits intoprocessing:dev-2.0from
vietnguyen2358:auto-return-shader-hooks

Conversation

@vietnguyen2358
Copy link

Resolves #7994
Addresses #7992

Changes:

  • Added auto-return behavior for shader hooks with matching input and return types, allows users to omit return inputs when modifying struct properties in place
  • Implemented type checking to ensure auto-return only applies to struct-returning hooks with a single parameter of matching type

PR Checklist

@welcome
Copy link

welcome bot commented Jan 5, 2026

🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors!
🤔 Please ensure that your PR links to an issue, which has been approved for work by a maintainer; otherwise, there might already be someone working on it, or still ongoing discussion about implementation. You are welcome to join the discussion in an Issue if you're not sure!
🌸 Once your PR is merged, be sure to add yourself to the list of contributors on the readme page !

Thank You!

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks for making these changes and also adding tests!

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh actually it looks like the tests are failing:

 FAIL |unit-tests|  test/unit/visual/cases/webgl.js > WebGL > p5.strands > auto-return for shader hooks > auto-return works with getObjectInputs > matches expected screenshots
TypeError: Cannot read properties of undefined (reading 'position')
 ❯ p5.hookImplementation src/strands/strands_api.js:446:50
    444|             const expectedProp = expectedProperties[i];
    445|             const propName = expectedProp.name;
    446|             const receivedValue = effectiveReturn[propName];
       |                                                  ^
    447|             if (receivedValue === undefined) {
    448|               FES.userError('type error', `You've returned an incomple…
 ❯ eval src/strands/strands_transpiler.js:1078:39
 ❯ src/strands/strands_transpiler.js:1087:20
 ❯ p5.Shader.modify src/strands/p5.strands.js:114:9
 ❯ test/unit/visual/cases/webgl.js:965:48
 ❯ test/unit/visual/visualTest.js:432:13

Possibly the isStructType check is failing? Maybe try adding some logging and then run npm run test test/unit/visual/cases/webgl.js to see what the types are?

@vietnguyen2358
Copy link
Author

Sure, I will look into it.

@davepagurek
Copy link
Contributor

Hi @vietnguyen2358! We're working on some updates to the p5.strands API for the next release in #8314 and we don't want to put any time pressure on you related to that, so I'm going to integrate your PR into that branch and fix the tests there, since other parts of the code are moving around too. Thanks for your help on this so far, I'm excited to have this functionality in the next version 🙂

@davepagurek
Copy link
Contributor

@all-contributors please add @vietnguyen2358 for code

@allcontributors
Copy link
Contributor

@davepagurek

I've put up a pull request to add @vietnguyen2358! 🎉

@davepagurek davepagurek merged commit 3c180eb into processing:dev-2.0 Jan 22, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants