diff options
author | Yuri Rubinsky <chaosus89@gmail.com> | 2022-12-27 20:49:11 +0300 |
---|---|---|
committer | Yuri Rubinsky <chaosus89@gmail.com> | 2023-01-06 10:35:25 +0300 |
commit | f101add78beb152b4c5ecd735534e9d462bbadaa (patch) | |
tree | 358f7abefc01c5769f8e59c75cc8fe1fb71ce92f | |
parent | b14f7aa9f92ff44135c283a9c88dab5ef9136d64 (diff) |
Add `uint` type support to visual shaders
-rw-r--r-- | doc/classes/VisualShader.xml | 14 | ||||
-rw-r--r-- | doc/classes/VisualShaderNode.xml | 17 | ||||
-rw-r--r-- | doc/classes/VisualShaderNodeClamp.xml | 11 | ||||
-rw-r--r-- | doc/classes/VisualShaderNodeCompare.xml | 15 | ||||
-rw-r--r-- | doc/classes/VisualShaderNodeSwitch.xml | 15 | ||||
-rw-r--r-- | doc/classes/VisualShaderNodeUIntConstant.xml | 16 | ||||
-rw-r--r-- | doc/classes/VisualShaderNodeUIntFunc.xml | 27 | ||||
-rw-r--r-- | doc/classes/VisualShaderNodeUIntOp.xml | 57 | ||||
-rw-r--r-- | doc/classes/VisualShaderNodeUIntParameter.xml | 15 | ||||
-rw-r--r-- | editor/plugins/visual_shader_editor_plugin.cpp | 84 | ||||
-rw-r--r-- | scene/register_scene_types.cpp | 4 | ||||
-rw-r--r-- | scene/resources/visual_shader.cpp | 115 | ||||
-rw-r--r-- | scene/resources/visual_shader.h | 3 | ||||
-rw-r--r-- | scene/resources/visual_shader_nodes.cpp | 389 | ||||
-rw-r--r-- | scene/resources/visual_shader_nodes.h | 166 |
15 files changed, 898 insertions, 50 deletions
diff --git a/doc/classes/VisualShader.xml b/doc/classes/VisualShader.xml index a2089ae2b8..2d59810a5f 100644 --- a/doc/classes/VisualShader.xml +++ b/doc/classes/VisualShader.xml @@ -208,17 +208,19 @@ </constant> <constant name="VARYING_TYPE_INT" value="1" enum="VaryingType"> </constant> - <constant name="VARYING_TYPE_VECTOR_2D" value="2" enum="VaryingType"> + <constant name="VARYING_TYPE_UINT" value="2" enum="VaryingType"> </constant> - <constant name="VARYING_TYPE_VECTOR_3D" value="3" enum="VaryingType"> + <constant name="VARYING_TYPE_VECTOR_2D" value="3" enum="VaryingType"> </constant> - <constant name="VARYING_TYPE_VECTOR_4D" value="4" enum="VaryingType"> + <constant name="VARYING_TYPE_VECTOR_3D" value="4" enum="VaryingType"> </constant> - <constant name="VARYING_TYPE_BOOLEAN" value="5" enum="VaryingType"> + <constant name="VARYING_TYPE_VECTOR_4D" value="5" enum="VaryingType"> </constant> - <constant name="VARYING_TYPE_TRANSFORM" value="6" enum="VaryingType"> + <constant name="VARYING_TYPE_BOOLEAN" value="6" enum="VaryingType"> </constant> - <constant name="VARYING_TYPE_MAX" value="7" enum="VaryingType"> + <constant name="VARYING_TYPE_TRANSFORM" value="7" enum="VaryingType"> + </constant> + <constant name="VARYING_TYPE_MAX" value="8" enum="VaryingType"> </constant> <constant name="NODE_ID_INVALID" value="-1"> </constant> diff --git a/doc/classes/VisualShaderNode.xml b/doc/classes/VisualShaderNode.xml index 1f3397f39c..f95f871e52 100644 --- a/doc/classes/VisualShaderNode.xml +++ b/doc/classes/VisualShaderNode.xml @@ -72,25 +72,28 @@ <constant name="PORT_TYPE_SCALAR_INT" value="1" enum="PortType"> Integer scalar. Translated to [code]int[/code] type in shader code. </constant> - <constant name="PORT_TYPE_VECTOR_2D" value="2" enum="PortType"> + <constant name="PORT_TYPE_SCALAR_UINT" value="2" enum="PortType"> + Unsigned integer scalar. Translated to [code]uint[/code] type in shader code. + </constant> + <constant name="PORT_TYPE_VECTOR_2D" value="3" enum="PortType"> 2D vector of floating-point values. Translated to [code]vec2[/code] type in shader code. </constant> - <constant name="PORT_TYPE_VECTOR_3D" value="3" enum="PortType"> + <constant name="PORT_TYPE_VECTOR_3D" value="4" enum="PortType"> 3D vector of floating-point values. Translated to [code]vec3[/code] type in shader code. </constant> - <constant name="PORT_TYPE_VECTOR_4D" value="4" enum="PortType"> + <constant name="PORT_TYPE_VECTOR_4D" value="5" enum="PortType"> 4D vector of floating-point values. Translated to [code]vec4[/code] type in shader code. </constant> - <constant name="PORT_TYPE_BOOLEAN" value="5" enum="PortType"> + <constant name="PORT_TYPE_BOOLEAN" value="6" enum="PortType"> Boolean type. Translated to [code]bool[/code] type in shader code. </constant> - <constant name="PORT_TYPE_TRANSFORM" value="6" enum="PortType"> + <constant name="PORT_TYPE_TRANSFORM" value="7" enum="PortType"> Transform type. Translated to [code]mat4[/code] type in shader code. </constant> - <constant name="PORT_TYPE_SAMPLER" value="7" enum="PortType"> + <constant name="PORT_TYPE_SAMPLER" value="8" enum="PortType"> Sampler type. Translated to reference of sampler uniform in shader code. Can only be used for input ports in non-uniform nodes. </constant> - <constant name="PORT_TYPE_MAX" value="8" enum="PortType"> + <constant name="PORT_TYPE_MAX" value="9" enum="PortType"> Represents the size of the [enum PortType] enum. </constant> </constants> diff --git a/doc/classes/VisualShaderNodeClamp.xml b/doc/classes/VisualShaderNodeClamp.xml index 35f50a37c3..642a98ec8c 100644 --- a/doc/classes/VisualShaderNodeClamp.xml +++ b/doc/classes/VisualShaderNodeClamp.xml @@ -20,16 +20,19 @@ <constant name="OP_TYPE_INT" value="1" enum="OpType"> An integer scalar. </constant> - <constant name="OP_TYPE_VECTOR_2D" value="2" enum="OpType"> + <constant name="OP_TYPE_UINT" value="2" enum="OpType"> + An unsigned integer scalar. + </constant> + <constant name="OP_TYPE_VECTOR_2D" value="3" enum="OpType"> A 2D vector type. </constant> - <constant name="OP_TYPE_VECTOR_3D" value="3" enum="OpType"> + <constant name="OP_TYPE_VECTOR_3D" value="4" enum="OpType"> A 3D vector type. </constant> - <constant name="OP_TYPE_VECTOR_4D" value="4" enum="OpType"> + <constant name="OP_TYPE_VECTOR_4D" value="5" enum="OpType"> A 4D vector type. </constant> - <constant name="OP_TYPE_MAX" value="5" enum="OpType"> + <constant name="OP_TYPE_MAX" value="6" enum="OpType"> Represents the size of the [enum OpType] enum. </constant> </constants> diff --git a/doc/classes/VisualShaderNodeCompare.xml b/doc/classes/VisualShaderNodeCompare.xml index 942ced2ebd..19ed42d1c7 100644 --- a/doc/classes/VisualShaderNodeCompare.xml +++ b/doc/classes/VisualShaderNodeCompare.xml @@ -26,22 +26,25 @@ <constant name="CTYPE_SCALAR_INT" value="1" enum="ComparisonType"> An integer scalar. </constant> - <constant name="CTYPE_VECTOR_2D" value="2" enum="ComparisonType"> + <constant name="CTYPE_SCALAR_UINT" value="2" enum="ComparisonType"> + An unsigned integer scalar. + </constant> + <constant name="CTYPE_VECTOR_2D" value="3" enum="ComparisonType"> A 2D vector type. </constant> - <constant name="CTYPE_VECTOR_3D" value="3" enum="ComparisonType"> + <constant name="CTYPE_VECTOR_3D" value="4" enum="ComparisonType"> A 3D vector type. </constant> - <constant name="CTYPE_VECTOR_4D" value="4" enum="ComparisonType"> + <constant name="CTYPE_VECTOR_4D" value="5" enum="ComparisonType"> A 4D vector type. </constant> - <constant name="CTYPE_BOOLEAN" value="5" enum="ComparisonType"> + <constant name="CTYPE_BOOLEAN" value="6" enum="ComparisonType"> A boolean type. </constant> - <constant name="CTYPE_TRANSFORM" value="6" enum="ComparisonType"> + <constant name="CTYPE_TRANSFORM" value="7" enum="ComparisonType"> A transform ([code]mat4[/code]) type. </constant> - <constant name="CTYPE_MAX" value="7" enum="ComparisonType"> + <constant name="CTYPE_MAX" value="8" enum="ComparisonType"> Represents the size of the [enum ComparisonType] enum. </constant> <constant name="FUNC_EQUAL" value="0" enum="Function"> diff --git a/doc/classes/VisualShaderNodeSwitch.xml b/doc/classes/VisualShaderNodeSwitch.xml index e74ff6e162..3fda4eb2b8 100644 --- a/doc/classes/VisualShaderNodeSwitch.xml +++ b/doc/classes/VisualShaderNodeSwitch.xml @@ -20,22 +20,25 @@ <constant name="OP_TYPE_INT" value="1" enum="OpType"> An integer scalar. </constant> - <constant name="OP_TYPE_VECTOR_2D" value="2" enum="OpType"> + <constant name="OP_TYPE_UINT" value="2" enum="OpType"> + An unsigned integer scalar. + </constant> + <constant name="OP_TYPE_VECTOR_2D" value="3" enum="OpType"> A 2D vector type. </constant> - <constant name="OP_TYPE_VECTOR_3D" value="3" enum="OpType"> + <constant name="OP_TYPE_VECTOR_3D" value="4" enum="OpType"> A 3D vector type. </constant> - <constant name="OP_TYPE_VECTOR_4D" value="4" enum="OpType"> + <constant name="OP_TYPE_VECTOR_4D" value="5" enum="OpType"> A 4D vector type. </constant> - <constant name="OP_TYPE_BOOLEAN" value="5" enum="OpType"> + <constant name="OP_TYPE_BOOLEAN" value="6" enum="OpType"> A boolean type. </constant> - <constant name="OP_TYPE_TRANSFORM" value="6" enum="OpType"> + <constant name="OP_TYPE_TRANSFORM" value="7" enum="OpType"> A transform type. </constant> - <constant name="OP_TYPE_MAX" value="7" enum="OpType"> + <constant name="OP_TYPE_MAX" value="8" enum="OpType"> Represents the size of the [enum OpType] enum. </constant> </constants> diff --git a/doc/classes/VisualShaderNodeUIntConstant.xml b/doc/classes/VisualShaderNodeUIntConstant.xml new file mode 100644 index 0000000000..926e4e11d2 --- /dev/null +++ b/doc/classes/VisualShaderNodeUIntConstant.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualShaderNodeUIntConstant" inherits="VisualShaderNodeConstant" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> + <brief_description> + An unsigned scalar integer constant to be used within the visual shader graph. + </brief_description> + <description> + Translated to [code]uint[/code] in the shader language. + </description> + <tutorials> + </tutorials> + <members> + <member name="constant" type="int" setter="set_constant" getter="get_constant" default="0"> + An unsigned integer constant which represents a state of this node. + </member> + </members> +</class> diff --git a/doc/classes/VisualShaderNodeUIntFunc.xml b/doc/classes/VisualShaderNodeUIntFunc.xml new file mode 100644 index 0000000000..c0c591304a --- /dev/null +++ b/doc/classes/VisualShaderNodeUIntFunc.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualShaderNodeUIntFunc" inherits="VisualShaderNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> + <brief_description> + An unsigned scalar integer function to be used within the visual shader graph. + </brief_description> + <description> + Accept an unsigned integer scalar ([code]x[/code]) to the input port and transform it according to [member function]. + </description> + <tutorials> + </tutorials> + <members> + <member name="function" type="int" setter="set_function" getter="get_function" enum="VisualShaderNodeUIntFunc.Function" default="0"> + A function to be applied to the scalar. See [enum Function] for options. + </member> + </members> + <constants> + <constant name="FUNC_NEGATE" value="0" enum="Function"> + Negates the [code]x[/code] using [code]-(x)[/code]. + </constant> + <constant name="FUNC_BITWISE_NOT" value="1" enum="Function"> + Returns the result of bitwise [code]NOT[/code] operation on the integer. Translates to [code]~a[/code] in the Godot Shader Language. + </constant> + <constant name="FUNC_MAX" value="2" enum="Function"> + Represents the size of the [enum Function] enum. + </constant> + </constants> +</class> diff --git a/doc/classes/VisualShaderNodeUIntOp.xml b/doc/classes/VisualShaderNodeUIntOp.xml new file mode 100644 index 0000000000..44f71286e3 --- /dev/null +++ b/doc/classes/VisualShaderNodeUIntOp.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualShaderNodeUIntOp" inherits="VisualShaderNode" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> + <brief_description> + An unsigned integer scalar operator to be used within the visual shader graph. + </brief_description> + <description> + Applies [member operator] to two unsigned integer inputs: [code]a[/code] and [code]b[/code]. + </description> + <tutorials> + </tutorials> + <members> + <member name="operator" type="int" setter="set_operator" getter="get_operator" enum="VisualShaderNodeUIntOp.Operator" default="0"> + An operator to be applied to the inputs. See [enum Operator] for options. + </member> + </members> + <constants> + <constant name="OP_ADD" value="0" enum="Operator"> + Sums two numbers using [code]a + b[/code]. + </constant> + <constant name="OP_SUB" value="1" enum="Operator"> + Subtracts two numbers using [code]a - b[/code]. + </constant> + <constant name="OP_MUL" value="2" enum="Operator"> + Multiplies two numbers using [code]a * b[/code]. + </constant> + <constant name="OP_DIV" value="3" enum="Operator"> + Divides two numbers using [code]a / b[/code]. + </constant> + <constant name="OP_MOD" value="4" enum="Operator"> + Calculates the remainder of two numbers using [code]a % b[/code]. + </constant> + <constant name="OP_MAX" value="5" enum="Operator"> + Returns the greater of two numbers. Translates to [code]max(a, b)[/code] in the Godot Shader Language. + </constant> + <constant name="OP_MIN" value="6" enum="Operator"> + Returns the lesser of two numbers. Translates to [code]max(a, b)[/code] in the Godot Shader Language. + </constant> + <constant name="OP_BITWISE_AND" value="7" enum="Operator"> + Returns the result of bitwise [code]AND[/code] operation on the integer. Translates to [code]a & b[/code] in the Godot Shader Language. + </constant> + <constant name="OP_BITWISE_OR" value="8" enum="Operator"> + Returns the result of bitwise [code]OR[/code] operation for two integers. Translates to [code]a | b[/code] in the Godot Shader Language. + </constant> + <constant name="OP_BITWISE_XOR" value="9" enum="Operator"> + Returns the result of bitwise [code]XOR[/code] operation for two integers. Translates to [code]a ^ b[/code] in the Godot Shader Language. + </constant> + <constant name="OP_BITWISE_LEFT_SHIFT" value="10" enum="Operator"> + Returns the result of bitwise left shift operation on the integer. Translates to [code]a << b[/code] in the Godot Shader Language. + </constant> + <constant name="OP_BITWISE_RIGHT_SHIFT" value="11" enum="Operator"> + Returns the result of bitwise right shift operation on the integer. Translates to [code]a >> b[/code] in the Godot Shader Language. + </constant> + <constant name="OP_ENUM_SIZE" value="12" enum="Operator"> + Represents the size of the [enum Operator] enum. + </constant> + </constants> +</class> diff --git a/doc/classes/VisualShaderNodeUIntParameter.xml b/doc/classes/VisualShaderNodeUIntParameter.xml new file mode 100644 index 0000000000..3b549c84f7 --- /dev/null +++ b/doc/classes/VisualShaderNodeUIntParameter.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualShaderNodeUIntParameter" inherits="VisualShaderNodeParameter" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <members> + <member name="default_value" type="int" setter="set_default_value" getter="get_default_value" default="0"> + </member> + <member name="default_value_enabled" type="bool" setter="set_default_value_enabled" getter="is_default_value_enabled" default="false"> + </member> + </members> +</class> diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 3e70d4ce11..8c92dc406a 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -375,6 +375,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { static const Color type_color[] = { Color(0.38, 0.85, 0.96), // scalar (float) Color(0.49, 0.78, 0.94), // scalar (int) + Color(0.20, 0.88, 0.67), // scalar (uint) Color(0.74, 0.57, 0.95), // vector2 Color(0.84, 0.49, 0.93), // vector3 Color(1.0, 0.125, 0.95), // vector4 @@ -745,6 +746,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { hb->add_child(type_box); type_box->add_item(TTR("Float")); type_box->add_item(TTR("Int")); + type_box->add_item(TTR("UInt")); type_box->add_item(TTR("Vector2")); type_box->add_item(TTR("Vector3")); type_box->add_item(TTR("Vector4")); @@ -808,6 +810,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { hb->add_child(type_box); type_box->add_item(TTR("Float")); type_box->add_item(TTR("Int")); + type_box->add_item(TTR("UInt")); type_box->add_item(TTR("Vector2")); type_box->add_item(TTR("Vector3")); type_box->add_item(TTR("Vector4")); @@ -1700,6 +1703,9 @@ void VisualShaderEditor::_update_options_menu() { case VisualShaderNode::PORT_TYPE_SCALAR_INT: item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("int"), SNAME("EditorIcons"))); break; + case VisualShaderNode::PORT_TYPE_SCALAR_UINT: + item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("uint"), SNAME("EditorIcons"))); + break; case VisualShaderNode::PORT_TYPE_VECTOR_2D: item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons"))); break; @@ -1808,6 +1814,7 @@ void VisualShaderEditor::_update_parameters(bool p_update_refs) { if (parameter.is_valid()) { Ref<VisualShaderNodeFloatParameter> float_parameter = vsnode; Ref<VisualShaderNodeIntParameter> int_parameter = vsnode; + Ref<VisualShaderNodeUIntParameter> uint_parameter = vsnode; Ref<VisualShaderNodeVec2Parameter> vec2_parameter = vsnode; Ref<VisualShaderNodeVec3Parameter> vec3_parameter = vsnode; Ref<VisualShaderNodeVec4Parameter> vec4_parameter = vsnode; @@ -1820,6 +1827,8 @@ void VisualShaderEditor::_update_parameters(bool p_update_refs) { parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_FLOAT; } else if (int_parameter.is_valid()) { parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_INT; + } else if (uint_parameter.is_valid()) { + parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_UINT; } else if (boolean_parameter.is_valid()) { parameter_type = VisualShaderNodeParameterRef::PARAMETER_TYPE_BOOLEAN; } else if (vec2_parameter.is_valid()) { @@ -2673,6 +2682,28 @@ void VisualShaderEditor::_setup_node(VisualShaderNode *p_node, const Vector<Vari } } + // UINT_OP + { + VisualShaderNodeUIntOp *uintOp = Object::cast_to<VisualShaderNodeUIntOp>(p_node); + + if (uintOp) { + ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); + uintOp->set_operator((VisualShaderNodeUIntOp::Operator)(int)p_ops[0]); + return; + } + } + + // UINT_FUNC + { + VisualShaderNodeUIntFunc *uintFunc = Object::cast_to<VisualShaderNodeUIntFunc>(p_node); + + if (uintFunc) { + ERR_FAIL_COND(p_ops[0].get_type() != Variant::INT); + uintFunc->set_function((VisualShaderNodeUIntFunc::Function)(int)p_ops[0]); + return; + } + } + // TRANSFORM_OP { VisualShaderNodeTransformOp *matOp = Object::cast_to<VisualShaderNodeTransformOp>(p_node); @@ -2962,6 +2993,9 @@ void VisualShaderEditor::_add_node(int p_idx, const Vector<Variant> &p_ops, Stri case VisualShaderNode::PORT_TYPE_SCALAR_INT: initial_expression_code = "output0 = 1;"; break; + case VisualShaderNode::PORT_TYPE_SCALAR_UINT: + initial_expression_code = "output0 = 1u;"; + break; case VisualShaderNode::PORT_TYPE_VECTOR_2D: initial_expression_code = "output0 = vec2(1.0, 1.0);"; break; @@ -4524,6 +4558,9 @@ void VisualShaderEditor::_update_varying_tree() { case VisualShader::VARYING_TYPE_INT: item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("int"), SNAME("EditorIcons"))); break; + case VisualShader::VARYING_TYPE_UINT: + item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("uint"), SNAME("EditorIcons"))); + break; case VisualShader::VARYING_TYPE_VECTOR_2D: item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons"))); break; @@ -4905,6 +4942,7 @@ VisualShaderEditor::VisualShaderEditor() { graph->set_connection_lines_curvature(graph_lines_curvature); graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR); graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_INT); + graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT); graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_BOOLEAN); graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_2D); graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR_3D); @@ -4927,20 +4965,31 @@ VisualShaderEditor::VisualShaderEditor() { graph->connect("visibility_changed", callable_mp(this, &VisualShaderEditor::_visibility_changed)); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_INT); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_UINT); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_2D); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_3D); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR_4D); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_BOOLEAN); - graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR_INT); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR_INT); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_SCALAR_UINT); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_2D); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_3D); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_VECTOR_4D); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_INT, VisualShaderNode::PORT_TYPE_BOOLEAN); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR_INT); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_SCALAR_UINT); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_2D); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_3D); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_VECTOR_4D); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR_UINT, VisualShaderNode::PORT_TYPE_BOOLEAN); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR_INT); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_SCALAR_UINT); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_2D); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_3D); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_2D, VisualShaderNode::PORT_TYPE_VECTOR_4D); @@ -4948,6 +4997,7 @@ VisualShaderEditor::VisualShaderEditor() { graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR_INT); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_SCALAR_UINT); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_2D); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_3D); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_3D, VisualShaderNode::PORT_TYPE_VECTOR_4D); @@ -4955,6 +5005,7 @@ VisualShaderEditor::VisualShaderEditor() { graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR_INT); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_SCALAR_UINT); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_2D); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_3D); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_VECTOR_4D, VisualShaderNode::PORT_TYPE_VECTOR_4D); @@ -4962,6 +5013,7 @@ VisualShaderEditor::VisualShaderEditor() { graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR_INT); + graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_SCALAR_UINT); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_2D); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_3D); graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShaderNode::PORT_TYPE_VECTOR_4D); @@ -5178,6 +5230,7 @@ VisualShaderEditor::VisualShaderEditor() { hb->add_child(varying_type); varying_type->add_item("Float"); varying_type->add_item("Int"); + varying_type->add_item("UInt"); varying_type->add_item("Vector2"); varying_type->add_item("Vector3"); varying_type->add_item("Vector4"); @@ -5313,6 +5366,7 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("SwitchFloat (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated floating-point scalar if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_FLOAT }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("SwitchInt (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated integer scalar if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_INT }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); add_options.push_back(AddOption("SwitchTransform (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated transform if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_TRANSFORM }, VisualShaderNode::PORT_TYPE_TRANSFORM)); + add_options.push_back(AddOption("SwitchUInt (==)", "Conditional/Functions", "VisualShaderNodeSwitch", TTR("Returns an associated unsigned integer scalar if the provided boolean value is true or false."), { VisualShaderNodeSwitch::OP_TYPE_UINT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("Compare (==)", "Conditional/Common", "VisualShaderNodeCompare", TTR("Returns the boolean result of the comparison between two parameters."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN)); add_options.push_back(AddOption("Is", "Conditional/Common", "VisualShaderNodeIs", TTR("Returns the boolean result of the comparison between INF (or NaN) and a scalar parameter."), {}, VisualShaderNode::PORT_TYPE_BOOLEAN)); @@ -5354,8 +5408,10 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Custom", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "custom", "CUSTOM"), { "custom" }, VisualShaderNode::PORT_TYPE_VECTOR_4D, -1, Shader::MODE_PARTICLES)); add_options.push_back(AddOption("Delta", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "delta", "DELTA"), { "delta" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_PARTICLES)); add_options.push_back(AddOption("EmissionTransform", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "emission_transform", "EMISSION_TRANSFORM"), { "emission_transform" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_PARTICLES)); - add_options.push_back(AddOption("Index", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "index", "INDEX"), { "index" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, -1, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("Index", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "index", "INDEX"), { "index" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, -1, Shader::MODE_PARTICLES)); add_options.push_back(AddOption("LifeTime", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "lifetime", "LIFETIME"), { "lifetime" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("Number", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "number", "NUMBER"), { "number" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, -1, Shader::MODE_PARTICLES)); + add_options.push_back(AddOption("RandomSeed", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "random_seed", "RANDOM_SEED"), { "random_seed" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, -1, Shader::MODE_PARTICLES)); add_options.push_back(AddOption("Restart", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "restart", "RESTART"), { "restart" }, VisualShaderNode::PORT_TYPE_BOOLEAN, -1, Shader::MODE_PARTICLES)); add_options.push_back(AddOption("Time", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "time", "TIME"), { "time" }, VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_PARTICLES)); add_options.push_back(AddOption("Transform", "Input/All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "transform", "TRANSFORM"), { "transform" }, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_PARTICLES)); @@ -5400,7 +5456,7 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("NodePositionWorld", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "node_position_world", "NODE_POSITION_WORLD"), { "node_position_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("CameraPositionWorld", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_position_world", "CAMERA_POSITION_WORLD"), { "camera_position_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("CameraDirectionWorld", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_direction_world", "CAMERA_DIRECTION_WORLD"), { "camera_direction_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("CameraVisibleLayers", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_visible_layers", "CAMERA_VISIBLE_LAYERS"), { "camera_visible_layers" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("CameraVisibleLayers", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_visible_layers", "CAMERA_VISIBLE_LAYERS"), { "camera_visible_layers" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("NodePositionView", "Input/Vertex", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "node_position_view", "NODE_POSITION_VIEW"), { "node_position_view" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_VERTEX, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("Binormal", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "binormal", "BINORMAL"), { "binormal" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); @@ -5420,7 +5476,7 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("NodePositionWorld", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "node_position_world", "NODE_POSITION_WORLD"), { "node_position_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("CameraPositionWorld", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_position_world", "CAMERA_POSITION_WORLD"), { "camera_position_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("CameraDirectionWorld", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_direction_world", "CAMERA_DIRECTION_WORLD"), { "camera_direction_world" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); - add_options.push_back(AddOption("CameraVisibleLayers", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_visible_layers", "CAMERA_VISIBLE_LAYERS"), { "camera_visible_layers" }, VisualShaderNode::PORT_TYPE_SCALAR_INT, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("CameraVisibleLayers", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "camera_visible_layers", "CAMERA_VISIBLE_LAYERS"), { "camera_visible_layers" }, VisualShaderNode::PORT_TYPE_SCALAR_UINT, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("NodePositionView", "Input/Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "node_position_view", "NODE_POSITION_VIEW"), { "node_position_view" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_FRAGMENT, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("Albedo", "Input/Light", "VisualShaderNodeInput", vformat(input_param_for_light_shader_mode, "albedo", "ALBEDO"), { "albedo" }, VisualShaderNode::PORT_TYPE_VECTOR_3D, TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL)); @@ -5540,6 +5596,8 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("FloatOp", "Scalar/Common", "VisualShaderNodeFloatOp", TTR("Float operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("IntFunc", "Scalar/Common", "VisualShaderNodeIntFunc", TTR("Integer function."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT)); add_options.push_back(AddOption("IntOp", "Scalar/Common", "VisualShaderNodeIntOp", TTR("Integer operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("UIntFunc", "Scalar/Common", "VisualShaderNodeUIntFunc", TTR("Unsigned integer function."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); + add_options.push_back(AddOption("UIntOp", "Scalar/Common", "VisualShaderNodeUIntOp", TTR("Unsigned integer operator."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); // CONSTANTS @@ -5558,9 +5616,11 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("ATan2", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the arc-tangent of the parameters."), { VisualShaderNodeFloatOp::OP_ATAN2 }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("ATanH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), { VisualShaderNodeFloatFunc::FUNC_ATANH }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("BitwiseNOT", "Scalar/Functions", "VisualShaderNodeIntFunc", TTR("Returns the result of bitwise NOT (~a) operation on the integer."), { VisualShaderNodeIntFunc::FUNC_BITWISE_NOT }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("BitwiseNOT", "Scalar/Functions", "VisualShaderNodeUIntFunc", TTR("Returns the result of bitwise NOT (~a) operation on the unsigned integer."), { VisualShaderNodeUIntFunc::FUNC_BITWISE_NOT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("Ceil", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Finds the nearest integer that is greater than or equal to the parameter."), { VisualShaderNodeFloatFunc::FUNC_CEIL }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Clamp", "Scalar/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_FLOAT }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Clamp", "Scalar/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_INT }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("Clamp", "Scalar/Functions", "VisualShaderNodeClamp", TTR("Constrains a value to lie between two further values."), { VisualShaderNodeClamp::OP_TYPE_UINT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("Cos", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_COS }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("CosH", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the hyperbolic cosine of the parameter."), { VisualShaderNodeFloatFunc::FUNC_COSH }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Degrees", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in radians to degrees."), { VisualShaderNodeFloatFunc::FUNC_DEGREES }, VisualShaderNode::PORT_TYPE_SCALAR)); @@ -5579,6 +5639,7 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("MultiplyAdd (a * b + c)", "Scalar/Functions", "VisualShaderNodeMultiplyAdd", TTR("Performs a fused multiply-add operation (a * b + c) on scalars."), { VisualShaderNodeMultiplyAdd::OP_TYPE_SCALAR }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Negate (*-1)", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeFloatFunc::FUNC_NEGATE }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Negate (*-1)", "Scalar/Functions", "VisualShaderNodeIntFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeIntFunc::FUNC_NEGATE }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("Negate (*-1)", "Scalar/Functions", "VisualShaderNodeUIntFunc", TTR("Returns the opposite value of the parameter."), { VisualShaderNodeUIntFunc::FUNC_NEGATE }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("OneMinus (1-)", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("1.0 - scalar"), { VisualShaderNodeFloatFunc::FUNC_ONEMINUS }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Pow", "Scalar/Functions", "VisualShaderNodeFloatOp", TTR("Returns the value of the first parameter raised to the power of the second."), { VisualShaderNodeFloatOp::OP_POW }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Radians", "Scalar/Functions", "VisualShaderNodeFloatFunc", TTR("Converts a quantity in degrees to radians."), { VisualShaderNodeFloatFunc::FUNC_RADIANS }, VisualShaderNode::PORT_TYPE_SCALAR)); @@ -5600,24 +5661,36 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Sums two floating-point scalars."), { VisualShaderNodeFloatOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Sums two integer scalars."), { VisualShaderNodeIntOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("Add (+)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Sums two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_ADD }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("BitwiseAND (&)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise AND (a & b) operation for two integers."), { VisualShaderNodeIntOp::OP_BITWISE_AND }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("BitwiseAND (&)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise AND (a & b) operation for two unsigned integers."), { VisualShaderNodeUIntOp::OP_BITWISE_AND }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("BitwiseLeftShift (<<)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise left shift (a << b) operation on the integer."), { VisualShaderNodeIntOp::OP_BITWISE_LEFT_SHIFT }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("BitwiseLeftShift (<<)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise left shift (a << b) operation on the unsigned integer."), { VisualShaderNodeUIntOp::OP_BITWISE_LEFT_SHIFT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("BitwiseOR (|)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise OR (a | b) operation for two integers."), { VisualShaderNodeIntOp::OP_BITWISE_OR }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("BitwiseOR (|)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise OR (a | b) operation for two unsigned integers."), { VisualShaderNodeUIntOp::OP_BITWISE_OR }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("BitwiseRightShift (>>)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise right shift (a >> b) operation on the integer."), { VisualShaderNodeIntOp::OP_BITWISE_RIGHT_SHIFT }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("BitwiseRightShift (>>)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise right shift (a >> b) operation on the unsigned integer."), { VisualShaderNodeIntOp::OP_BITWISE_RIGHT_SHIFT }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("BitwiseXOR (^)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the result of bitwise XOR (a ^ b) operation on the integer."), { VisualShaderNodeIntOp::OP_BITWISE_XOR }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("BitwiseXOR (^)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the result of bitwise XOR (a ^ b) operation on the unsigned integer."), { VisualShaderNodeUIntOp::OP_BITWISE_XOR }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Divides two floating-point scalars."), { VisualShaderNodeFloatOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Divides two integer scalars."), { VisualShaderNodeIntOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("Divide (/)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Divides two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_DIV }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Multiplies two floating-point scalars."), { VisualShaderNodeFloatOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Multiplies two integer scalars."), { VisualShaderNodeIntOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("Multiply (*)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Multiplies two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_MUL }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("Remainder", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Returns the remainder of the two floating-point scalars."), { VisualShaderNodeFloatOp::OP_MOD }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Remainder", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Returns the remainder of the two integer scalars."), { VisualShaderNodeIntOp::OP_MOD }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("Remainder", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Returns the remainder of the two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_MOD }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeFloatOp", TTR("Subtracts two floating-point scalars."), { VisualShaderNodeFloatOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeIntOp", TTR("Subtracts two integer scalars."), { VisualShaderNodeIntOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("Subtract (-)", "Scalar/Operators", "VisualShaderNodeUIntOp", TTR("Subtracts two unsigned integer scalars."), { VisualShaderNodeUIntOp::OP_SUB }, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("FloatConstant", "Scalar/Variables", "VisualShaderNodeFloatConstant", TTR("Scalar floating-point constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("IntConstant", "Scalar/Variables", "VisualShaderNodeIntConstant", TTR("Scalar integer constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("UIntConstant", "Scalar/Variables", "VisualShaderNodeUIntConstant", TTR("Scalar unsigned integer constant."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); add_options.push_back(AddOption("FloatParameter", "Scalar/Variables", "VisualShaderNodeFloatParameter", TTR("Scalar floating-point parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("IntParameter", "Scalar/Variables", "VisualShaderNodeIntParameter", TTR("Scalar integer parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR_INT)); + add_options.push_back(AddOption("UIntParameter", "Scalar/Variables", "VisualShaderNodeUIntParameter", TTR("Scalar unsigned integer parameter."), {}, VisualShaderNode::PORT_TYPE_SCALAR_UINT)); // SDF { @@ -5942,6 +6015,7 @@ public: Ref<Texture2D> type_icon[] = { EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("float"), SNAME("EditorIcons")), EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("int"), SNAME("EditorIcons")), + EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("uint"), SNAME("EditorIcons")), EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons")), EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector3"), SNAME("EditorIcons")), EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector4"), SNAME("EditorIcons")), @@ -5991,6 +6065,7 @@ public: Ref<Texture2D> type_icon[] = { EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("float"), SNAME("EditorIcons")), EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("int"), SNAME("EditorIcons")), + EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("uint"), SNAME("EditorIcons")), EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons")), EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector3"), SNAME("EditorIcons")), EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector4"), SNAME("EditorIcons")), @@ -6070,6 +6145,7 @@ public: Ref<Texture2D> type_icon[] = { EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("float"), SNAME("EditorIcons")), EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("int"), SNAME("EditorIcons")), + EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("uint"), SNAME("EditorIcons")), EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("bool"), SNAME("EditorIcons")), EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons")), EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Vector3"), SNAME("EditorIcons")), diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index b2d1f06da1..00c538976f 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -602,6 +602,7 @@ void register_scene_types() { GDREGISTER_CLASS(VisualShaderNodeComment); GDREGISTER_CLASS(VisualShaderNodeFloatConstant); GDREGISTER_CLASS(VisualShaderNodeIntConstant); + GDREGISTER_CLASS(VisualShaderNodeUIntConstant); GDREGISTER_CLASS(VisualShaderNodeBooleanConstant); GDREGISTER_CLASS(VisualShaderNodeColorConstant); GDREGISTER_CLASS(VisualShaderNodeVec2Constant); @@ -610,12 +611,14 @@ void register_scene_types() { GDREGISTER_CLASS(VisualShaderNodeTransformConstant); GDREGISTER_CLASS(VisualShaderNodeFloatOp); GDREGISTER_CLASS(VisualShaderNodeIntOp); + GDREGISTER_CLASS(VisualShaderNodeUIntOp); GDREGISTER_CLASS(VisualShaderNodeVectorOp); GDREGISTER_CLASS(VisualShaderNodeColorOp); GDREGISTER_CLASS(VisualShaderNodeTransformOp); GDREGISTER_CLASS(VisualShaderNodeTransformVecMult); GDREGISTER_CLASS(VisualShaderNodeFloatFunc); GDREGISTER_CLASS(VisualShaderNodeIntFunc); + GDREGISTER_CLASS(VisualShaderNodeUIntFunc); GDREGISTER_CLASS(VisualShaderNodeVectorFunc); GDREGISTER_CLASS(VisualShaderNodeColorFunc); GDREGISTER_CLASS(VisualShaderNodeTransformFunc); @@ -648,6 +651,7 @@ void register_scene_types() { GDREGISTER_CLASS(VisualShaderNodeParameterRef); GDREGISTER_CLASS(VisualShaderNodeFloatParameter); GDREGISTER_CLASS(VisualShaderNodeIntParameter); + GDREGISTER_CLASS(VisualShaderNodeUIntParameter); GDREGISTER_CLASS(VisualShaderNodeBooleanParameter); GDREGISTER_CLASS(VisualShaderNodeColorParameter); GDREGISTER_CLASS(VisualShaderNodeVec2Parameter); diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index d8a963f15b..0008250f8f 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -403,6 +403,7 @@ void VisualShaderNode::_bind_methods() { BIND_ENUM_CONSTANT(PORT_TYPE_SCALAR); BIND_ENUM_CONSTANT(PORT_TYPE_SCALAR_INT); + BIND_ENUM_CONSTANT(PORT_TYPE_SCALAR_UINT); BIND_ENUM_CONSTANT(PORT_TYPE_VECTOR_2D); BIND_ENUM_CONSTANT(PORT_TYPE_VECTOR_3D); BIND_ENUM_CONSTANT(PORT_TYPE_VECTOR_4D); @@ -951,7 +952,7 @@ bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_po } bool VisualShader::is_port_types_compatible(int p_a, int p_b) const { - return MAX(0, p_a - 5) == (MAX(0, p_b - 5)); + return MAX(0, p_a - (int)VisualShaderNode::PORT_TYPE_BOOLEAN) == (MAX(0, p_b - (int)VisualShaderNode::PORT_TYPE_BOOLEAN)); } void VisualShader::connect_nodes_forced(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) { @@ -1198,6 +1199,9 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port case VisualShaderNode::PORT_TYPE_SCALAR_INT: { shader_code += " COLOR.rgb = vec3(float(n_out" + itos(p_node) + "p" + itos(p_port) + "));\n"; } break; + case VisualShaderNode::PORT_TYPE_SCALAR_UINT: { + shader_code += " COLOR.rgb = vec3(float(n_out" + itos(p_node) + "p" + itos(p_port) + "));\n"; + } break; case VisualShaderNode::PORT_TYPE_BOOLEAN: { shader_code += " COLOR.rgb = vec3(n_out" + itos(p_node) + "p" + itos(p_port) + " ? 1.0 : 0.0);\n"; } break; @@ -1689,6 +1693,9 @@ Error VisualShader::_write_node(Type type, StringBuilder *p_global_code, StringB case VisualShaderNode::PORT_TYPE_SCALAR_INT: { inputs[i] = "float(" + src_var + ")"; } break; + case VisualShaderNode::PORT_TYPE_SCALAR_UINT: { + inputs[i] = "float(" + src_var + ")"; + } break; case VisualShaderNode::PORT_TYPE_BOOLEAN: { inputs[i] = "(" + src_var + " ? 1.0 : 0.0)"; } break; @@ -1710,17 +1717,44 @@ Error VisualShader::_write_node(Type type, StringBuilder *p_global_code, StringB case VisualShaderNode::PORT_TYPE_SCALAR: { inputs[i] = "int(" + src_var + ")"; } break; + case VisualShaderNode::PORT_TYPE_SCALAR_UINT: { + inputs[i] = "int(" + src_var + ")"; + } break; case VisualShaderNode::PORT_TYPE_BOOLEAN: { inputs[i] = "(" + src_var + " ? 1 : 0)"; } break; case VisualShaderNode::PORT_TYPE_VECTOR_2D: { - inputs[i] = "dot(float(" + src_var + "), vec2(0.5, 0.5))"; + inputs[i] = "int(" + src_var + ".x)"; + } break; + case VisualShaderNode::PORT_TYPE_VECTOR_3D: { + inputs[i] = "int(" + src_var + ".x)"; + } break; + case VisualShaderNode::PORT_TYPE_VECTOR_4D: { + inputs[i] = "int(" + src_var + ".x)"; + } break; + default: + break; + } + } break; + case VisualShaderNode::PORT_TYPE_SCALAR_UINT: { + switch (out_type) { + case VisualShaderNode::PORT_TYPE_SCALAR: { + inputs[i] = "uint(" + src_var + ")"; + } break; + case VisualShaderNode::PORT_TYPE_SCALAR_INT: { + inputs[i] = "uint(" + src_var + ")"; + } break; + case VisualShaderNode::PORT_TYPE_BOOLEAN: { + inputs[i] = "(" + src_var + " ? 1u : 0u)"; + } break; + case VisualShaderNode::PORT_TYPE_VECTOR_2D: { + inputs[i] = "uint(" + src_var + ".x)"; } break; case VisualShaderNode::PORT_TYPE_VECTOR_3D: { - inputs[i] = "dot(float(" + src_var + "), vec3(0.333333, 0.333333, 0.333333))"; + inputs[i] = "uint(" + src_var + ".x)"; } break; case VisualShaderNode::PORT_TYPE_VECTOR_4D: { - inputs[i] = "dot(float(" + src_var + "), vec4(0.25, 0.25, 0.25, 0.25))"; + inputs[i] = "uint(" + src_var + ".x)"; } break; default: break; @@ -1734,6 +1768,9 @@ Error VisualShader::_write_node(Type type, StringBuilder *p_global_code, StringB case VisualShaderNode::PORT_TYPE_SCALAR_INT: { inputs[i] = src_var + " > 0 ? true : false"; } break; + case VisualShaderNode::PORT_TYPE_SCALAR_UINT: { + inputs[i] = src_var + " > 0u ? true : false"; + } break; case VisualShaderNode::PORT_TYPE_VECTOR_2D: { inputs[i] = "all(bvec2(" + src_var + "))"; } break; @@ -1755,6 +1792,9 @@ Error VisualShader::_write_node(Type type, StringBuilder *p_global_code, StringB case VisualShaderNode::PORT_TYPE_SCALAR_INT: { inputs[i] = "vec2(float(" + src_var + "))"; } break; + case VisualShaderNode::PORT_TYPE_SCALAR_UINT: { + inputs[i] = "vec2(float(" + src_var + "))"; + } break; case VisualShaderNode::PORT_TYPE_BOOLEAN: { inputs[i] = "vec2(" + src_var + " ? 1.0 : 0.0)"; } break; @@ -1775,6 +1815,9 @@ Error VisualShader::_write_node(Type type, StringBuilder *p_global_code, StringB case VisualShaderNode::PORT_TYPE_SCALAR_INT: { inputs[i] = "vec3(float(" + src_var + "))"; } break; + case VisualShaderNode::PORT_TYPE_SCALAR_UINT: { + inputs[i] = "vec3(float(" + src_var + "))"; + } break; case VisualShaderNode::PORT_TYPE_BOOLEAN: { inputs[i] = "vec3(" + src_var + " ? 1.0 : 0.0)"; } break; @@ -1796,6 +1839,9 @@ Error VisualShader::_write_node(Type type, StringBuilder *p_global_code, StringB case VisualShaderNode::PORT_TYPE_SCALAR_INT: { inputs[i] = "vec4(float(" + src_var + "))"; } break; + case VisualShaderNode::PORT_TYPE_SCALAR_UINT: { + inputs[i] = "vec4(float(" + src_var + "))"; + } break; case VisualShaderNode::PORT_TYPE_BOOLEAN: { inputs[i] = "vec4(" + src_var + " ? 1.0 : 0.0)"; } break; @@ -1826,7 +1872,11 @@ Error VisualShader::_write_node(Type type, StringBuilder *p_global_code, StringB } else if (defval.get_type() == Variant::INT) { int val = defval; inputs[i] = "n_in" + itos(p_node) + "p" + itos(i); - node_code += " int " + inputs[i] + " = " + itos(val) + ";\n"; + if (vsnode->get_input_port_type(i) == VisualShaderNode::PORT_TYPE_SCALAR_UINT) { + node_code += " uint " + inputs[i] + " = " + itos(val) + "u;\n"; + } else { + node_code += " int " + inputs[i] + " = " + itos(val) + ";\n"; + } } else if (defval.get_type() == Variant::BOOL) { bool val = defval; inputs[i] = "n_in" + itos(p_node) + "p" + itos(i); @@ -1906,6 +1956,9 @@ Error VisualShader::_write_node(Type type, StringBuilder *p_global_code, StringB case VisualShaderNode::PORT_TYPE_SCALAR_INT: outputs[i] = "int " + var_name; break; + case VisualShaderNode::PORT_TYPE_SCALAR_UINT: + outputs[i] = "uint " + var_name; + break; case VisualShaderNode::PORT_TYPE_VECTOR_2D: outputs[i] = "vec2 " + var_name; break; @@ -1951,6 +2004,9 @@ Error VisualShader::_write_node(Type type, StringBuilder *p_global_code, StringB case VisualShaderNode::PORT_TYPE_SCALAR_INT: r_code += " int " + outputs[i] + ";\n"; break; + case VisualShaderNode::PORT_TYPE_SCALAR_UINT: + r_code += " uint " + outputs[i] + ";\n"; + break; case VisualShaderNode::PORT_TYPE_VECTOR_2D: r_code += " vec2 " + outputs[i] + ";\n"; break; @@ -2214,6 +2270,12 @@ void VisualShader::_update_shader() const { } global_code += "int "; break; + case VaryingType::VARYING_TYPE_UINT: + if (E.value.mode == VaryingMode::VARYING_MODE_VERTEX_TO_FRAG_LIGHT) { + global_code += "flat "; + } + global_code += "uint "; + break; case VaryingType::VARYING_TYPE_VECTOR_2D: global_code += "vec2 "; break; @@ -2283,6 +2345,9 @@ void VisualShader::_update_shader() const { case VaryingType::VARYING_TYPE_INT: code2 += "0"; break; + case VaryingType::VARYING_TYPE_UINT: + code2 += "0u"; + break; case VaryingType::VARYING_TYPE_VECTOR_2D: code2 += "vec2(0.0)"; break; @@ -2583,6 +2648,7 @@ void VisualShader::_bind_methods() { BIND_ENUM_CONSTANT(VARYING_TYPE_FLOAT); BIND_ENUM_CONSTANT(VARYING_TYPE_INT); + BIND_ENUM_CONSTANT(VARYING_TYPE_UINT); BIND_ENUM_CONSTANT(VARYING_TYPE_VECTOR_2D); BIND_ENUM_CONSTANT(VARYING_TYPE_VECTOR_3D); BIND_ENUM_CONSTANT(VARYING_TYPE_VECTOR_4D); @@ -2648,7 +2714,7 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = { { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "node_position_world", "NODE_POSITION_WORLD" }, { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "camera_position_world", "CAMERA_POSITION_WORLD" }, { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "camera_direction_world", "CAMERA_DIRECTION_WORLD" }, - { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR_INT, "camera_visible_layers", "CAMERA_VISIBLE_LAYERS" }, + { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "camera_visible_layers", "CAMERA_VISIBLE_LAYERS" }, { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "node_position_view", "NODE_POSITION_VIEW" }, { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_4D, "custom0", "CUSTOM0" }, { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_4D, "custom1", "CUSTOM1" }, @@ -2685,7 +2751,7 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = { { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "node_position_world", "NODE_POSITION_WORLD" }, { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "camera_position_world", "CAMERA_POSITION_WORLD" }, { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "camera_direction_world", "CAMERA_DIRECTION_WORLD" }, - { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR_INT, "camera_visible_layers", "CAMERA_VISIBLE_LAYERS" }, + { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "camera_visible_layers", "CAMERA_VISIBLE_LAYERS" }, { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "node_position_view", "NODE_POSITION_VIEW" }, // Node3D, Light @@ -2776,7 +2842,9 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = { { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_TRANSFORM, "transform", "TRANSFORM" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_SCALAR, "delta", "DELTA" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_SCALAR, "lifetime", "LIFETIME" }, - { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_SCALAR_INT, "index", "INDEX" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "index", "INDEX" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "number", "NUMBER" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "random_seed", "RANDOM_SEED" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_TRANSFORM, "emission_transform", "EMISSION_TRANSFORM" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, @@ -2790,7 +2858,9 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = { { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_TRANSFORM, "transform", "TRANSFORM" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "delta", "DELTA" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "lifetime", "LIFETIME" }, - { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR_INT, "index", "INDEX" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "index", "INDEX" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "number", "NUMBER" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "random_seed", "RANDOM_SEED" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_TRANSFORM, "emission_transform", "EMISSION_TRANSFORM" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, @@ -2804,7 +2874,9 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = { { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_TRANSFORM, "transform", "TRANSFORM" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_SCALAR, "delta", "DELTA" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_SCALAR, "lifetime", "LIFETIME" }, - { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_SCALAR_INT, "index", "INDEX" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "index", "INDEX" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "number", "NUMBER" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "random_seed", "RANDOM_SEED" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_TRANSFORM, "emission_transform", "EMISSION_TRANSFORM" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, @@ -2818,7 +2890,9 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = { { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_TRANSFORM, "transform", "TRANSFORM" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "delta", "DELTA" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "lifetime", "LIFETIME" }, - { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR_INT, "index", "INDEX" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "index", "INDEX" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "number", "NUMBER" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "random_seed", "RANDOM_SEED" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_TRANSFORM, "emission_transform", "EMISSION_TRANSFORM" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, @@ -2834,7 +2908,9 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = { { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_TRANSFORM, "transform", "TRANSFORM" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_SCALAR, "delta", "DELTA" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_SCALAR, "lifetime", "LIFETIME" }, - { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_SCALAR_INT, "index", "INDEX" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "index", "INDEX" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "number", "NUMBER" }, + { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_SCALAR_UINT, "random_seed", "RANDOM_SEED" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_TRANSFORM, "emission_transform", "EMISSION_TRANSFORM" }, { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" }, @@ -3252,6 +3328,8 @@ int VisualShaderNodeParameterRef::get_output_port_count() const { return 1; case PARAMETER_TYPE_INT: return 1; + case PARAMETER_TYPE_UINT: + return 1; case PARAMETER_TYPE_BOOLEAN: return 1; case PARAMETER_TYPE_VECTOR2: @@ -3278,6 +3356,8 @@ VisualShaderNodeParameterRef::PortType VisualShaderNodeParameterRef::get_output_ return PortType::PORT_TYPE_SCALAR; case PARAMETER_TYPE_INT: return PortType::PORT_TYPE_SCALAR_INT; + case PARAMETER_TYPE_UINT: + return PortType::PORT_TYPE_SCALAR_UINT; case PARAMETER_TYPE_BOOLEAN: return PortType::PORT_TYPE_BOOLEAN; case PARAMETER_TYPE_VECTOR2: @@ -3309,6 +3389,8 @@ String VisualShaderNodeParameterRef::get_output_port_name(int p_port) const { return ""; case PARAMETER_TYPE_INT: return ""; + case PARAMETER_TYPE_UINT: + return ""; case PARAMETER_TYPE_BOOLEAN: return ""; case PARAMETER_TYPE_VECTOR2: @@ -3403,6 +3485,8 @@ VisualShaderNodeParameterRef::PortType VisualShaderNodeParameterRef::get_port_ty return PORT_TYPE_SCALAR; case PARAMETER_TYPE_INT: return PORT_TYPE_SCALAR_INT; + case PARAMETER_TYPE_UINT: + return PORT_TYPE_SCALAR_UINT; case UNIFORM_TYPE_SAMPLER: return PORT_TYPE_SAMPLER; case PARAMETER_TYPE_VECTOR2: @@ -4659,6 +4743,8 @@ String VisualShaderNodeVarying::get_type_str() const { return "float"; case VisualShader::VARYING_TYPE_INT: return "int"; + case VisualShader::VARYING_TYPE_UINT: + return "uint"; case VisualShader::VARYING_TYPE_VECTOR_2D: return "vec2"; case VisualShader::VARYING_TYPE_VECTOR_3D: @@ -4679,6 +4765,8 @@ VisualShaderNodeVarying::PortType VisualShaderNodeVarying::get_port_type(VisualS switch (p_type) { case VisualShader::VARYING_TYPE_INT: return PORT_TYPE_SCALAR_INT; + case VisualShader::VARYING_TYPE_UINT: + return PORT_TYPE_SCALAR_UINT; case VisualShader::VARYING_TYPE_VECTOR_2D: return PORT_TYPE_VECTOR_2D; case VisualShader::VARYING_TYPE_VECTOR_3D: @@ -4811,6 +4899,9 @@ String VisualShaderNodeVaryingGetter::generate_code(Shader::Mode p_mode, VisualS case VisualShader::VARYING_TYPE_INT: from = "0"; break; + case VisualShader::VARYING_TYPE_UINT: + from = "0u"; + break; case VisualShader::VARYING_TYPE_VECTOR_2D: from = "vec2(0.0)"; break; diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h index b8ee693a84..0d53589fa5 100644 --- a/scene/resources/visual_shader.h +++ b/scene/resources/visual_shader.h @@ -80,6 +80,7 @@ public: enum VaryingType { VARYING_TYPE_FLOAT, VARYING_TYPE_INT, + VARYING_TYPE_UINT, VARYING_TYPE_VECTOR_2D, VARYING_TYPE_VECTOR_3D, VARYING_TYPE_VECTOR_4D, @@ -260,6 +261,7 @@ public: enum PortType { PORT_TYPE_SCALAR, PORT_TYPE_SCALAR_INT, + PORT_TYPE_SCALAR_UINT, PORT_TYPE_VECTOR_2D, PORT_TYPE_VECTOR_3D, PORT_TYPE_VECTOR_4D, @@ -550,6 +552,7 @@ public: enum ParameterType { PARAMETER_TYPE_FLOAT, PARAMETER_TYPE_INT, + PARAMETER_TYPE_UINT, PARAMETER_TYPE_BOOLEAN, PARAMETER_TYPE_VECTOR2, PARAMETER_TYPE_VECTOR3, diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp index df8e836a51..432d5a5b59 100644 --- a/scene/resources/visual_shader_nodes.cpp +++ b/scene/resources/visual_shader_nodes.cpp @@ -223,6 +223,68 @@ void VisualShaderNodeIntConstant::_bind_methods() { VisualShaderNodeIntConstant::VisualShaderNodeIntConstant() { } +////////////// Scalar(UInt) + +String VisualShaderNodeUIntConstant::get_caption() const { + return "UIntConstant"; +} + +int VisualShaderNodeUIntConstant::get_input_port_count() const { + return 0; +} + +VisualShaderNodeUIntConstant::PortType VisualShaderNodeUIntConstant::get_input_port_type(int p_port) const { + return PORT_TYPE_SCALAR_UINT; +} + +String VisualShaderNodeUIntConstant::get_input_port_name(int p_port) const { + return String(); +} + +int VisualShaderNodeUIntConstant::get_output_port_count() const { + return 1; +} + +VisualShaderNodeUIntConstant::PortType VisualShaderNodeUIntConstant::get_output_port_type(int p_port) const { + return PORT_TYPE_SCALAR_UINT; +} + +String VisualShaderNodeUIntConstant::get_output_port_name(int p_port) const { + return ""; // No output port means the editor will be used as port. +} + +String VisualShaderNodeUIntConstant::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 { + return " " + p_output_vars[0] + " = " + itos(constant) + "u;\n"; +} + +void VisualShaderNodeUIntConstant::set_constant(int p_constant) { + if (constant == p_constant) { + return; + } + constant = p_constant; + emit_changed(); +} + +int VisualShaderNodeUIntConstant::get_constant() const { + return constant; +} + +Vector<StringName> VisualShaderNodeUIntConstant::get_editable_properties() const { + Vector<StringName> props; + props.push_back("constant"); + return props; +} + +void VisualShaderNodeUIntConstant::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_constant", "constant"), &VisualShaderNodeUIntConstant::set_constant); + ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeUIntConstant::get_constant); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "constant"), "set_constant", "get_constant"); +} + +VisualShaderNodeUIntConstant::VisualShaderNodeUIntConstant() { +} + ////////////// Boolean String VisualShaderNodeBooleanConstant::get_caption() const { @@ -1797,7 +1859,7 @@ VisualShaderNodeIntOp::PortType VisualShaderNodeIntOp::get_output_port_type(int } String VisualShaderNodeIntOp::get_output_port_name(int p_port) const { - return "op"; //no output port means the editor will be used as port + return "op"; // No output port means the editor will be used as port. } String VisualShaderNodeIntOp::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 { @@ -1891,6 +1953,127 @@ VisualShaderNodeIntOp::VisualShaderNodeIntOp() { set_input_port_default_value(1, 0); } +////////////// Unsigned Integer Op + +String VisualShaderNodeUIntOp::get_caption() const { + return "UIntOp"; +} + +int VisualShaderNodeUIntOp::get_input_port_count() const { + return 2; +} + +VisualShaderNodeUIntOp::PortType VisualShaderNodeUIntOp::get_input_port_type(int p_port) const { + return PORT_TYPE_SCALAR_UINT; +} + +String VisualShaderNodeUIntOp::get_input_port_name(int p_port) const { + return p_port == 0 ? "a" : "b"; +} + +int VisualShaderNodeUIntOp::get_output_port_count() const { + return 1; +} + +VisualShaderNodeUIntOp::PortType VisualShaderNodeUIntOp::get_output_port_type(int p_port) const { + return PORT_TYPE_SCALAR_UINT; +} + +String VisualShaderNodeUIntOp::get_output_port_name(int p_port) const { + return "op"; // No output port means the editor will be used as port. +} + +String VisualShaderNodeUIntOp::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 { + String code = " " + p_output_vars[0] + " = "; + switch (op) { + case OP_ADD: + code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n"; + break; + case OP_SUB: + code += p_input_vars[0] + " - " + p_input_vars[1] + ";\n"; + break; + case OP_MUL: + code += p_input_vars[0] + " * " + p_input_vars[1] + ";\n"; + break; + case OP_DIV: + code += p_input_vars[0] + " / " + p_input_vars[1] + ";\n"; + break; + case OP_MOD: + code += p_input_vars[0] + " % " + p_input_vars[1] + ";\n"; + break; + case OP_MAX: + code += "max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; + break; + case OP_MIN: + code += "min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; + break; + case OP_BITWISE_AND: + code += p_input_vars[0] + " & " + p_input_vars[1] + ";\n"; + break; + case OP_BITWISE_OR: + code += p_input_vars[0] + " | " + p_input_vars[1] + ";\n"; + break; + case OP_BITWISE_XOR: + code += p_input_vars[0] + " ^ " + p_input_vars[1] + ";\n"; + break; + case OP_BITWISE_LEFT_SHIFT: + code += p_input_vars[0] + " << " + p_input_vars[1] + ";\n"; + break; + case OP_BITWISE_RIGHT_SHIFT: + code += p_input_vars[0] + " >> " + p_input_vars[1] + ";\n"; + break; + default: + break; + } + + return code; +} + +void VisualShaderNodeUIntOp::set_operator(Operator p_op) { + ERR_FAIL_INDEX(int(p_op), OP_ENUM_SIZE); + if (op == p_op) { + return; + } + op = p_op; + emit_changed(); +} + +VisualShaderNodeUIntOp::Operator VisualShaderNodeUIntOp::get_operator() const { + return op; +} + +Vector<StringName> VisualShaderNodeUIntOp::get_editable_properties() const { + Vector<StringName> props; + props.push_back("operator"); + return props; +} + +void VisualShaderNodeUIntOp::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeUIntOp::set_operator); + ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeUIntOp::get_operator); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "Add,Subtract,Multiply,Divide,Remainder,Max,Min,Bitwise AND,Bitwise OR,Bitwise XOR,Bitwise Left Shift,Bitwise Right Shift"), "set_operator", "get_operator"); + + BIND_ENUM_CONSTANT(OP_ADD); + BIND_ENUM_CONSTANT(OP_SUB); + BIND_ENUM_CONSTANT(OP_MUL); + BIND_ENUM_CONSTANT(OP_DIV); + BIND_ENUM_CONSTANT(OP_MOD); + BIND_ENUM_CONSTANT(OP_MAX); + BIND_ENUM_CONSTANT(OP_MIN); + BIND_ENUM_CONSTANT(OP_BITWISE_AND); + BIND_ENUM_CONSTANT(OP_BITWISE_OR); + BIND_ENUM_CONSTANT(OP_BITWISE_XOR); + BIND_ENUM_CONSTANT(OP_BITWISE_LEFT_SHIFT); + BIND_ENUM_CONSTANT(OP_BITWISE_RIGHT_SHIFT); + BIND_ENUM_CONSTANT(OP_ENUM_SIZE); +} + +VisualShaderNodeUIntOp::VisualShaderNodeUIntOp() { + set_input_port_default_value(0, 0); + set_input_port_default_value(1, 0); +} + ////////////// Vector Op String VisualShaderNodeVectorOp::get_caption() const { @@ -2626,6 +2809,79 @@ VisualShaderNodeIntFunc::VisualShaderNodeIntFunc() { set_input_port_default_value(0, 0); } +////////////// Unsigned Int Func + +String VisualShaderNodeUIntFunc::get_caption() const { + return "UIntFunc"; +} + +int VisualShaderNodeUIntFunc::get_input_port_count() const { + return 1; +} + +VisualShaderNodeUIntFunc::PortType VisualShaderNodeUIntFunc::get_input_port_type(int p_port) const { + return PORT_TYPE_SCALAR_UINT; +} + +String VisualShaderNodeUIntFunc::get_input_port_name(int p_port) const { + return ""; +} + +int VisualShaderNodeUIntFunc::get_output_port_count() const { + return 1; +} + +VisualShaderNodeUIntFunc::PortType VisualShaderNodeUIntFunc::get_output_port_type(int p_port) const { + return PORT_TYPE_SCALAR_UINT; +} + +String VisualShaderNodeUIntFunc::get_output_port_name(int p_port) const { + return ""; // No output port means the editor will be used as port. +} + +String VisualShaderNodeUIntFunc::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 { + static const char *functions[FUNC_MAX] = { + "-($)", + "~($)" + }; + + return " " + p_output_vars[0] + " = " + String(functions[func]).replace("$", p_input_vars[0]) + ";\n"; +} + +void VisualShaderNodeUIntFunc::set_function(Function p_func) { + ERR_FAIL_INDEX(int(p_func), int(FUNC_MAX)); + if (func == p_func) { + return; + } + func = p_func; + emit_changed(); +} + +VisualShaderNodeUIntFunc::Function VisualShaderNodeUIntFunc::get_function() const { + return func; +} + +Vector<StringName> VisualShaderNodeUIntFunc::get_editable_properties() const { + Vector<StringName> props; + props.push_back("function"); + return props; +} + +void VisualShaderNodeUIntFunc::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeUIntFunc::set_function); + ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeUIntFunc::get_function); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Negate,Bitwise NOT"), "set_function", "get_function"); + + BIND_ENUM_CONSTANT(FUNC_NEGATE); + BIND_ENUM_CONSTANT(FUNC_BITWISE_NOT); + BIND_ENUM_CONSTANT(FUNC_MAX); +} + +VisualShaderNodeUIntFunc::VisualShaderNodeUIntFunc() { + set_input_port_default_value(0, 0); +} + ////////////// Vector Func String VisualShaderNodeVectorFunc::get_caption() const { @@ -3531,6 +3787,8 @@ VisualShaderNodeClamp::PortType VisualShaderNodeClamp::get_input_port_type(int p switch (op_type) { case OP_TYPE_INT: return PORT_TYPE_SCALAR_INT; + case OP_TYPE_UINT: + return PORT_TYPE_SCALAR_UINT; case OP_TYPE_VECTOR_2D: return PORT_TYPE_VECTOR_2D; case OP_TYPE_VECTOR_3D: @@ -3562,6 +3820,8 @@ VisualShaderNodeClamp::PortType VisualShaderNodeClamp::get_output_port_type(int switch (op_type) { case OP_TYPE_INT: return PORT_TYPE_SCALAR_INT; + case OP_TYPE_UINT: + return PORT_TYPE_SCALAR_UINT; case OP_TYPE_VECTOR_2D: return PORT_TYPE_VECTOR_2D; case OP_TYPE_VECTOR_3D: @@ -3593,6 +3853,7 @@ void VisualShaderNodeClamp::set_op_type(OpType p_op_type) { set_input_port_default_value(1, 0.0, get_input_port_default_value(1)); set_input_port_default_value(2, 0.0, get_input_port_default_value(2)); break; + case OP_TYPE_UINT: case OP_TYPE_INT: set_input_port_default_value(0, 0, get_input_port_default_value(0)); set_input_port_default_value(1, 0, get_input_port_default_value(1)); @@ -3634,10 +3895,11 @@ void VisualShaderNodeClamp::_bind_methods() { ClassDB::bind_method(D_METHOD("set_op_type", "op_type"), &VisualShaderNodeClamp::set_op_type); ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeClamp::get_op_type); - ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Float,Int,Vector2,Vector3,Vector4"), "set_op_type", "get_op_type"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Float,Int,UInt,Vector2,Vector3,Vector4"), "set_op_type", "get_op_type"); BIND_ENUM_CONSTANT(OP_TYPE_FLOAT); BIND_ENUM_CONSTANT(OP_TYPE_INT); + BIND_ENUM_CONSTANT(OP_TYPE_UINT); BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D); BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D); BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D); @@ -4914,7 +5176,7 @@ Vector<StringName> VisualShaderNodeFloatParameter::get_editable_properties() con VisualShaderNodeFloatParameter::VisualShaderNodeFloatParameter() { } -////////////// Integer Parametet +////////////// Integer Parameter String VisualShaderNodeIntParameter::get_caption() const { return "IntParameter"; @@ -5105,6 +5367,112 @@ Vector<StringName> VisualShaderNodeIntParameter::get_editable_properties() const VisualShaderNodeIntParameter::VisualShaderNodeIntParameter() { } +////////////// Unsigned Integer Parameter + +String VisualShaderNodeUIntParameter::get_caption() const { + return "UIntParameter"; +} + +int VisualShaderNodeUIntParameter::get_input_port_count() const { + return 0; +} + +VisualShaderNodeUIntParameter::PortType VisualShaderNodeUIntParameter::get_input_port_type(int p_port) const { + return PORT_TYPE_SCALAR_UINT; +} + +String VisualShaderNodeUIntParameter::get_input_port_name(int p_port) const { + return String(); +} + +int VisualShaderNodeUIntParameter::get_output_port_count() const { + return 1; +} + +VisualShaderNodeUIntParameter::PortType VisualShaderNodeUIntParameter::get_output_port_type(int p_port) const { + return PORT_TYPE_SCALAR_UINT; +} + +String VisualShaderNodeUIntParameter::get_output_port_name(int p_port) const { + return ""; // No output port means the editor will be used as port. +} + +String VisualShaderNodeUIntParameter::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { + String code = _get_qual_str() + "uniform uint " + get_parameter_name(); + if (default_value_enabled) { + code += " = " + itos(default_value); + } + code += ";\n"; + return code; +} + +String VisualShaderNodeUIntParameter::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 { + return " " + p_output_vars[0] + " = " + get_parameter_name() + ";\n"; +} + +bool VisualShaderNodeUIntParameter::is_show_prop_names() const { + return true; +} + +bool VisualShaderNodeUIntParameter::is_use_prop_slots() const { + return true; +} + +void VisualShaderNodeUIntParameter::set_default_value_enabled(bool p_default_value_enabled) { + if (default_value_enabled == p_default_value_enabled) { + return; + } + default_value_enabled = p_default_value_enabled; + emit_changed(); +} + +bool VisualShaderNodeUIntParameter::is_default_value_enabled() const { + return default_value_enabled; +} + +void VisualShaderNodeUIntParameter::set_default_value(int p_default_value) { + if (default_value == p_default_value) { + return; + } + default_value = p_default_value; + emit_changed(); +} + +int VisualShaderNodeUIntParameter::get_default_value() const { + return default_value; +} + +void VisualShaderNodeUIntParameter::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_default_value_enabled", "enabled"), &VisualShaderNodeUIntParameter::set_default_value_enabled); + ClassDB::bind_method(D_METHOD("is_default_value_enabled"), &VisualShaderNodeUIntParameter::is_default_value_enabled); + + ClassDB::bind_method(D_METHOD("set_default_value", "value"), &VisualShaderNodeUIntParameter::set_default_value); + ClassDB::bind_method(D_METHOD("get_default_value"), &VisualShaderNodeUIntParameter::get_default_value); + + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "default_value_enabled"), "set_default_value_enabled", "is_default_value_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "default_value"), "set_default_value", "get_default_value"); +} + +bool VisualShaderNodeUIntParameter::is_qualifier_supported(Qualifier p_qual) const { + return true; // All qualifiers are supported. +} + +bool VisualShaderNodeUIntParameter::is_convertible_to_constant() const { + return true; // Conversion is allowed. +} + +Vector<StringName> VisualShaderNodeUIntParameter::get_editable_properties() const { + Vector<StringName> props = VisualShaderNodeParameter::get_editable_properties(); + props.push_back("default_value_enabled"); + if (default_value_enabled) { + props.push_back("default_value"); + } + return props; +} + +VisualShaderNodeUIntParameter::VisualShaderNodeUIntParameter() { +} + ////////////// Boolean Parameter String VisualShaderNodeBooleanParameter::get_caption() const { @@ -6315,6 +6683,8 @@ VisualShaderNodeSwitch::PortType VisualShaderNodeSwitch::get_input_port_type(int switch (op_type) { case OP_TYPE_INT: return PORT_TYPE_SCALAR_INT; + case OP_TYPE_UINT: + return PORT_TYPE_SCALAR_UINT; case OP_TYPE_VECTOR_2D: return PORT_TYPE_VECTOR_2D; case OP_TYPE_VECTOR_3D: @@ -6353,6 +6723,8 @@ VisualShaderNodeSwitch::PortType VisualShaderNodeSwitch::get_output_port_type(in switch (op_type) { case OP_TYPE_INT: return PORT_TYPE_SCALAR_INT; + case OP_TYPE_UINT: + return PORT_TYPE_SCALAR_UINT; case OP_TYPE_VECTOR_2D: return PORT_TYPE_VECTOR_2D; case OP_TYPE_VECTOR_3D: @@ -6383,6 +6755,7 @@ void VisualShaderNodeSwitch::set_op_type(OpType p_op_type) { set_input_port_default_value(1, 1.0, get_input_port_default_value(1)); set_input_port_default_value(2, 0.0, get_input_port_default_value(2)); break; + case OP_TYPE_UINT: case OP_TYPE_INT: set_input_port_default_value(1, 1, get_input_port_default_value(1)); set_input_port_default_value(2, 0, get_input_port_default_value(2)); @@ -6428,10 +6801,11 @@ void VisualShaderNodeSwitch::_bind_methods() { // static ClassDB::bind_method(D_METHOD("set_op_type", "type"), &VisualShaderNodeSwitch::set_op_type); ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeSwitch::get_op_type); - ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Float,Int,Vector2,Vector3,Vector4,Boolean,Transform"), "set_op_type", "get_op_type"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Float,Int,UInt,Vector2,Vector3,Vector4,Boolean,Transform"), "set_op_type", "get_op_type"); BIND_ENUM_CONSTANT(OP_TYPE_FLOAT); BIND_ENUM_CONSTANT(OP_TYPE_INT); + BIND_ENUM_CONSTANT(OP_TYPE_UINT); BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D); BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D); BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_4D); @@ -6664,6 +7038,8 @@ VisualShaderNodeCompare::PortType VisualShaderNodeCompare::get_input_port_type(i return PORT_TYPE_SCALAR; case CTYPE_SCALAR_INT: return PORT_TYPE_SCALAR_INT; + case CTYPE_SCALAR_UINT: + return PORT_TYPE_SCALAR_UINT; case CTYPE_VECTOR_2D: return PORT_TYPE_VECTOR_2D; case CTYPE_VECTOR_3D: @@ -6749,6 +7125,7 @@ String VisualShaderNodeCompare::generate_code(Shader::Mode p_mode, VisualShader: code += " " + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", operators[func]) + ";\n"; } } break; + case CTYPE_SCALAR_UINT: case CTYPE_SCALAR_INT: { code += " " + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", operators[func]) + ";\n"; } break; @@ -6799,6 +7176,7 @@ void VisualShaderNodeCompare::set_comparison_type(ComparisonType p_comparison_ty set_input_port_default_value(1, 0.0, get_input_port_default_value(1)); simple_decl = true; break; + case CTYPE_SCALAR_UINT: case CTYPE_SCALAR_INT: set_input_port_default_value(0, 0, get_input_port_default_value(0)); set_input_port_default_value(1, 0, get_input_port_default_value(1)); @@ -6886,12 +7264,13 @@ void VisualShaderNodeCompare::_bind_methods() { ClassDB::bind_method(D_METHOD("set_condition", "condition"), &VisualShaderNodeCompare::set_condition); ClassDB::bind_method(D_METHOD("get_condition"), &VisualShaderNodeCompare::get_condition); - ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, "Float,Int,Vector2,Vector3,Vector4,Boolean,Transform"), "set_comparison_type", "get_comparison_type"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, "Float,Int,UInt,Vector2,Vector3,Vector4,Boolean,Transform"), "set_comparison_type", "get_comparison_type"); ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "a == b,a != b,a > b,a >= b,a < b,a <= b"), "set_function", "get_function"); ADD_PROPERTY(PropertyInfo(Variant::INT, "condition", PROPERTY_HINT_ENUM, "All,Any"), "set_condition", "get_condition"); BIND_ENUM_CONSTANT(CTYPE_SCALAR); BIND_ENUM_CONSTANT(CTYPE_SCALAR_INT); + BIND_ENUM_CONSTANT(CTYPE_SCALAR_UINT); BIND_ENUM_CONSTANT(CTYPE_VECTOR_2D); BIND_ENUM_CONSTANT(CTYPE_VECTOR_3D); BIND_ENUM_CONSTANT(CTYPE_VECTOR_4D); diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h index b2d71a35a6..07843c0264 100644 --- a/scene/resources/visual_shader_nodes.h +++ b/scene/resources/visual_shader_nodes.h @@ -160,6 +160,36 @@ public: /////////////////////////////////////// +class VisualShaderNodeUIntConstant : public VisualShaderNodeConstant { + GDCLASS(VisualShaderNodeUIntConstant, VisualShaderNodeConstant); + int constant = 0; + +protected: + static void _bind_methods(); + +public: + virtual String get_caption() const override; + + virtual int get_input_port_count() const override; + virtual PortType get_input_port_type(int p_port) const override; + virtual String get_input_port_name(int p_port) const override; + + virtual int get_output_port_count() const override; + virtual PortType get_output_port_type(int p_port) const override; + virtual String get_output_port_name(int p_port) const override; + + virtual String 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 = false) const override; + + void set_constant(int p_constant); + int get_constant() const; + + virtual Vector<StringName> get_editable_properties() const override; + + VisualShaderNodeUIntConstant(); +}; + +/////////////////////////////////////// + class VisualShaderNodeBooleanConstant : public VisualShaderNodeConstant { GDCLASS(VisualShaderNodeBooleanConstant, VisualShaderNodeConstant); bool constant = false; @@ -741,6 +771,54 @@ public: VARIANT_ENUM_CAST(VisualShaderNodeIntOp::Operator) +class VisualShaderNodeUIntOp : public VisualShaderNode { + GDCLASS(VisualShaderNodeUIntOp, VisualShaderNode); + +public: + enum Operator { + OP_ADD, + OP_SUB, + OP_MUL, + OP_DIV, + OP_MOD, + OP_MAX, + OP_MIN, + OP_BITWISE_AND, + OP_BITWISE_OR, + OP_BITWISE_XOR, + OP_BITWISE_LEFT_SHIFT, + OP_BITWISE_RIGHT_SHIFT, + OP_ENUM_SIZE, + }; + +protected: + Operator op = OP_ADD; + + static void _bind_methods(); + +public: + virtual String get_caption() const override; + + virtual int get_input_port_count() const override; + virtual PortType get_input_port_type(int p_port) const override; + virtual String get_input_port_name(int p_port) const override; + + virtual int get_output_port_count() const override; + virtual PortType get_output_port_type(int p_port) const override; + virtual String get_output_port_name(int p_port) const override; + + virtual String 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 = false) const override; + + void set_operator(Operator p_op); + Operator get_operator() const; + + virtual Vector<StringName> get_editable_properties() const override; + + VisualShaderNodeUIntOp(); +}; + +VARIANT_ENUM_CAST(VisualShaderNodeUIntOp::Operator) + class VisualShaderNodeVectorOp : public VisualShaderNodeVectorBase { GDCLASS(VisualShaderNodeVectorOp, VisualShaderNodeVectorBase); @@ -1047,6 +1125,48 @@ public: VARIANT_ENUM_CAST(VisualShaderNodeIntFunc::Function) /////////////////////////////////////// +/// UINT FUNC +/////////////////////////////////////// + +class VisualShaderNodeUIntFunc : public VisualShaderNode { + GDCLASS(VisualShaderNodeUIntFunc, VisualShaderNode); + +public: + enum Function { + FUNC_NEGATE, + FUNC_BITWISE_NOT, + FUNC_MAX, + }; + +protected: + Function func = FUNC_NEGATE; + + static void _bind_methods(); + +public: + virtual String get_caption() const override; + + virtual int get_input_port_count() const override; + virtual PortType get_input_port_type(int p_port) const override; + virtual String get_input_port_name(int p_port) const override; + + virtual int get_output_port_count() const override; + virtual PortType get_output_port_type(int p_port) const override; + virtual String get_output_port_name(int p_port) const override; + + virtual String 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 = false) const override; + + void set_function(Function p_func); + Function get_function() const; + + virtual Vector<StringName> get_editable_properties() const override; + + VisualShaderNodeUIntFunc(); +}; + +VARIANT_ENUM_CAST(VisualShaderNodeUIntFunc::Function) + +/////////////////////////////////////// /// VECTOR FUNC /////////////////////////////////////// @@ -1356,6 +1476,7 @@ public: enum OpType { OP_TYPE_FLOAT, OP_TYPE_INT, + OP_TYPE_UINT, OP_TYPE_VECTOR_2D, OP_TYPE_VECTOR_3D, OP_TYPE_VECTOR_4D, @@ -1902,6 +2023,49 @@ VARIANT_ENUM_CAST(VisualShaderNodeIntParameter::Hint) /////////////////////////////////////// +class VisualShaderNodeUIntParameter : public VisualShaderNodeParameter { + GDCLASS(VisualShaderNodeUIntParameter, VisualShaderNodeParameter); + +private: + bool default_value_enabled = false; + int default_value = 0; + +protected: + static void _bind_methods(); + +public: + virtual String get_caption() const override; + + virtual int get_input_port_count() const override; + virtual PortType get_input_port_type(int p_port) const override; + virtual String get_input_port_name(int p_port) const override; + + virtual int get_output_port_count() const override; + virtual PortType get_output_port_type(int p_port) const override; + virtual String get_output_port_name(int p_port) const override; + + virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override; + virtual String 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 = false) const override; + + virtual bool is_show_prop_names() const override; + virtual bool is_use_prop_slots() const override; + + void set_default_value_enabled(bool p_enabled); + bool is_default_value_enabled() const; + + void set_default_value(int p_value); + 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; + + VisualShaderNodeUIntParameter(); +}; + +/////////////////////////////////////// + class VisualShaderNodeBooleanParameter : public VisualShaderNodeParameter { GDCLASS(VisualShaderNodeBooleanParameter, VisualShaderNodeParameter); @@ -2361,6 +2525,7 @@ public: enum OpType { OP_TYPE_FLOAT, OP_TYPE_INT, + OP_TYPE_UINT, OP_TYPE_VECTOR_2D, OP_TYPE_VECTOR_3D, OP_TYPE_VECTOR_4D, @@ -2476,6 +2641,7 @@ public: enum ComparisonType { CTYPE_SCALAR, CTYPE_SCALAR_INT, + CTYPE_SCALAR_UINT, CTYPE_VECTOR_2D, CTYPE_VECTOR_3D, CTYPE_VECTOR_4D, |