-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[p5.strands] Bridging p5.strands and p5.js functions #7849
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
Comments
|
Hi! 👋 I'm interested in contributing to this issue, especially the Could you please point me to the correct file or folder in the repo? Thanks in advance! |
Thanks @LalitNarayanYadav! Currently, p5.js/src/webgl/ShaderGenerator.js Lines 1564 to 1567 in 2606c21
Later on in the file, it loops through the things in this list, creating a new p5.strands function out of them. The array of args options specify the different overloads the function has, and Currently, the part later on that generates the functions assumes the name in the list ( p5.js/src/webgl/ShaderGenerator.js Lines 1598 to 1620 in 2606c21
I could see us solving this maybe by manually creating a similar function to the snippet above, but outside of the loop, that sets |
Thanks so much, @davepagurek , that makes it a lot clearer! Just to confirm my understanding: since the function creation loop uses the same name for both the JS function and GLSL mapping, you're suggesting that I manually define Also, would it be okay to add a short comment there explaining the purpose of the alias for clarity? Happy to take this up if it sounds good! |
It'll be a bit more complicated because setting |
That would be great, thanks! |
Thanks for the clarification, @davepagurek! So to implement the
I’ll also add a clear comment explaining the aliasing purpose as you suggested. Please let me know if this plan sounds good, and I’ll start working on it! |
That sounds great, thanks! |
Uh oh!
There was an error while loading. Please reload this page.
Increasing access
By aiming to make the learning curve for p5.strands (therefore shaders) as easy as possible when coming from p5.js. As much as possible, p5.js functions should work in p5.strands, unless there is good reason for them not to.
Most appropriate sub-area of p5.js?
Feature enhancement details
Currently, some p5.js functions will not work properly in p5.strands. This issue aims to improve compatiblity, reduce confusion, and make it easier to mix standard p5.js code in with p5.strands shaders.
Background
p5.strands ports a large number of GLSL's built in functions. For example:
sin
,cos
, etcabs
andmix
In some cases, these are duplicates of p5.js functions. The p5.strands compiler temporarily overrides duplicates, so they can be used with p5.strands objects.
p5.strands operates a bit differently than the rest of the library. In a way, it emulates namespacing by overriding p5.js functions, but it does so implicitly. The compiler lets use use JavaScript values like Numbers and Arrays, but internally they are converted to objects representing nodes in a kind of Abstract Syntax tree (e.g.
FunctionCallNode
,VectorNode
, etc). So when we try to use p5.js functions, they can fail if we pass these nodes as objects. At the same time, p5.strands currently disables the Friendly Error System, which further obfuscates the problem.(Note: the disabling of FES is a separate Issue which I will post soon and update the link to soon)
Apart from documentation and other learning materials, some work is needed to improve the interoperability of p5.js and p5.strands functions. The aim is to keep the node based abstraction hidden, and provide more analogues for p5.js functions. This should make p5.strands more integrated with the rest of the library, making it more accessible.
p5.js Math functions
p5.js' math functions, such as
map
, don't always work as expected in p5.js. Take the following code for example:This currently throws a generic JS 'NaN' error, as
map
expects a number but receives aFunctionCallNode
object. This should be allowed behaviour, and p5.js functions should as much as possible be usable within p5.strands to reduce the mental load of remembering what can and can't be done.There may be cases apart from the Math functions, but that's the most obvious example. This part of the issue requires some discussion about what should be ported to p5.strands, and how it could be implemented.
Mix / lerp
There is a special case for
mix
, which is GLSL's version oflerp
in p5.js. There has been some discussion about creating an analogue forlerp
in p5.strands, so that either of the following would be possible:In this case, it's a small amount of code to fix, and could be done separately.
The text was updated successfully, but these errors were encountered: