-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[p5.strands] should instanceID() be auto-converted to a float? #7856
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 @davepagurek, thanks for bringing this up. It’s a great discussion. I haven’t used p5.strands, but It says ;
Since array indexing requires an integer, dynamic lookups must be done with an int. Integer IDs remain useful for indexing arrays or performing lookups, If we auto-converted Also, with very large draw calls, a I don't know these two points still an issue here but if it matters, without chainging If these are not the concern users gonna use, we can convert |
While those are true, I think it might be worth compromising on those more advanced features for the sake of ease of use. Another thought: for array indexing, we could make our |
also cc @lukeplowden in case you have thoughts! |
Aah, yes. That's sounds great. I agree that prioritizing ease of use over more complex features is sensible. This approach makes a lot of sense and we could do that after making |
Firstly, this is actually a bug coming from here: This is the error
It infers On the actual topic of this issue, this does raise some other issues:
I do basically agree that everything could be converted to float, and I like the mental model of "there are separate operators for int and float". For the most part, we do always use floats at least in vertex and fragment shaders. I think though, for compute (which may be added in the future) there are generally more integer operations. At least for now, I think it's better to presume that all binary operations using |
Does it go through Initially I was thinking the fix might be in here: p5.js/src/webgl/ShaderGenerator.js Lines 1385 to 1387 in 2606c21
Possibly returning something like |
That would also fix it, but let userType = getType(userArg);
...
if (expectedArgType === 'genType') {
if (userType === 'int') userType = 'float';
... Then it does properly cast the type to float, and handle the error. It does leave the weirdness from the table above, where different syntaxes for the same operation currently give different results. It will just render unexpectedly, instead of not compiling as GLSL or throwing the type error about function signatures.
There are a few different options as you've highlighted, about whether to just assume all scalars are floats (which can already be cast to vecs easily). That way we can cast back to int if needed. Otherwise, I suppose the compiler would have to be a bit smarter about knowing what type something should be based on what it's used in... maybe nodes could be duplicated if used in different contexts? This is probably unnecessary though... Your change would definitely work for |
got it, thanks for the explanation! That works too. I'm going to mark this one as "help wanted" in case any contributors want to try tackling this based on this discussion. |
Topic
I was working on this sketch https://openprocessing.org/sketch/2664809 and
instanceID() / 10
gives a type error, but0.1 * instanceID()
does not. For consistency and to reduce the number of times a programmer has to manually convert between numeric types, do you think we should just auto-convertinstanceID()
to a float behind the scenes?The text was updated successfully, but these errors were encountered: