Description
Describe the project you are working on
A top-down 3D game with custom shaders
Describe the problem or limitation you are having in your project
A fog-of-war shader I have requires a different vertex operation when running in Godot’s editor (a line needs to be commented out). Currently, I manually comment out the line whenever I want to visualize the shader in Godot’s editor and then uncomment it whenever I want to observe the changes in the running code. This process becomes tedious quite quickly.
While I can avoid the issue by defining a shader uniform and checking it at runtime, this would add an unnecessary runtime overhead which can be completely avoided if the shading language had a built-in macro that's defined whenever the shader is running inside Godot's editor.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Please add a built-in shader preprocessor macro named IS_IN_EDITOR
. This macro should be defined whenever Engine.is_editor_hint()
would return true if called, and it should not be defined otherwise.
Notes:
- Another good name might be
IS_EDITOR_HINT
if matching the equivalent GDScript function's name is desired. - To see how to define built-in shader macros, search for other, existing built-in macros in Godot's source code:
CURRENT_RENDERER
,RENDERER_COMPATIBILITY
,RENDERER_MOBILE
, andRENDERER_FORWARD_PLUS
.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
void vertex( )
{
#ifndef IS_IN_EDITOR
POSITION = vec4(VERTEX, 1.0);
#endif
}
If this enhancement will not be used often, can it be worked around with a few lines of script?
A similar result can be achieved by introducing a shader uniform to every shader that needs to access this macro, and set it from GDScript/GDExtrension code. However, doing so would introduce a runtime overhead to every vertex/fragment/light calculation that needs to check for this condition.
Is there a reason why this should be core and not an add-on in the asset library?
Cannot be implemented as an add-on.