godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Add methods to check for high shader precision support from scripting #1747

Open ATryder opened 3 years ago

ATryder commented 3 years ago

Describe the project you are working on: Cross-platform sci-fi turn based strategy

Describe the problem or limitation you are having in your project: I have an options menu that will allow a player to select from low, medium, high and extra-high shader quality for some of the effects in my game for performance reasons. On mobile platforms the three highest quality shader options require high precision floating point operations. When running on devices that don't support high precision floats these shaders can look pretty terrible.

Describe the feature / enhancement and how it helps to overcome the problem or limitation: I'd like to be able to check if the device supports GLSL high precision floats from GDScript when the option menu is displayed. If not supported I would hide the material quality option and just load the lowest quality shaders.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

if !gl_precision(PRECISION_FLOAT_HIGH):
    #hide options here

If this enhancement will not be used often, can it be worked around with a few lines of script?: I don't think so

Is there a reason why this should be core and not an add-on in the asset library?: Doesn't seem like the type of thing one would write an add-on for.

clayjohn commented 3 years ago

Looks like GL ES 2.0 and 3.0 support this through https://www.khronos.org/registry/OpenGL-Refpages/es3/

While openGL 2.1 and 3.3 don't https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGetShaderPrecisionFormat.xhtml

That being said, I think PCs always use high precision, so could be safe to always return high precision on desktop platforms and then query on mobile (and maybe web?)