Skip to content

Commit

Permalink
Merge pull request godotengine#47616 from Chaosus/vs_prevent_texture_…
Browse files Browse the repository at this point in the history
…uniform_convert

Prevents TextureUniform in visual shaders from conversion to constant
  • Loading branch information
Chaosus authored Apr 4, 2021
2 parents cbf5408 + 44af52d commit 541bd55
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion editor/plugins/visual_shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2627,7 +2627,7 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
selected_constants.insert(id);
}
VisualShaderNodeUniform *uniform_node = Object::cast_to<VisualShaderNodeUniform>(node.ptr());
if (uniform_node != nullptr) {
if (uniform_node != nullptr && uniform_node->is_convertible_to_constant()) {
selected_uniforms.insert(id);
}
}
Expand Down
1 change: 1 addition & 0 deletions scene/resources/visual_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ class VisualShaderNodeUniform : public VisualShaderNode {
bool is_global_code_generated() const;

virtual bool is_qualifier_supported(Qualifier p_qual) const = 0;
virtual bool is_convertible_to_constant() const = 0;

virtual Vector<StringName> get_editable_properties() const override;
virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const override;
Expand Down
28 changes: 28 additions & 0 deletions scene/resources/visual_shader_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3744,6 +3744,10 @@ bool VisualShaderNodeFloatUniform::is_qualifier_supported(Qualifier p_qual) cons
return true; // all qualifiers are supported
}

bool VisualShaderNodeFloatUniform::is_convertible_to_constant() const {
return true; // conversion is allowed
}

Vector<StringName> VisualShaderNodeFloatUniform::get_editable_properties() const {
Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
props.push_back("hint");
Expand Down Expand Up @@ -3911,6 +3915,10 @@ bool VisualShaderNodeIntUniform::is_qualifier_supported(Qualifier p_qual) const
return true; // all qualifiers are supported
}

bool VisualShaderNodeIntUniform::is_convertible_to_constant() const {
return true; // conversion is allowed
}

Vector<StringName> VisualShaderNodeIntUniform::get_editable_properties() const {
Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
props.push_back("hint");
Expand Down Expand Up @@ -4019,6 +4027,10 @@ bool VisualShaderNodeBooleanUniform::is_qualifier_supported(Qualifier p_qual) co
return true; // all qualifiers are supported
}

bool VisualShaderNodeBooleanUniform::is_convertible_to_constant() const {
return true; // conversion is allowed
}

Vector<StringName> VisualShaderNodeBooleanUniform::get_editable_properties() const {
Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
props.push_back("default_value_enabled");
Expand Down Expand Up @@ -4113,6 +4125,10 @@ bool VisualShaderNodeColorUniform::is_qualifier_supported(Qualifier p_qual) cons
return true; // all qualifiers are supported
}

bool VisualShaderNodeColorUniform::is_convertible_to_constant() const {
return true; // conversion is allowed
}

Vector<StringName> VisualShaderNodeColorUniform::get_editable_properties() const {
Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
props.push_back("default_value_enabled");
Expand Down Expand Up @@ -4209,6 +4225,10 @@ bool VisualShaderNodeVec3Uniform::is_qualifier_supported(Qualifier p_qual) const
return true; // all qualifiers are supported
}

bool VisualShaderNodeVec3Uniform::is_convertible_to_constant() const {
return true; // conversion is allowed
}

Vector<StringName> VisualShaderNodeVec3Uniform::get_editable_properties() const {
Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
props.push_back("default_value_enabled");
Expand Down Expand Up @@ -4309,6 +4329,10 @@ bool VisualShaderNodeTransformUniform::is_qualifier_supported(Qualifier p_qual)
return true; // all qualifiers are supported
}

bool VisualShaderNodeTransformUniform::is_convertible_to_constant() const {
return true; // conversion is allowed
}

Vector<StringName> VisualShaderNodeTransformUniform::get_editable_properties() const {
Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
props.push_back("default_value_enabled");
Expand Down Expand Up @@ -4494,6 +4518,10 @@ bool VisualShaderNodeTextureUniform::is_qualifier_supported(Qualifier p_qual) co
return false;
}

bool VisualShaderNodeTextureUniform::is_convertible_to_constant() const {
return false; // conversion is not allowed
}

VisualShaderNodeTextureUniform::VisualShaderNodeTextureUniform() {
simple_decl = false;
}
Expand Down
7 changes: 7 additions & 0 deletions scene/resources/visual_shader_nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,7 @@ class VisualShaderNodeFloatUniform : public VisualShaderNodeUniform {
float get_default_value() const;

bool is_qualifier_supported(Qualifier p_qual) const override;
bool is_convertible_to_constant() const override;

virtual Vector<StringName> get_editable_properties() const override;

Expand Down Expand Up @@ -1639,6 +1640,7 @@ class VisualShaderNodeIntUniform : public VisualShaderNodeUniform {
int get_default_value() const;

bool is_qualifier_supported(Qualifier p_qual) const override;
bool is_convertible_to_constant() const override;

virtual Vector<StringName> get_editable_properties() const override;

Expand Down Expand Up @@ -1683,6 +1685,7 @@ class VisualShaderNodeBooleanUniform : public VisualShaderNodeUniform {
bool get_default_value() const;

bool is_qualifier_supported(Qualifier p_qual) const override;
bool is_convertible_to_constant() const override;

virtual Vector<StringName> get_editable_properties() const override;

Expand Down Expand Up @@ -1724,6 +1727,7 @@ class VisualShaderNodeColorUniform : public VisualShaderNodeUniform {
Color get_default_value() const;

bool is_qualifier_supported(Qualifier p_qual) const override;
bool is_convertible_to_constant() const override;

virtual Vector<StringName> get_editable_properties() const override;

Expand Down Expand Up @@ -1766,6 +1770,7 @@ class VisualShaderNodeVec3Uniform : public VisualShaderNodeUniform {
Vector3 get_default_value() const;

bool is_qualifier_supported(Qualifier p_qual) const override;
bool is_convertible_to_constant() const override;

virtual Vector<StringName> get_editable_properties() const override;

Expand Down Expand Up @@ -1808,6 +1813,7 @@ class VisualShaderNodeTransformUniform : public VisualShaderNodeUniform {
Transform get_default_value() const;

bool is_qualifier_supported(Qualifier p_qual) const override;
bool is_convertible_to_constant() const override;

virtual Vector<StringName> get_editable_properties() const override;

Expand Down Expand Up @@ -1865,6 +1871,7 @@ class VisualShaderNodeTextureUniform : public VisualShaderNodeUniform {
ColorDefault get_color_default() const;

bool is_qualifier_supported(Qualifier p_qual) const override;
bool is_convertible_to_constant() const override;

VisualShaderNodeTextureUniform();
};
Expand Down

0 comments on commit 541bd55

Please sign in to comment.