Skip to content

Commit

Permalink
shader override handling workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtarsia committed Sep 27, 2024
1 parent ac4b2e2 commit 61290f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/shaders/editor_functions.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions src/terrain_3d_material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ String Terrain3DMaterial::_inject_editor_code(const String &p_shader) const {
idx = 0;
insert_names.clear();
if (_compatibility) {
insert_names.push_back("EDITOR_COMPATIBILITY_DEFINES");
if (!shader.contains("COMPATIBILITY_DEFINES")) {
insert_names.push_back("EDITOR_COMPATIBILITY_DEFINES");
}
}
for (int i = 0; i < insert_names.size(); i++) {
String insert = _shader_code[insert_names[i]];
Expand Down Expand Up @@ -251,7 +253,16 @@ void Terrain3DMaterial::_update_shader() {
String code;
if (_shader_override_enabled && _shader_override.is_valid()) {
if (_shader_override->get_code().is_empty()) {
_shader_override->set_code(_generate_shader_code());
if (_compatibility) {
_shader_override->set_code(_generate_shader_code().insert(0, _shader_code["EDITOR_COMPATIBILITY_DEFINES"]));
} else {
_shader_override->set_code(_generate_shader_code());
}
}
if (_compatibility) {
if (!_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))) {
Expand Down

0 comments on commit 61290f1

Please sign in to comment.