class_visualshader.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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 VisualShader.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_VisualShader:
  6. VisualShader
  7. ============
  8. **Inherits:** :ref:`Shader<class_Shader>` **<** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  9. A custom shader program with a visual editor.
  10. Description
  11. -----------
  12. This class allows you to define a custom shader program that can be used for various materials to render objects.
  13. The visual shader editor creates the shader.
  14. Properties
  15. ----------
  16. +-------------------------------------+-------------------------------------------------------------------+-------------------+
  17. | :ref:`Dictionary<class_Dictionary>` | :ref:`engine_version<class_VisualShader_property_engine_version>` | ``{}`` |
  18. +-------------------------------------+-------------------------------------------------------------------+-------------------+
  19. | :ref:`Vector2<class_Vector2>` | :ref:`graph_offset<class_VisualShader_property_graph_offset>` | ``Vector2(0, 0)`` |
  20. +-------------------------------------+-------------------------------------------------------------------+-------------------+
  21. Methods
  22. -------
  23. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | void | :ref:`add_node<class_VisualShader_method_add_node>` **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`VisualShaderNode<class_VisualShaderNode>` node, :ref:`Vector2<class_Vector2>` position, :ref:`int<class_int>` id **)** |
  25. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | void | :ref:`add_varying<class_VisualShader_method_add_varying>` **(** :ref:`String<class_String>` name, :ref:`VaryingMode<enum_VisualShader_VaryingMode>` mode, :ref:`VaryingType<enum_VisualShader_VaryingType>` type **)** |
  27. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`bool<class_bool>` | :ref:`can_connect_nodes<class_VisualShader_method_can_connect_nodes>` **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` from_node, :ref:`int<class_int>` from_port, :ref:`int<class_int>` to_node, :ref:`int<class_int>` to_port **)** |const| |
  29. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`connect_nodes<class_VisualShader_method_connect_nodes>` **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` from_node, :ref:`int<class_int>` from_port, :ref:`int<class_int>` to_node, :ref:`int<class_int>` to_port **)** |
  31. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | void | :ref:`connect_nodes_forced<class_VisualShader_method_connect_nodes_forced>` **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` from_node, :ref:`int<class_int>` from_port, :ref:`int<class_int>` to_node, :ref:`int<class_int>` to_port **)** |
  33. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | void | :ref:`disconnect_nodes<class_VisualShader_method_disconnect_nodes>` **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` from_node, :ref:`int<class_int>` from_port, :ref:`int<class_int>` to_node, :ref:`int<class_int>` to_port **)** |
  35. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`VisualShaderNode<class_VisualShaderNode>` | :ref:`get_node<class_VisualShader_method_get_node>` **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` id **)** |const| |
  37. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Array<class_Array>` | :ref:`get_node_connections<class_VisualShader_method_get_node_connections>` **(** :ref:`Type<enum_VisualShader_Type>` type **)** |const| |
  39. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`PackedInt32Array<class_PackedInt32Array>` | :ref:`get_node_list<class_VisualShader_method_get_node_list>` **(** :ref:`Type<enum_VisualShader_Type>` type **)** |const| |
  41. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Vector2<class_Vector2>` | :ref:`get_node_position<class_VisualShader_method_get_node_position>` **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` id **)** |const| |
  43. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`int<class_int>` | :ref:`get_valid_node_id<class_VisualShader_method_get_valid_node_id>` **(** :ref:`Type<enum_VisualShader_Type>` type **)** |const| |
  45. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`bool<class_bool>` | :ref:`has_varying<class_VisualShader_method_has_varying>` **(** :ref:`String<class_String>` name **)** |const| |
  47. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`bool<class_bool>` | :ref:`is_node_connection<class_VisualShader_method_is_node_connection>` **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` from_node, :ref:`int<class_int>` from_port, :ref:`int<class_int>` to_node, :ref:`int<class_int>` to_port **)** |const| |
  49. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`remove_node<class_VisualShader_method_remove_node>` **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` id **)** |
  51. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | void | :ref:`remove_varying<class_VisualShader_method_remove_varying>` **(** :ref:`String<class_String>` name **)** |
  53. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | void | :ref:`replace_node<class_VisualShader_method_replace_node>` **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` id, :ref:`StringName<class_StringName>` new_class **)** |
  55. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | void | :ref:`set_mode<class_VisualShader_method_set_mode>` **(** :ref:`Mode<enum_Shader_Mode>` mode **)** |
  57. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`set_node_position<class_VisualShader_method_set_node_position>` **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` id, :ref:`Vector2<class_Vector2>` position **)** |
  59. +-------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. Enumerations
  61. ------------
  62. .. _enum_VisualShader_Type:
  63. .. _class_VisualShader_constant_TYPE_VERTEX:
  64. .. _class_VisualShader_constant_TYPE_FRAGMENT:
  65. .. _class_VisualShader_constant_TYPE_LIGHT:
  66. .. _class_VisualShader_constant_TYPE_START:
  67. .. _class_VisualShader_constant_TYPE_PROCESS:
  68. .. _class_VisualShader_constant_TYPE_COLLIDE:
  69. .. _class_VisualShader_constant_TYPE_START_CUSTOM:
  70. .. _class_VisualShader_constant_TYPE_PROCESS_CUSTOM:
  71. .. _class_VisualShader_constant_TYPE_SKY:
  72. .. _class_VisualShader_constant_TYPE_FOG:
  73. .. _class_VisualShader_constant_TYPE_MAX:
  74. enum **Type**:
  75. - **TYPE_VERTEX** = **0** --- A vertex shader, operating on vertices.
  76. - **TYPE_FRAGMENT** = **1** --- A fragment shader, operating on fragments (pixels).
  77. - **TYPE_LIGHT** = **2** --- A shader for light calculations.
  78. - **TYPE_START** = **3**
  79. - **TYPE_PROCESS** = **4**
  80. - **TYPE_COLLIDE** = **5**
  81. - **TYPE_START_CUSTOM** = **6**
  82. - **TYPE_PROCESS_CUSTOM** = **7**
  83. - **TYPE_SKY** = **8**
  84. - **TYPE_FOG** = **9** --- A compute shader that runs for each froxel of the volumetric fog map.
  85. - **TYPE_MAX** = **10** --- Represents the size of the :ref:`Type<enum_VisualShader_Type>` enum.
  86. ----
  87. .. _enum_VisualShader_VaryingMode:
  88. .. _class_VisualShader_constant_VARYING_MODE_VERTEX_TO_FRAG_LIGHT:
  89. .. _class_VisualShader_constant_VARYING_MODE_FRAG_TO_LIGHT:
  90. .. _class_VisualShader_constant_VARYING_MODE_MAX:
  91. enum **VaryingMode**:
  92. - **VARYING_MODE_VERTEX_TO_FRAG_LIGHT** = **0**
  93. - **VARYING_MODE_FRAG_TO_LIGHT** = **1**
  94. - **VARYING_MODE_MAX** = **2**
  95. ----
  96. .. _enum_VisualShader_VaryingType:
  97. .. _class_VisualShader_constant_VARYING_TYPE_FLOAT:
  98. .. _class_VisualShader_constant_VARYING_TYPE_VECTOR_2D:
  99. .. _class_VisualShader_constant_VARYING_TYPE_VECTOR_3D:
  100. .. _class_VisualShader_constant_VARYING_TYPE_COLOR:
  101. .. _class_VisualShader_constant_VARYING_TYPE_TRANSFORM:
  102. .. _class_VisualShader_constant_VARYING_TYPE_MAX:
  103. enum **VaryingType**:
  104. - **VARYING_TYPE_FLOAT** = **0**
  105. - **VARYING_TYPE_VECTOR_2D** = **1**
  106. - **VARYING_TYPE_VECTOR_3D** = **2**
  107. - **VARYING_TYPE_COLOR** = **3**
  108. - **VARYING_TYPE_TRANSFORM** = **4**
  109. - **VARYING_TYPE_MAX** = **5**
  110. Constants
  111. ---------
  112. .. _class_VisualShader_constant_NODE_ID_INVALID:
  113. .. _class_VisualShader_constant_NODE_ID_OUTPUT:
  114. - **NODE_ID_INVALID** = **-1**
  115. - **NODE_ID_OUTPUT** = **0**
  116. Property Descriptions
  117. ---------------------
  118. .. _class_VisualShader_property_engine_version:
  119. - :ref:`Dictionary<class_Dictionary>` **engine_version**
  120. +-----------+---------------------------+
  121. | *Default* | ``{}`` |
  122. +-----------+---------------------------+
  123. | *Setter* | set_engine_version(value) |
  124. +-----------+---------------------------+
  125. | *Getter* | get_engine_version() |
  126. +-----------+---------------------------+
  127. The Godot version this ``VisualShader`` was designed for, in the form of a :ref:`Dictionary<class_Dictionary>` with ``major`` and ``minor`` keys with integer values. Example: ``{"major": 4, "minor": 0}``\
  128. This is used by the editor to convert visual shaders from older Godot versions.
  129. ----
  130. .. _class_VisualShader_property_graph_offset:
  131. - :ref:`Vector2<class_Vector2>` **graph_offset**
  132. +-----------+-------------------------+
  133. | *Default* | ``Vector2(0, 0)`` |
  134. +-----------+-------------------------+
  135. | *Setter* | set_graph_offset(value) |
  136. +-----------+-------------------------+
  137. | *Getter* | get_graph_offset() |
  138. +-----------+-------------------------+
  139. The offset vector of the whole graph.
  140. Method Descriptions
  141. -------------------
  142. .. _class_VisualShader_method_add_node:
  143. - void **add_node** **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`VisualShaderNode<class_VisualShaderNode>` node, :ref:`Vector2<class_Vector2>` position, :ref:`int<class_int>` id **)**
  144. Adds the specified node to the shader.
  145. ----
  146. .. _class_VisualShader_method_add_varying:
  147. - void **add_varying** **(** :ref:`String<class_String>` name, :ref:`VaryingMode<enum_VisualShader_VaryingMode>` mode, :ref:`VaryingType<enum_VisualShader_VaryingType>` type **)**
  148. ----
  149. .. _class_VisualShader_method_can_connect_nodes:
  150. - :ref:`bool<class_bool>` **can_connect_nodes** **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` from_node, :ref:`int<class_int>` from_port, :ref:`int<class_int>` to_node, :ref:`int<class_int>` to_port **)** |const|
  151. Returns ``true`` if the specified nodes and ports can be connected together.
  152. ----
  153. .. _class_VisualShader_method_connect_nodes:
  154. - :ref:`Error<enum_@GlobalScope_Error>` **connect_nodes** **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` from_node, :ref:`int<class_int>` from_port, :ref:`int<class_int>` to_node, :ref:`int<class_int>` to_port **)**
  155. Connects the specified nodes and ports.
  156. ----
  157. .. _class_VisualShader_method_connect_nodes_forced:
  158. - void **connect_nodes_forced** **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` from_node, :ref:`int<class_int>` from_port, :ref:`int<class_int>` to_node, :ref:`int<class_int>` to_port **)**
  159. Connects the specified nodes and ports, even if they can't be connected. Such connection is invalid and will not function properly.
  160. ----
  161. .. _class_VisualShader_method_disconnect_nodes:
  162. - void **disconnect_nodes** **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` from_node, :ref:`int<class_int>` from_port, :ref:`int<class_int>` to_node, :ref:`int<class_int>` to_port **)**
  163. Connects the specified nodes and ports.
  164. ----
  165. .. _class_VisualShader_method_get_node:
  166. - :ref:`VisualShaderNode<class_VisualShaderNode>` **get_node** **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` id **)** |const|
  167. Returns the shader node instance with specified ``type`` and ``id``.
  168. ----
  169. .. _class_VisualShader_method_get_node_connections:
  170. - :ref:`Array<class_Array>` **get_node_connections** **(** :ref:`Type<enum_VisualShader_Type>` type **)** |const|
  171. Returns the list of connected nodes with the specified type.
  172. ----
  173. .. _class_VisualShader_method_get_node_list:
  174. - :ref:`PackedInt32Array<class_PackedInt32Array>` **get_node_list** **(** :ref:`Type<enum_VisualShader_Type>` type **)** |const|
  175. Returns the list of all nodes in the shader with the specified type.
  176. ----
  177. .. _class_VisualShader_method_get_node_position:
  178. - :ref:`Vector2<class_Vector2>` **get_node_position** **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` id **)** |const|
  179. Returns the position of the specified node within the shader graph.
  180. ----
  181. .. _class_VisualShader_method_get_valid_node_id:
  182. - :ref:`int<class_int>` **get_valid_node_id** **(** :ref:`Type<enum_VisualShader_Type>` type **)** |const|
  183. ----
  184. .. _class_VisualShader_method_has_varying:
  185. - :ref:`bool<class_bool>` **has_varying** **(** :ref:`String<class_String>` name **)** |const|
  186. ----
  187. .. _class_VisualShader_method_is_node_connection:
  188. - :ref:`bool<class_bool>` **is_node_connection** **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` from_node, :ref:`int<class_int>` from_port, :ref:`int<class_int>` to_node, :ref:`int<class_int>` to_port **)** |const|
  189. Returns ``true`` if the specified node and port connection exist.
  190. ----
  191. .. _class_VisualShader_method_remove_node:
  192. - void **remove_node** **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` id **)**
  193. Removes the specified node from the shader.
  194. ----
  195. .. _class_VisualShader_method_remove_varying:
  196. - void **remove_varying** **(** :ref:`String<class_String>` name **)**
  197. ----
  198. .. _class_VisualShader_method_replace_node:
  199. - void **replace_node** **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` id, :ref:`StringName<class_StringName>` new_class **)**
  200. Replaces the specified node with a node of new class type.
  201. ----
  202. .. _class_VisualShader_method_set_mode:
  203. - void **set_mode** **(** :ref:`Mode<enum_Shader_Mode>` mode **)**
  204. Sets the mode of this shader.
  205. ----
  206. .. _class_VisualShader_method_set_node_position:
  207. - void **set_node_position** **(** :ref:`Type<enum_VisualShader_Type>` type, :ref:`int<class_int>` id, :ref:`Vector2<class_Vector2>` position **)**
  208. Sets the position of the specified node.
  209. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  210. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  211. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  212. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  213. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  214. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`