Skip to content

Commit

Permalink
Merge pull request #94497 from Chaosus/vs_rotation_by_axis
Browse files Browse the repository at this point in the history
Few fixes for `VisualShaderNodeRotationByAxis`
  • Loading branch information
akien-mga committed Jul 18, 2024
2 parents fefd953 + cf70cb5 commit 72e434b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
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

0 comments on commit 72e434b

Please sign in to comment.