diff --git a/src/shaders/editor_functions.glsl b/src/shaders/editor_functions.glsl index 563ad5d2..48fe84f1 100644 --- a/src/shaders/editor_functions.glsl +++ b/src/shaders/editor_functions.glsl @@ -12,7 +12,8 @@ R"( //INSERT: EDITOR_COMPATIBILITY_DEFINES -// Compatibility overrides +// COMPATIBILITY_DEFINES +// This is added automatically when in compatibility mode. It is not required for Mobile or Forward+ #define fma(a, b, c) (a) * (b) + (c) #define dFdxCoarse(a) dFdx(a) #define dFdyCoarse(a) dFdy(a) diff --git a/src/terrain_3d_material.cpp b/src/terrain_3d_material.cpp index a86f6635..2963f4d8 100644 --- a/src/terrain_3d_material.cpp +++ b/src/terrain_3d_material.cpp @@ -155,7 +155,7 @@ String Terrain3DMaterial::_inject_editor_code(const String &p_shader) const { // Insert at the very begining idx = 0; insert_names.clear(); - if (_compatibility) { + if (_compatibility && !shader.contains("COMPATIBILITY_DEFINES")) { insert_names.push_back("EDITOR_COMPATIBILITY_DEFINES"); } for (int i = 0; i < insert_names.size(); i++) { @@ -253,6 +253,10 @@ void Terrain3DMaterial::_update_shader() { if (_shader_override->get_code().is_empty()) { _shader_override->set_code(_generate_shader_code()); } + // + if (_compatibility && !_shader_override->get_code().contains("COMPATIBILITY_DEFINES")) { + _shader_override->set_code(_shader_override->get_code().insert(0, _shader_code["EDITOR_COMPATIBILITY_DEFINES"])); + } code = _shader_override->get_code(); if (!_shader_override->is_connected("changed", callable_mp(this, &Terrain3DMaterial::_update_shader))) { LOG(DEBUG, "Connecting changed signal to _update_shader()");