-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add shortcut methods for modifying base shaders and documentation #8020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev-2.0
Are you sure you want to change the base?
Conversation
- Introduced modifyMaterialShader, modifyFilterShader, modifyNormalShader, modifyColorShader, and modifyStrokeShader functions - Added documentation file 'modifymethod shortcut.md' explaining usage and benefits
Thanks for working on this! Are you still interested in continuing? I think to get this mergeable, I'd like to:
|
failureCallback | ||
) { | ||
// p5._validateParameters('loadShader', arguments); | ||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this file got pretty restructured, was that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushing the new code to avoid the circular dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still if the code breaks or anything comes up, please let know
I am trying
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now a lot of this file has changed slightly, e.g. method names inside other examples are renamed. I think for this to be mergeable we'll need to keep everything else in place. Do you think we can start from your previous code, and just add examples in without modifying the rest? Not sure if you're using AI to make changes or not, but modifying other pieces slightly is something it does sometimes.
The ones I was thinking of adding are, e.g. for createMaterialShader
, the examples from here:
Line 1432 in bfe2867
* @example |
* declarations: 'uniform float time;', | ||
* 'vec3 getWorldPosition': `(vec3 pos) { | ||
* pos.y += 20. * sin(time * 0.001 + pos.x * 0.05); | ||
* return pos; | ||
* }` | ||
* }); | ||
* myShader.inspectHooks(); | ||
* | ||
* // Inside the callback, you can use: | ||
* // - modifyFragment() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't methods that exist, let's take this bit out
* // - modifyVertex() | ||
* // - addUniform() | ||
* // - etc. | ||
* // These functions are shorthand for calling `.modify()` on the corresponding base shader. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this sentence (with slight modification -- "this function" instead of "these functions" when referring to a specific create*
function) can be brought out of the example inside the docs, and just into the main text of the docs.
Hi both, really exciting to see this!
On some reflection, I am gently leaning toward Initially I would have voted for However, these shortcuts do seem better described by |
modifyMaterialShader
,modifyFilterShader
,modifyNormalShader
,modifyColorShader
, andmodifyStrokeShader
functionsmodifymethod shortcut.md
explaining usage and benefitsResolves #7993
Shader Modification Shortcuts
Overview
This PR introduces shortcut methods for modifying base shaders in p5.js. These methods reduce boilerplate and make it easier for users to customize shaders by combining base shader creation and modification into a single function call.
Added File
src/webgl/modifyShaderShortcuts.js
Contains the following exported functions:
modifyMaterialShader(modifier)
modifyFilterShader(modifier)
modifyNormalShader(modifier)
modifyColorShader(modifier)
modifyStrokeShader(modifier)
attachModifyShaderShortcuts(p5Instance)
Usage
Direct Usage
Equivalent to:
Attaching to p5 Prototype
To make these shortcuts available in all sketches, call:
Then you can use:
Benefits
.modify()
.Example
How to Test
PR Checklist
npm run lint
passes