mirror of
https://github.com/godotengine/godot.git
synced 2024-11-28 23:22:38 +00:00
Merge pull request #50389 from Chaosus/vs_uniform_ref
Auto-set a first compatible uniform on dragging to create a UniformRef (VisualShaders)
This commit is contained in:
commit
30d4732623
@ -2274,6 +2274,8 @@ void VisualShaderEditor::_setup_node(VisualShaderNode *p_node, int p_op_idx) {
|
||||
void VisualShaderEditor::_add_node(int p_idx, int p_op_idx, String p_resource_path, int p_node_idx) {
|
||||
ERR_FAIL_INDEX(p_idx, add_options.size());
|
||||
|
||||
VisualShader::Type type = get_current_shader_type();
|
||||
|
||||
Ref<VisualShaderNode> vsnode;
|
||||
|
||||
bool is_custom = add_options[p_idx].is_custom;
|
||||
@ -2300,6 +2302,29 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx, String p_resource_pa
|
||||
}
|
||||
}
|
||||
|
||||
VisualShaderNodeUniformRef *uniform_ref = Object::cast_to<VisualShaderNodeUniformRef>(vsn);
|
||||
|
||||
if (uniform_ref && to_node != -1 && to_slot != -1) {
|
||||
VisualShaderNode::PortType input_port_type = visual_shader->get_node(type, to_node)->get_input_port_type(to_slot);
|
||||
bool success = false;
|
||||
|
||||
for (int i = 0; i < uniform_ref->get_uniforms_count(); i++) {
|
||||
if (uniform_ref->get_port_type_by_index(i) == input_port_type) {
|
||||
uniform_ref->set_uniform_name(uniform_ref->get_uniform_name_by_index(i));
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
for (int i = 0; i < uniform_ref->get_uniforms_count(); i++) {
|
||||
if (visual_shader->is_port_types_compatible(uniform_ref->get_port_type_by_index(i), input_port_type)) {
|
||||
uniform_ref->set_uniform_name(uniform_ref->get_uniform_name_by_index(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vsnode = Ref<VisualShaderNode>(vsn);
|
||||
} else {
|
||||
ERR_FAIL_COND(add_options[p_idx].script.is_null());
|
||||
@ -2320,8 +2345,6 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx, String p_resource_pa
|
||||
}
|
||||
saved_node_pos_dirty = false;
|
||||
|
||||
VisualShader::Type type = get_current_shader_type();
|
||||
|
||||
int id_to_use = visual_shader->get_valid_node_id(type);
|
||||
|
||||
if (p_resource_path.is_empty()) {
|
||||
|
@ -2708,6 +2708,28 @@ VisualShaderNodeUniformRef::UniformType VisualShaderNodeUniformRef::get_uniform_
|
||||
return UniformType::UNIFORM_TYPE_FLOAT;
|
||||
}
|
||||
|
||||
VisualShaderNodeUniformRef::PortType VisualShaderNodeUniformRef::get_port_type_by_index(int p_idx) const {
|
||||
if (p_idx >= 0 && p_idx < uniforms.size()) {
|
||||
switch (uniforms[p_idx].type) {
|
||||
case UniformType::UNIFORM_TYPE_FLOAT:
|
||||
return PORT_TYPE_SCALAR;
|
||||
case UniformType::UNIFORM_TYPE_INT:
|
||||
return PORT_TYPE_SCALAR_INT;
|
||||
case UniformType::UNIFORM_TYPE_SAMPLER:
|
||||
return PORT_TYPE_SAMPLER;
|
||||
case UniformType::UNIFORM_TYPE_VECTOR:
|
||||
return PORT_TYPE_VECTOR;
|
||||
case UniformType::UNIFORM_TYPE_TRANSFORM:
|
||||
return PORT_TYPE_TRANSFORM;
|
||||
case UniformType::UNIFORM_TYPE_COLOR:
|
||||
return PORT_TYPE_VECTOR;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return PORT_TYPE_SCALAR;
|
||||
}
|
||||
|
||||
String VisualShaderNodeUniformRef::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
|
||||
switch (uniform_type) {
|
||||
case UniformType::UNIFORM_TYPE_FLOAT:
|
||||
|
@ -517,6 +517,7 @@ public:
|
||||
String get_uniform_name_by_index(int p_idx) const;
|
||||
UniformType get_uniform_type_by_name(const String &p_name) const;
|
||||
UniformType get_uniform_type_by_index(int p_idx) const;
|
||||
PortType get_port_type_by_index(int p_idx) const;
|
||||
|
||||
virtual Vector<StringName> get_editable_properties() const override;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user