class_visualshadernodecustom.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.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. Virtual class to define custom :ref:`VisualShaderNode<class_VisualShaderNode>`\ s for use in the Visual Shader Editor.
  10. Description
  11. -----------
  12. 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.
  13. 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:
  14. ::
  15. tool
  16. extends VisualShaderNodeCustom
  17. class_name VisualShaderNodeNoise
  18. Tutorials
  19. ---------
  20. - :doc:`../tutorials/plugins/editor/visual_shader_plugins`
  21. Methods
  22. -------
  23. +-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`String<class_String>` | :ref:`_get_category<class_VisualShaderNodeCustom_method__get_category>` **(** **)** |virtual| |
  25. +-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :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| |
  27. +-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`String<class_String>` | :ref:`_get_description<class_VisualShaderNodeCustom_method__get_description>` **(** **)** |virtual| |
  29. +-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`String<class_String>` | :ref:`_get_global_code<class_VisualShaderNodeCustom_method__get_global_code>` **(** :ref:`int<class_int>` mode **)** |virtual| |
  31. +-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`int<class_int>` | :ref:`_get_input_port_count<class_VisualShaderNodeCustom_method__get_input_port_count>` **(** **)** |virtual| |
  33. +-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`String<class_String>` | :ref:`_get_input_port_name<class_VisualShaderNodeCustom_method__get_input_port_name>` **(** :ref:`int<class_int>` port **)** |virtual| |
  35. +-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`int<class_int>` | :ref:`_get_input_port_type<class_VisualShaderNodeCustom_method__get_input_port_type>` **(** :ref:`int<class_int>` port **)** |virtual| |
  37. +-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`String<class_String>` | :ref:`_get_name<class_VisualShaderNodeCustom_method__get_name>` **(** **)** |virtual| |
  39. +-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`_get_output_port_count<class_VisualShaderNodeCustom_method__get_output_port_count>` **(** **)** |virtual| |
  41. +-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`String<class_String>` | :ref:`_get_output_port_name<class_VisualShaderNodeCustom_method__get_output_port_name>` **(** :ref:`int<class_int>` port **)** |virtual| |
  43. +-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`int<class_int>` | :ref:`_get_output_port_type<class_VisualShaderNodeCustom_method__get_output_port_type>` **(** :ref:`int<class_int>` port **)** |virtual| |
  45. +-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`int<class_int>` | :ref:`_get_return_icon_type<class_VisualShaderNodeCustom_method__get_return_icon_type>` **(** **)** |virtual| |
  47. +-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`String<class_String>` | :ref:`_get_subcategory<class_VisualShaderNodeCustom_method__get_subcategory>` **(** **)** |virtual| |
  49. +-----------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. Method Descriptions
  51. -------------------
  52. .. _class_VisualShaderNodeCustom_method__get_category:
  53. - :ref:`String<class_String>` **_get_category** **(** **)** |virtual|
  54. Override this method to define the category of the associated custom node in the Visual Shader Editor's members dialog. The path may look like ``"MyGame/MyFunctions/Noise"``.
  55. Defining this method is **optional**. If not overridden, the node will be filed under the "Custom" category.
  56. ----
  57. .. _class_VisualShaderNodeCustom_method__get_code:
  58. - :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|
  59. 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).
  60. 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.
  61. The output ports can be assigned values in the shader code. For example, ``return output_vars[0] + " = " + input_vars[0] + ";"``.
  62. 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>`).
  63. Defining this method is **required**.
  64. ----
  65. .. _class_VisualShaderNodeCustom_method__get_description:
  66. - :ref:`String<class_String>` **_get_description** **(** **)** |virtual|
  67. Override this method to define the description of the associated custom node in the Visual Shader Editor's members dialog.
  68. Defining this method is **optional**.
  69. ----
  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. ----
  77. .. _class_VisualShaderNodeCustom_method__get_input_port_count:
  78. - :ref:`int<class_int>` **_get_input_port_count** **(** **)** |virtual|
  79. Override this method to define the amount of input ports of the associated custom node.
  80. Defining this method is **required**. If not overridden, the node has no input ports.
  81. ----
  82. .. _class_VisualShaderNodeCustom_method__get_input_port_name:
  83. - :ref:`String<class_String>` **_get_input_port_name** **(** :ref:`int<class_int>` port **)** |virtual|
  84. 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>`.
  85. Defining this method is **optional**, but recommended. If not overridden, input ports are named as ``"in" + str(port)``.
  86. ----
  87. .. _class_VisualShaderNodeCustom_method__get_input_port_type:
  88. - :ref:`int<class_int>` **_get_input_port_type** **(** :ref:`int<class_int>` port **)** |virtual|
  89. 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).
  90. 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.
  91. ----
  92. .. _class_VisualShaderNodeCustom_method__get_name:
  93. - :ref:`String<class_String>` **_get_name** **(** **)** |virtual|
  94. Override this method to define the name of the associated custom node in the Visual Shader Editor's members dialog and graph.
  95. Defining this method is **optional**, but recommended. If not overridden, the node will be named as "Unnamed".
  96. ----
  97. .. _class_VisualShaderNodeCustom_method__get_output_port_count:
  98. - :ref:`int<class_int>` **_get_output_port_count** **(** **)** |virtual|
  99. Override this method to define the amount of output ports of the associated custom node.
  100. Defining this method is **required**. If not overridden, the node has no output ports.
  101. ----
  102. .. _class_VisualShaderNodeCustom_method__get_output_port_name:
  103. - :ref:`String<class_String>` **_get_output_port_name** **(** :ref:`int<class_int>` port **)** |virtual|
  104. 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>`.
  105. Defining this method is **optional**, but recommended. If not overridden, output ports are named as ``"out" + str(port)``.
  106. ----
  107. .. _class_VisualShaderNodeCustom_method__get_output_port_type:
  108. - :ref:`int<class_int>` **_get_output_port_type** **(** :ref:`int<class_int>` port **)** |virtual|
  109. 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).
  110. 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.
  111. ----
  112. .. _class_VisualShaderNodeCustom_method__get_return_icon_type:
  113. - :ref:`int<class_int>` **_get_return_icon_type** **(** **)** |virtual|
  114. Override this method to define the return icon of the associated custom node in the Visual Shader Editor's members dialog.
  115. Defining this method is **optional**. If not overridden, no return icon is shown.
  116. ----
  117. .. _class_VisualShaderNodeCustom_method__get_subcategory:
  118. - :ref:`String<class_String>` **_get_subcategory** **(** **)** |virtual|
  119. Override this method to define the subcategory of the associated custom node in the Visual Shader Editor's members dialog.
  120. 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>`).
  121. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  122. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  123. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`