class_visualshadernodecustom.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the VisualShaderNodeCustom.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_VisualShaderNodeCustom:
  6. VisualShaderNodeCustom
  7. ======================
  8. **Inherits:** :ref:`VisualShaderNode<class_VisualShaderNode>` **<** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. **Category:** Core
  10. Brief Description
  11. -----------------
  12. Virtual class to define custom :ref:`VisualShaderNode<class_VisualShaderNode>`\ s for use in the Visual Shader Editor.
  13. Methods
  14. -------
  15. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | :ref:`String<class_String>` | :ref:`_get_category<class_VisualShaderNodeCustom_method__get_category>` **(** **)** virtual |
  17. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`String<class_String>` | :ref:`_get_code<class_VisualShaderNodeCustom_method__get_code>` **(** :ref:`Array<class_Array>` input_vars, :ref:`Array<class_Array>` output_vars, :ref:`int<class_int>` mode, :ref:`int<class_int>` type **)** virtual |
  19. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`String<class_String>` | :ref:`_get_description<class_VisualShaderNodeCustom_method__get_description>` **(** **)** virtual |
  21. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`String<class_String>` | :ref:`_get_global_code<class_VisualShaderNodeCustom_method__get_global_code>` **(** :ref:`int<class_int>` mode **)** virtual |
  23. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`int<class_int>` | :ref:`_get_input_port_count<class_VisualShaderNodeCustom_method__get_input_port_count>` **(** **)** virtual |
  25. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`String<class_String>` | :ref:`_get_input_port_name<class_VisualShaderNodeCustom_method__get_input_port_name>` **(** :ref:`int<class_int>` port **)** virtual |
  27. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`int<class_int>` | :ref:`_get_input_port_type<class_VisualShaderNodeCustom_method__get_input_port_type>` **(** :ref:`int<class_int>` port **)** virtual |
  29. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`String<class_String>` | :ref:`_get_name<class_VisualShaderNodeCustom_method__get_name>` **(** **)** virtual |
  31. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`int<class_int>` | :ref:`_get_output_port_count<class_VisualShaderNodeCustom_method__get_output_port_count>` **(** **)** virtual |
  33. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`String<class_String>` | :ref:`_get_output_port_name<class_VisualShaderNodeCustom_method__get_output_port_name>` **(** :ref:`int<class_int>` port **)** virtual |
  35. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`int<class_int>` | :ref:`_get_output_port_type<class_VisualShaderNodeCustom_method__get_output_port_type>` **(** :ref:`int<class_int>` port **)** virtual |
  37. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`int<class_int>` | :ref:`_get_return_icon_type<class_VisualShaderNodeCustom_method__get_return_icon_type>` **(** **)** virtual |
  39. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`String<class_String>` | :ref:`_get_subcategory<class_VisualShaderNodeCustom_method__get_subcategory>` **(** **)** virtual |
  41. +-----------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. Description
  43. -----------
  44. By inheriting this class you can create a custom :ref:`VisualShader<class_VisualShader>` script addon which will be automatically added to the Visual Shader Editor. The :ref:`VisualShaderNode<class_VisualShaderNode>`'s behavior is defined by overriding the provided virtual methods.
  45. In order for the node to be registered as an editor addon, you must use the ``tool`` keyword and provide a ``class_name`` for your custom script. For example:
  46. ::
  47. tool
  48. extends VisualShaderNodeCustom
  49. class_name VisualShaderNodeNoise
  50. Tutorials
  51. ---------
  52. - :doc:`../tutorials/plugins/editor/visual_shader_plugins`
  53. Method Descriptions
  54. -------------------
  55. .. _class_VisualShaderNodeCustom_method__get_category:
  56. - :ref:`String<class_String>` **_get_category** **(** **)** virtual
  57. Override this method to define the category of the associated custom node in the Visual Shader Editor's members dialog.
  58. Defining this method is **optional**. If not overridden, the node will be filed under the "Custom" category.
  59. .. _class_VisualShaderNodeCustom_method__get_code:
  60. - :ref:`String<class_String>` **_get_code** **(** :ref:`Array<class_Array>` input_vars, :ref:`Array<class_Array>` output_vars, :ref:`int<class_int>` mode, :ref:`int<class_int>` type **)** virtual
  61. Override this method to define the actual shader code of the associated custom node. The shader code should be returned as a string, which can have multiple lines (the ``"""`` multiline string construct can be used for convenience).
  62. The ``input_vars`` and ``output_vars`` arrays contain the string names of the various input and output variables, as defined by ``_get_input_*`` and ``_get_output_*`` virtual methods in this class.
  63. The output ports can be assigned values in the shader code. For example, ``return output_vars[0] + " = " + input_vars[0] + ";"``.
  64. You can customize the generated code based on the shader ``mode`` (see :ref:`Mode<enum_Shader_Mode>`) and/or ``type`` (see :ref:`Type<enum_VisualShader_Type>`).
  65. Defining this method is **required**.
  66. .. _class_VisualShaderNodeCustom_method__get_description:
  67. - :ref:`String<class_String>` **_get_description** **(** **)** virtual
  68. Override this method to define the description of the associated custom node in the Visual Shader Editor's members dialog.
  69. Defining this method is **optional**.
  70. .. _class_VisualShaderNodeCustom_method__get_global_code:
  71. - :ref:`String<class_String>` **_get_global_code** **(** :ref:`int<class_int>` mode **)** virtual
  72. Override this method to add shader code on top of the global shader, to define your own standard library of reusable methods, varyings, constants, uniforms, etc. The shader code should be returned as a string, which can have multiple lines (the ``"""`` multiline string construct can be used for convenience).
  73. Be careful with this functionality as it can cause name conflicts with other custom nodes, so be sure to give the defined entities unique names.
  74. You can customize the generated code based on the shader ``mode`` (see :ref:`Mode<enum_Shader_Mode>`).
  75. Defining this method is **optional**.
  76. .. _class_VisualShaderNodeCustom_method__get_input_port_count:
  77. - :ref:`int<class_int>` **_get_input_port_count** **(** **)** virtual
  78. Override this method to define the amount of input ports of the associated custom node.
  79. Defining this method is **required**. If not overridden, the node has no input ports.
  80. .. _class_VisualShaderNodeCustom_method__get_input_port_name:
  81. - :ref:`String<class_String>` **_get_input_port_name** **(** :ref:`int<class_int>` port **)** virtual
  82. Override this method to define the names of input ports of the associated custom node. The names are used both for the input slots in the editor and as identifiers in the shader code, and are passed in the ``input_vars`` array in :ref:`_get_code<class_VisualShaderNodeCustom_method__get_code>`.
  83. Defining this method is **optional**, but recommended. If not overridden, input ports are named as ``"in" + str(port)``.
  84. .. _class_VisualShaderNodeCustom_method__get_input_port_type:
  85. - :ref:`int<class_int>` **_get_input_port_type** **(** :ref:`int<class_int>` port **)** virtual
  86. Override this method to define the returned type of each input port of the associated custom node (see :ref:`PortType<enum_VisualShaderNode_PortType>` for possible types).
  87. Defining this method is **optional**, but recommended. If not overridden, input ports will return the :ref:`VisualShaderNode.PORT_TYPE_SCALAR<class_VisualShaderNode_constant_PORT_TYPE_SCALAR>` type.
  88. .. _class_VisualShaderNodeCustom_method__get_name:
  89. - :ref:`String<class_String>` **_get_name** **(** **)** virtual
  90. Override this method to define the name of the associated custom node in the Visual Shader Editor's members dialog and graph.
  91. Defining this method is **optional**, but recommended. If not overridden, the node will be named as "Unnamed".
  92. .. _class_VisualShaderNodeCustom_method__get_output_port_count:
  93. - :ref:`int<class_int>` **_get_output_port_count** **(** **)** virtual
  94. Override this method to define the amount of output ports of the associated custom node.
  95. Defining this method is **required**. If not overridden, the node has no output ports.
  96. .. _class_VisualShaderNodeCustom_method__get_output_port_name:
  97. - :ref:`String<class_String>` **_get_output_port_name** **(** :ref:`int<class_int>` port **)** virtual
  98. Override this method to define the names of output ports of the associated custom node. The names are used both for the output slots in the editor and as identifiers in the shader code, and are passed in the ``output_vars`` array in :ref:`_get_code<class_VisualShaderNodeCustom_method__get_code>`.
  99. Defining this method is **optional**, but recommended. If not overridden, output ports are named as ``"out" + str(port)``.
  100. .. _class_VisualShaderNodeCustom_method__get_output_port_type:
  101. - :ref:`int<class_int>` **_get_output_port_type** **(** :ref:`int<class_int>` port **)** virtual
  102. Override this method to define the returned type of each output port of the associated custom node (see :ref:`PortType<enum_VisualShaderNode_PortType>` for possible types).
  103. Defining this method is **optional**, but recommended. If not overridden, output ports will return the :ref:`VisualShaderNode.PORT_TYPE_SCALAR<class_VisualShaderNode_constant_PORT_TYPE_SCALAR>` type.
  104. .. _class_VisualShaderNodeCustom_method__get_return_icon_type:
  105. - :ref:`int<class_int>` **_get_return_icon_type** **(** **)** virtual
  106. Override this method to define the return icon of the associated custom node in the Visual Shader Editor's members dialog.
  107. Defining this method is **optional**. If not overridden, no return icon is shown.
  108. .. _class_VisualShaderNodeCustom_method__get_subcategory:
  109. - :ref:`String<class_String>` **_get_subcategory** **(** **)** virtual
  110. Override this method to define the subcategory of the associated custom node in the Visual Shader Editor's members dialog.
  111. Defining this method is **optional**. If not overridden, the node will be filed under the root of the main category (see :ref:`_get_category<class_VisualShaderNodeCustom_method__get_category>`).