class_visualshadernodecustom.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/VisualShaderNodeCustom.xml.
  6. .. _class_VisualShaderNodeCustom:
  7. VisualShaderNodeCustom
  8. ======================
  9. **Inherits:** :ref:`VisualShaderNode<class_VisualShaderNode>` **<** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Virtual class to define custom :ref:`VisualShaderNode<class_VisualShaderNode>`\ s for use in the Visual Shader Editor.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. 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.
  15. In order for the node to be registered as an editor addon, you must use the ``@tool`` annotation and provide a ``class_name`` for your custom script. For example:
  16. ::
  17. @tool
  18. extends VisualShaderNodeCustom
  19. class_name VisualShaderNodeNoise
  20. .. rst-class:: classref-introduction-group
  21. Tutorials
  22. ---------
  23. - :doc:`Visual Shader plugins <../tutorials/plugins/editor/visual_shader_plugins>`
  24. .. rst-class:: classref-reftable-group
  25. Methods
  26. -------
  27. .. table::
  28. :widths: auto
  29. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`String<class_String>` | :ref:`_get_category<class_VisualShaderNodeCustom_method__get_category>` **(** **)** |virtual| |const| |
  31. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`String<class_String>` | :ref:`_get_code<class_VisualShaderNodeCustom_method__get_code>` **(** :ref:`String[]<class_String>` input_vars, :ref:`String[]<class_String>` output_vars, :ref:`Mode<enum_Shader_Mode>` mode, :ref:`Type<enum_VisualShader_Type>` type **)** |virtual| |const| |
  33. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`int<class_int>` | :ref:`_get_default_input_port<class_VisualShaderNodeCustom_method__get_default_input_port>` **(** :ref:`PortType<enum_VisualShaderNode_PortType>` type **)** |virtual| |const| |
  35. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`String<class_String>` | :ref:`_get_description<class_VisualShaderNodeCustom_method__get_description>` **(** **)** |virtual| |const| |
  37. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`String<class_String>` | :ref:`_get_func_code<class_VisualShaderNodeCustom_method__get_func_code>` **(** :ref:`Mode<enum_Shader_Mode>` mode, :ref:`Type<enum_VisualShader_Type>` type **)** |virtual| |const| |
  39. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`String<class_String>` | :ref:`_get_global_code<class_VisualShaderNodeCustom_method__get_global_code>` **(** :ref:`Mode<enum_Shader_Mode>` mode **)** |virtual| |const| |
  41. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`int<class_int>` | :ref:`_get_input_port_count<class_VisualShaderNodeCustom_method__get_input_port_count>` **(** **)** |virtual| |const| |
  43. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`String<class_String>` | :ref:`_get_input_port_name<class_VisualShaderNodeCustom_method__get_input_port_name>` **(** :ref:`int<class_int>` port **)** |virtual| |const| |
  45. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`PortType<enum_VisualShaderNode_PortType>` | :ref:`_get_input_port_type<class_VisualShaderNodeCustom_method__get_input_port_type>` **(** :ref:`int<class_int>` port **)** |virtual| |const| |
  47. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`String<class_String>` | :ref:`_get_name<class_VisualShaderNodeCustom_method__get_name>` **(** **)** |virtual| |const| |
  49. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`int<class_int>` | :ref:`_get_output_port_count<class_VisualShaderNodeCustom_method__get_output_port_count>` **(** **)** |virtual| |const| |
  51. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`String<class_String>` | :ref:`_get_output_port_name<class_VisualShaderNodeCustom_method__get_output_port_name>` **(** :ref:`int<class_int>` port **)** |virtual| |const| |
  53. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`PortType<enum_VisualShaderNode_PortType>` | :ref:`_get_output_port_type<class_VisualShaderNodeCustom_method__get_output_port_type>` **(** :ref:`int<class_int>` port **)** |virtual| |const| |
  55. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`PortType<enum_VisualShaderNode_PortType>` | :ref:`_get_return_icon_type<class_VisualShaderNodeCustom_method__get_return_icon_type>` **(** **)** |virtual| |const| |
  57. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`bool<class_bool>` | :ref:`_is_available<class_VisualShaderNodeCustom_method__is_available>` **(** :ref:`Mode<enum_Shader_Mode>` mode, :ref:`Type<enum_VisualShader_Type>` type **)** |virtual| |const| |
  59. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`bool<class_bool>` | :ref:`_is_highend<class_VisualShaderNodeCustom_method__is_highend>` **(** **)** |virtual| |const| |
  61. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. .. rst-class:: classref-section-separator
  63. ----
  64. .. rst-class:: classref-descriptions-group
  65. Method Descriptions
  66. -------------------
  67. .. _class_VisualShaderNodeCustom_method__get_category:
  68. .. rst-class:: classref-method
  69. :ref:`String<class_String>` **_get_category** **(** **)** |virtual| |const|
  70. Override this method to define the path to the associated custom node in the Visual Shader Editor's members dialog. The path may look like ``"MyGame/MyFunctions/Noise"``.
  71. Defining this method is **optional**. If not overridden, the node will be filed under the "Addons" category.
  72. .. rst-class:: classref-item-separator
  73. ----
  74. .. _class_VisualShaderNodeCustom_method__get_code:
  75. .. rst-class:: classref-method
  76. :ref:`String<class_String>` **_get_code** **(** :ref:`String[]<class_String>` input_vars, :ref:`String[]<class_String>` output_vars, :ref:`Mode<enum_Shader_Mode>` mode, :ref:`Type<enum_VisualShader_Type>` type **)** |virtual| |const|
  77. 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).
  78. 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.
  79. The output ports can be assigned values in the shader code. For example, ``return output_vars[0] + " = " + input_vars[0] + ";"``.
  80. 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>`).
  81. Defining this method is **required**.
  82. .. rst-class:: classref-item-separator
  83. ----
  84. .. _class_VisualShaderNodeCustom_method__get_default_input_port:
  85. .. rst-class:: classref-method
  86. :ref:`int<class_int>` **_get_default_input_port** **(** :ref:`PortType<enum_VisualShaderNode_PortType>` type **)** |virtual| |const|
  87. Override this method to define the input port which should be connected by default when this node is created as a result of dragging a connection from an existing node to the empty space on the graph.
  88. Defining this method is **optional**. If not overridden, the connection will be created to the first valid port.
  89. .. rst-class:: classref-item-separator
  90. ----
  91. .. _class_VisualShaderNodeCustom_method__get_description:
  92. .. rst-class:: classref-method
  93. :ref:`String<class_String>` **_get_description** **(** **)** |virtual| |const|
  94. Override this method to define the description of the associated custom node in the Visual Shader Editor's members dialog.
  95. Defining this method is **optional**.
  96. .. rst-class:: classref-item-separator
  97. ----
  98. .. _class_VisualShaderNodeCustom_method__get_func_code:
  99. .. rst-class:: classref-method
  100. :ref:`String<class_String>` **_get_func_code** **(** :ref:`Mode<enum_Shader_Mode>` mode, :ref:`Type<enum_VisualShader_Type>` type **)** |virtual| |const|
  101. Override this method to add a shader code to the beginning of each shader function (once). The shader code should be returned as a string, which can have multiple lines (the ``"""`` multiline string construct can be used for convenience).
  102. If there are multiple custom nodes of different types which use this feature the order of each insertion is undefined.
  103. 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>`).
  104. Defining this method is **optional**.
  105. .. rst-class:: classref-item-separator
  106. ----
  107. .. _class_VisualShaderNodeCustom_method__get_global_code:
  108. .. rst-class:: classref-method
  109. :ref:`String<class_String>` **_get_global_code** **(** :ref:`Mode<enum_Shader_Mode>` mode **)** |virtual| |const|
  110. 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).
  111. 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.
  112. You can customize the generated code based on the shader ``mode`` (see :ref:`Mode<enum_Shader_Mode>`).
  113. Defining this method is **optional**.
  114. .. rst-class:: classref-item-separator
  115. ----
  116. .. _class_VisualShaderNodeCustom_method__get_input_port_count:
  117. .. rst-class:: classref-method
  118. :ref:`int<class_int>` **_get_input_port_count** **(** **)** |virtual| |const|
  119. Override this method to define the number of input ports of the associated custom node.
  120. Defining this method is **required**. If not overridden, the node has no input ports.
  121. .. rst-class:: classref-item-separator
  122. ----
  123. .. _class_VisualShaderNodeCustom_method__get_input_port_name:
  124. .. rst-class:: classref-method
  125. :ref:`String<class_String>` **_get_input_port_name** **(** :ref:`int<class_int>` port **)** |virtual| |const|
  126. 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>`.
  127. Defining this method is **optional**, but recommended. If not overridden, input ports are named as ``"in" + str(port)``.
  128. .. rst-class:: classref-item-separator
  129. ----
  130. .. _class_VisualShaderNodeCustom_method__get_input_port_type:
  131. .. rst-class:: classref-method
  132. :ref:`PortType<enum_VisualShaderNode_PortType>` **_get_input_port_type** **(** :ref:`int<class_int>` port **)** |virtual| |const|
  133. 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).
  134. 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.
  135. .. rst-class:: classref-item-separator
  136. ----
  137. .. _class_VisualShaderNodeCustom_method__get_name:
  138. .. rst-class:: classref-method
  139. :ref:`String<class_String>` **_get_name** **(** **)** |virtual| |const|
  140. Override this method to define the name of the associated custom node in the Visual Shader Editor's members dialog and graph.
  141. Defining this method is **optional**, but recommended. If not overridden, the node will be named as "Unnamed".
  142. .. rst-class:: classref-item-separator
  143. ----
  144. .. _class_VisualShaderNodeCustom_method__get_output_port_count:
  145. .. rst-class:: classref-method
  146. :ref:`int<class_int>` **_get_output_port_count** **(** **)** |virtual| |const|
  147. Override this method to define the number of output ports of the associated custom node.
  148. Defining this method is **required**. If not overridden, the node has no output ports.
  149. .. rst-class:: classref-item-separator
  150. ----
  151. .. _class_VisualShaderNodeCustom_method__get_output_port_name:
  152. .. rst-class:: classref-method
  153. :ref:`String<class_String>` **_get_output_port_name** **(** :ref:`int<class_int>` port **)** |virtual| |const|
  154. 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>`.
  155. Defining this method is **optional**, but recommended. If not overridden, output ports are named as ``"out" + str(port)``.
  156. .. rst-class:: classref-item-separator
  157. ----
  158. .. _class_VisualShaderNodeCustom_method__get_output_port_type:
  159. .. rst-class:: classref-method
  160. :ref:`PortType<enum_VisualShaderNode_PortType>` **_get_output_port_type** **(** :ref:`int<class_int>` port **)** |virtual| |const|
  161. 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).
  162. 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.
  163. .. rst-class:: classref-item-separator
  164. ----
  165. .. _class_VisualShaderNodeCustom_method__get_return_icon_type:
  166. .. rst-class:: classref-method
  167. :ref:`PortType<enum_VisualShaderNode_PortType>` **_get_return_icon_type** **(** **)** |virtual| |const|
  168. Override this method to define the return icon of the associated custom node in the Visual Shader Editor's members dialog.
  169. Defining this method is **optional**. If not overridden, no return icon is shown.
  170. .. rst-class:: classref-item-separator
  171. ----
  172. .. _class_VisualShaderNodeCustom_method__is_available:
  173. .. rst-class:: classref-method
  174. :ref:`bool<class_bool>` **_is_available** **(** :ref:`Mode<enum_Shader_Mode>` mode, :ref:`Type<enum_VisualShader_Type>` type **)** |virtual| |const|
  175. Override this method to prevent the node to be visible in the member dialog for the certain ``mode`` (see :ref:`Mode<enum_Shader_Mode>`) and/or ``type`` (see :ref:`Type<enum_VisualShader_Type>`).
  176. Defining this method is **optional**. If not overridden, it's ``true``.
  177. .. rst-class:: classref-item-separator
  178. ----
  179. .. _class_VisualShaderNodeCustom_method__is_highend:
  180. .. rst-class:: classref-method
  181. :ref:`bool<class_bool>` **_is_highend** **(** **)** |virtual| |const|
  182. Override this method to enable high-end mark in the Visual Shader Editor's members dialog.
  183. Defining this method is **optional**. If not overridden, it's ``false``.
  184. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  185. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  186. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  187. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  188. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  189. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  190. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`