You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
things that don't convince me are:
1)what's the reason of doing "pi/180.0" when we could save the operation by directly assigning the result 0.017453278 (i don't know how many numbers are allowed)? Is it for clarity? A comment would be more clear and wouldn't affect performance.
2)why not simply using the function "radians" to convert degrees to radians? Is it faster to make a simple multiply instead of calling the function? But if so the first division is still a waste.
3)not a issue but for some reason before doing this shader i thought "pi" was a default constant, i think it would be useful to have "pi" constant already defined instead of make us define it every time, that would save an assign and eventual value errors.
Particles are supposed to be many so in my opinion every little saving on their (converted)shader is useful.
Sorry if this is eventually dumb :/
Merry Christmas and happy new year! :D
The text was updated successfully, but these errors were encountered:
The compiler optimizes away constant expressions like this. In the compiled code there is no difference between pi / 180.0 and 0.017453278. It is preferable to use pi / 180.0 so that the user can understand where the value is coming from.
I don't think there is any reason not to use radians() here. The compiler would likely optimize it as well, so it would be no different than just multiplying by degree_to_rad. That being said, there is no compelling reason to use it either.
This seems like a good idea. Making it a global constant might actually make it a little faster for users if they use PI a lot. But again, there is not a really compelling reason to add it.
If you really want these changes I suggest making a PR yourself, it wouldn't take a lot to change them and it would be a great way to start contributing!
Thanks for the answer!
Sorry if i'm annoying but i'm curious so... It's obvious that i don't know exactly how shaders work, so it's probably a stupid question, but using radians() wouldn't avoid the allocation and assign of pi and degree_to_rad?
I first made a particlesmaterial and then converted it to a shader and i found some lines in the vertex function that left me perplexed:
...
float pi = 3.14159;
float degree_to_rad = pi / 180.0;
...
float spread_rad = spread * degree_to_rad;
...
CUSTOM.x = base_angle * degree_to_rad;
...
things that don't convince me are:
1)what's the reason of doing "pi/180.0" when we could save the operation by directly assigning the result 0.017453278 (i don't know how many numbers are allowed)? Is it for clarity? A comment would be more clear and wouldn't affect performance.
2)why not simply using the function "radians" to convert degrees to radians? Is it faster to make a simple multiply instead of calling the function? But if so the first division is still a waste.
3)not a issue but for some reason before doing this shader i thought "pi" was a default constant, i think it would be useful to have "pi" constant already defined instead of make us define it every time, that would save an assign and eventual value errors.
Particles are supposed to be many so in my opinion every little saving on their (converted)shader is useful.
Sorry if this is eventually dumb :/
Merry Christmas and happy new year! :D
The text was updated successfully, but these errors were encountered: