summaryrefslogtreecommitdiffstats
path: root/scene/resources/shader.cpp
diff options
context:
space:
mode:
authorYuri Sizov <yuris@humnom.net>2023-07-14 18:49:44 +0200
committerYuri Sizov <yuris@humnom.net>2023-07-14 18:49:44 +0200
commitead69eba96e51e377029c5a942aac0ecaa53ce1a (patch)
treef966547be2f5b37388153714e0170c3a3d5affc1 /scene/resources/shader.cpp
parentde14f09c1d903c808a50aab7b04574ca44e6016d (diff)
parent905c10bc5415c6659412d6b3e429660e7c8ca2ba (diff)
downloadredot-engine-ead69eba96e51e377029c5a942aac0ecaa53ce1a.tar.gz
Merge pull request #79287 from bitsawer/fix_shader_type_detection
Fix shader type detection
Diffstat (limited to 'scene/resources/shader.cpp')
-rw-r--r--scene/resources/shader.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp
index 62c2483a93..361a28194f 100644
--- a/scene/resources/shader.cpp
+++ b/scene/resources/shader.cpp
@@ -66,20 +66,6 @@ void Shader::set_code(const String &p_code) {
E->disconnect(SNAME("changed"), callable_mp(this, &Shader::_dependency_changed));
}
- String type = ShaderLanguage::get_shader_type(p_code);
-
- if (type == "canvas_item") {
- mode = MODE_CANVAS_ITEM;
- } else if (type == "particles") {
- mode = MODE_PARTICLES;
- } else if (type == "sky") {
- mode = MODE_SKY;
- } else if (type == "fog") {
- mode = MODE_FOG;
- } else {
- mode = MODE_SPATIAL;
- }
-
code = p_code;
String pp_code = p_code;
@@ -100,6 +86,21 @@ void Shader::set_code(const String &p_code) {
}
}
+ // Try to get the shader type from the final, fully preprocessed shader code.
+ String type = ShaderLanguage::get_shader_type(pp_code);
+
+ if (type == "canvas_item") {
+ mode = MODE_CANVAS_ITEM;
+ } else if (type == "particles") {
+ mode = MODE_PARTICLES;
+ } else if (type == "sky") {
+ mode = MODE_SKY;
+ } else if (type == "fog") {
+ mode = MODE_FOG;
+ } else {
+ mode = MODE_SPATIAL;
+ }
+
for (const Ref<ShaderInclude> &E : include_dependencies) {
E->connect(SNAME("changed"), callable_mp(this, &Shader::_dependency_changed));
}