class_visualshadernodecustom.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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/4.0/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.0/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:`String<class_String>` | :ref:`_get_description<class_VisualShaderNodeCustom_method__get_description>` **(** **)** |virtual| |const| |
  35. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :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| |
  37. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`String<class_String>` | :ref:`_get_global_code<class_VisualShaderNodeCustom_method__get_global_code>` **(** :ref:`Mode<enum_Shader_Mode>` mode **)** |virtual| |const| |
  39. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`_get_input_port_count<class_VisualShaderNodeCustom_method__get_input_port_count>` **(** **)** |virtual| |const| |
  41. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`String<class_String>` | :ref:`_get_input_port_name<class_VisualShaderNodeCustom_method__get_input_port_name>` **(** :ref:`int<class_int>` port **)** |virtual| |const| |
  43. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`PortType<enum_VisualShaderNode_PortType>` | :ref:`_get_input_port_type<class_VisualShaderNodeCustom_method__get_input_port_type>` **(** :ref:`int<class_int>` port **)** |virtual| |const| |
  45. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`String<class_String>` | :ref:`_get_name<class_VisualShaderNodeCustom_method__get_name>` **(** **)** |virtual| |const| |
  47. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`int<class_int>` | :ref:`_get_output_port_count<class_VisualShaderNodeCustom_method__get_output_port_count>` **(** **)** |virtual| |const| |
  49. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`String<class_String>` | :ref:`_get_output_port_name<class_VisualShaderNodeCustom_method__get_output_port_name>` **(** :ref:`int<class_int>` port **)** |virtual| |const| |
  51. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`PortType<enum_VisualShaderNode_PortType>` | :ref:`_get_output_port_type<class_VisualShaderNodeCustom_method__get_output_port_type>` **(** :ref:`int<class_int>` port **)** |virtual| |const| |
  53. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`PortType<enum_VisualShaderNode_PortType>` | :ref:`_get_return_icon_type<class_VisualShaderNodeCustom_method__get_return_icon_type>` **(** **)** |virtual| |const| |
  55. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :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| |
  57. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`bool<class_bool>` | :ref:`_is_highend<class_VisualShaderNodeCustom_method__is_highend>` **(** **)** |virtual| |const| |
  59. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. .. rst-class:: classref-section-separator
  61. ----
  62. .. rst-class:: classref-descriptions-group
  63. Method Descriptions
  64. -------------------
  65. .. _class_VisualShaderNodeCustom_method__get_category:
  66. .. rst-class:: classref-method
  67. :ref:`String<class_String>` **_get_category** **(** **)** |virtual| |const|
  68. 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"``.
  69. Defining this method is **optional**. If not overridden, the node will be filed under the "Addons" category.
  70. .. rst-class:: classref-item-separator
  71. ----
  72. .. _class_VisualShaderNodeCustom_method__get_code:
  73. .. rst-class:: classref-method
  74. :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|
  75. 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).
  76. 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.
  77. The output ports can be assigned values in the shader code. For example, ``return output_vars[0] + " = " + input_vars[0] + ";"``.
  78. 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>`).
  79. Defining this method is **required**.
  80. .. rst-class:: classref-item-separator
  81. ----
  82. .. _class_VisualShaderNodeCustom_method__get_description:
  83. .. rst-class:: classref-method
  84. :ref:`String<class_String>` **_get_description** **(** **)** |virtual| |const|
  85. Override this method to define the description of the associated custom node in the Visual Shader Editor's members dialog.
  86. Defining this method is **optional**.
  87. .. rst-class:: classref-item-separator
  88. ----
  89. .. _class_VisualShaderNodeCustom_method__get_func_code:
  90. .. rst-class:: classref-method
  91. :ref:`String<class_String>` **_get_func_code** **(** :ref:`Mode<enum_Shader_Mode>` mode, :ref:`Type<enum_VisualShader_Type>` type **)** |virtual| |const|
  92. 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).
  93. If there are multiple custom nodes of different types which use this feature the order of each insertion is undefined.
  94. 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>`).
  95. Defining this method is **optional**.
  96. .. rst-class:: classref-item-separator
  97. ----
  98. .. _class_VisualShaderNodeCustom_method__get_global_code:
  99. .. rst-class:: classref-method
  100. :ref:`String<class_String>` **_get_global_code** **(** :ref:`Mode<enum_Shader_Mode>` mode **)** |virtual| |const|
  101. 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).
  102. 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.
  103. You can customize the generated code based on the shader ``mode`` (see :ref:`Mode<enum_Shader_Mode>`).
  104. Defining this method is **optional**.
  105. .. rst-class:: classref-item-separator
  106. ----
  107. .. _class_VisualShaderNodeCustom_method__get_input_port_count:
  108. .. rst-class:: classref-method
  109. :ref:`int<class_int>` **_get_input_port_count** **(** **)** |virtual| |const|
  110. Override this method to define the number of input ports of the associated custom node.
  111. Defining this method is **required**. If not overridden, the node has no input ports.
  112. .. rst-class:: classref-item-separator
  113. ----
  114. .. _class_VisualShaderNodeCustom_method__get_input_port_name:
  115. .. rst-class:: classref-method
  116. :ref:`String<class_String>` **_get_input_port_name** **(** :ref:`int<class_int>` port **)** |virtual| |const|
  117. 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>`.
  118. Defining this method is **optional**, but recommended. If not overridden, input ports are named as ``"in" + str(port)``.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_VisualShaderNodeCustom_method__get_input_port_type:
  122. .. rst-class:: classref-method
  123. :ref:`PortType<enum_VisualShaderNode_PortType>` **_get_input_port_type** **(** :ref:`int<class_int>` port **)** |virtual| |const|
  124. 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).
  125. 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.
  126. .. rst-class:: classref-item-separator
  127. ----
  128. .. _class_VisualShaderNodeCustom_method__get_name:
  129. .. rst-class:: classref-method
  130. :ref:`String<class_String>` **_get_name** **(** **)** |virtual| |const|
  131. Override this method to define the name of the associated custom node in the Visual Shader Editor's members dialog and graph.
  132. Defining this method is **optional**, but recommended. If not overridden, the node will be named as "Unnamed".
  133. .. rst-class:: classref-item-separator
  134. ----
  135. .. _class_VisualShaderNodeCustom_method__get_output_port_count:
  136. .. rst-class:: classref-method
  137. :ref:`int<class_int>` **_get_output_port_count** **(** **)** |virtual| |const|
  138. Override this method to define the number of output ports of the associated custom node.
  139. Defining this method is **required**. If not overridden, the node has no output ports.
  140. .. rst-class:: classref-item-separator
  141. ----
  142. .. _class_VisualShaderNodeCustom_method__get_output_port_name:
  143. .. rst-class:: classref-method
  144. :ref:`String<class_String>` **_get_output_port_name** **(** :ref:`int<class_int>` port **)** |virtual| |const|
  145. 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>`.
  146. Defining this method is **optional**, but recommended. If not overridden, output ports are named as ``"out" + str(port)``.
  147. .. rst-class:: classref-item-separator
  148. ----
  149. .. _class_VisualShaderNodeCustom_method__get_output_port_type:
  150. .. rst-class:: classref-method
  151. :ref:`PortType<enum_VisualShaderNode_PortType>` **_get_output_port_type** **(** :ref:`int<class_int>` port **)** |virtual| |const|
  152. 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).
  153. 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.
  154. .. rst-class:: classref-item-separator
  155. ----
  156. .. _class_VisualShaderNodeCustom_method__get_return_icon_type:
  157. .. rst-class:: classref-method
  158. :ref:`PortType<enum_VisualShaderNode_PortType>` **_get_return_icon_type** **(** **)** |virtual| |const|
  159. Override this method to define the return icon of the associated custom node in the Visual Shader Editor's members dialog.
  160. Defining this method is **optional**. If not overridden, no return icon is shown.
  161. .. rst-class:: classref-item-separator
  162. ----
  163. .. _class_VisualShaderNodeCustom_method__is_available:
  164. .. rst-class:: classref-method
  165. :ref:`bool<class_bool>` **_is_available** **(** :ref:`Mode<enum_Shader_Mode>` mode, :ref:`Type<enum_VisualShader_Type>` type **)** |virtual| |const|
  166. 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>`).
  167. Defining this method is **optional**. If not overridden, it's ``true``.
  168. .. rst-class:: classref-item-separator
  169. ----
  170. .. _class_VisualShaderNodeCustom_method__is_highend:
  171. .. rst-class:: classref-method
  172. :ref:`bool<class_bool>` **_is_highend** **(** **)** |virtual| |const|
  173. Override this method to enable high-end mark in the Visual Shader Editor's members dialog.
  174. Defining this method is **optional**. If not overridden, it's ``false``.
  175. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  176. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  177. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  178. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  179. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  180. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`