Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few fixes for VisualShaderNodeRotationByAxis #94497

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions editor/plugins/visual_shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6905,8 +6905,7 @@ VisualShaderEditor::VisualShaderEditor() {
add_options.push_back(AddOption("ProximityFade", "Utility", "VisualShaderNodeProximityFade", TTR("The proximity fade effect fades out each pixel based on its distance to another object."), {}, VisualShaderNode::PORT_TYPE_SCALAR, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
add_options.push_back(AddOption("RandomRange", "Utility", "VisualShaderNodeRandomRange", TTR("Returns a random value between the minimum and maximum input values."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
add_options.push_back(AddOption("Remap", "Utility", "VisualShaderNodeRemap", TTR("Remaps a given input from the input range to the output range."), {}, VisualShaderNode::PORT_TYPE_SCALAR));
add_options.push_back(AddOption("RotationByAxis", "Utility", "VisualShaderNodeRotationByAxis", TTR("Rotates an input vector by a given angle."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL));
add_options.push_back(AddOption("RotationByAxis", "Utility", "VisualShaderNodeRotationByAxis", TTR("Rotates an input vector by a given angle."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL));
add_options.push_back(AddOption("RotationByAxis", "Utility", "VisualShaderNodeRotationByAxis", TTR("Builds a rotation matrix from the given axis and angle, multiply the input vector by it and returns both this vector and a matrix."), {}, VisualShaderNode::PORT_TYPE_VECTOR_3D));

// VECTOR

Expand Down
14 changes: 11 additions & 3 deletions scene/resources/visual_shader_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8177,6 +8177,9 @@ String VisualShaderNodeRotationByAxis::get_output_port_name(int p_port) const {
}

bool VisualShaderNodeRotationByAxis::has_output_port_preview(int p_port) const {
if (p_port == 0) {
return true;
}
return false;
}

Expand All @@ -8190,15 +8193,20 @@ String VisualShaderNodeRotationByAxis::generate_code(Shader::Mode p_mode, Visual
code += vformat(" vec3( __axis.y*__axis.x*(1.0-cos(__angle))+__axis.z*sin(__angle), cos(__angle)+__axis.y*__axis.y*(1.0-cos(__angle)), __axis.y*__axis.z*(1.0-cos(__angle))-__axis.x*sin(__angle) ),\n");
code += vformat(" vec3( __axis.z*__axis.x*(1.0-cos(__angle))-__axis.y*sin(__angle), __axis.z*__axis.y*(1.0-cos(__angle))+__axis.x*sin(__angle), cos(__angle)+__axis.z*__axis.z*(1.0-cos(__angle)) )\n");
code += vformat(" );\n");
code += vformat(" %s = %s * __rot_matrix;\n", p_output_vars[0], p_input_vars[0]);
code += vformat(" %s = mat4(__rot_matrix);\n", p_output_vars[1]);
if (is_output_port_connected(0)) {
code += vformat(" %s = %s * __rot_matrix;\n", p_output_vars[0], p_input_vars[0]);
}
if (is_output_port_connected(1)) {
code += vformat(" %s = mat4(__rot_matrix);\n", p_output_vars[1]);
}
code += " }\n";
return code;
}

VisualShaderNodeRotationByAxis::VisualShaderNodeRotationByAxis() {
set_input_port_default_value(0, Vector3());
set_input_port_default_value(1, 0.0);
set_input_port_default_value(2, Vector3(0.0, 0.0, 0.0));
set_input_port_default_value(2, Vector3());

simple_decl = false;
}
Expand Down
Loading