-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Add is_equal_approx
/is_zero_approx
for floats to shading language
#77239
Conversation
9d59426
to
cdebff2
Compare
@paddy-exe may be interested in this system, since it could allow adding helper functions to the text-based shader language similar to the ones we already have in VisualShader. |
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.
Tested locally (rebased on top of master
6758a7f), it works as expected.
Code looks good to me at a glance.
This likely depends on godotengine/godot-proposals#2808, unless we're OK with using methods that have different names instead (which is inconsistent with how GDScript does it). |
cdebff2
to
337a096
Compare
337a096
to
7478c51
Compare
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.
Code looks good to me 👍🏻
I think this can be pretty useful, although as Calinou noted type overloading (for float, vec2, vec3 and vec4) would be great to add at some point as many similar GLSL functions understand overloading and these will be kind of special cases that don't. I usually use custom epsilon comparison values tuned for each purpose, but I think rough comparisons can be useful in many cases. Another minor issue is this kind of "GDScriptification" of the shader language, as But generally, I don't mind adding this. Especially if we want to add function overlading at some point. Plus the system used for generating code only if used can be pretty useful for other things, too. |
Yeah, so either we assign a name from https://docs.godotengine.org/en/stable/tutorials/shaders/shaders_style_guide.html#naming-conventions (is_equal_approx) or make them like GLSL built-ins ( |
I personally like |
Hey 👋 I have commented under the original proposal, but I was wondering if we can put our brain together to try and make a bit of golfing and find code that can be inlined perhaps? Shouldn't it be better than using a function and binary operators? I proposed this for vectors |
This is likely significantly slower, as |
But the GPU has dedicated hardware for that i think ..? not sure :D |
No matter how fast the GPU is, more instructions still take more time to run than fewer instructions 🙂 |
Hah, I wouldn't bet on that because GPUs are freaky. At the same time, I don't have enough hard evidence to support that and I don't think it's enough of an issue to be worthy more discussion ^^ no more opposition from my side |
To add to Bitsawer's comment. I do feel weird about adding GDScript functionality into GDShaders, I think for two reasons:
That being said this particular change is rather simple and does not add much complexity. So I think it is worth evaluating on its own. In any case, I think it would be beneficial to discuss this at the next rendering meeting so we can start to put together a clear idea about the future of GDShaders in respect to adding GDScript functionality. |
We discussed this in the Rendering meeting on September 6. Those present in the meeting felt that adding this function into GDShaders is problematic as it mixed GLSL and GDScript paradigms, and doesn't actually solve the issue of users not understanding floating point precision. In the meeting we agreed that a better solution would be to detect usages of equal and not-equal operators with floats on either side and present the user with a clear warning in the editor |
Alright, then this should be closed. A warning is already been present for the users. |
Could we have a built-in |
I think writing < EPSILON or < 0.001 is free enough |
Adds the support for these two functions to Godot Shading Language. If the user does not use them - they will not be added to the code and thus will not be compiled by the internal system compiler (main @reduz claim about adding custom functions).
This should fix (partly, only for floats): godotengine/godot-proposals#6870