godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Add preprocessor to paths #10275

Open BastiaanOlij opened 3 months ago

BastiaanOlij commented 3 months ago

Describe the project you are working on

VR application exported to both stand alone headsets (Android, Mobile renderer) and desktop (PC, Forward+ renderer)

Describe the problem or limitation you are having in your project

I want to set up shaders and materials differently depending on the renderer or platform I'm exporting too without needing code that changes them when the wrong versions have already been compiled on scene loading.

Especially with the new custom shader templates this will become even more of a problem if you wish to target multiple platforms/renderers.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The solution I'm thinking off is adding a preprocessor to paths. We already parse res:// and user:// etc. We could easily extend this logic to parse additional markers.

For instance we could have a path like res://%rendering_method%/textured.gdshader that would be parsed to res://forward_clustered/textured.gdshader.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

We create a static registry where different parts of Godot can register keywords. For instance for the above example to work we would do:

void SceneShaderForwardClustered::init(const String p_defines) {
    DirAccess::register_path_keyword('rendering_method`, `forward_clustered`)

or potentially this code could be in Main::setup and react to a number of keywords we set there (rendering_method, platform, etc.)

In our DirAccess and FileAccess classes we add a parse function for the path that we call at the start of functions like FileAccess::open.

If this enhancement will not be used often, can it be worked around with a few lines of script?

This requires core changes

Is there a reason why this should be core and not an add-on in the asset library?

This requires core changes

Calinou commented 3 months ago

I would prefer reusing the remap system as it doesn't see much use currently.

BastiaanOlij commented 3 months ago

I would prefer reusing the remap system as it doesn't see much use currently.

Yes I would agree, when I wrote this I wasn't aware we had that system but it seems much better suited.