class_shader.rst 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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/Shader.xml.
  6. .. _class_Shader:
  7. Shader
  8. ======
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`VisualShader<class_VisualShader>`
  11. A custom shader program.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. This class allows you to define a custom shader program that can be used by a :ref:`ShaderMaterial<class_ShaderMaterial>`. Shaders allow you to write your own custom behavior for rendering objects or updating particle information. For a detailed explanation and usage, please see the tutorials linked below.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - :doc:`Shaders documentation index <../tutorials/shaders/index>`
  20. .. rst-class:: classref-reftable-group
  21. Properties
  22. ----------
  23. .. table::
  24. :widths: auto
  25. +-----------------------------+-----------------------------------------+--------+
  26. | :ref:`String<class_String>` | :ref:`code<class_Shader_property_code>` | ``""`` |
  27. +-----------------------------+-----------------------------------------+--------+
  28. .. rst-class:: classref-reftable-group
  29. Methods
  30. -------
  31. .. table::
  32. :widths: auto
  33. +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`Texture2D<class_Texture2D>` | :ref:`get_default_texture_parameter<class_Shader_method_get_default_texture_parameter>` **(** :ref:`StringName<class_StringName>` name, :ref:`int<class_int>` index=0 **)** |const| |
  35. +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`Mode<enum_Shader_Mode>` | :ref:`get_mode<class_Shader_method_get_mode>` **(** **)** |const| |
  37. +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Array<class_Array>` | :ref:`get_shader_uniform_list<class_Shader_method_get_shader_uniform_list>` **(** :ref:`bool<class_bool>` get_groups=false **)** |
  39. +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | void | :ref:`set_default_texture_parameter<class_Shader_method_set_default_texture_parameter>` **(** :ref:`StringName<class_StringName>` name, :ref:`Texture2D<class_Texture2D>` texture, :ref:`int<class_int>` index=0 **)** |
  41. +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. .. rst-class:: classref-section-separator
  43. ----
  44. .. rst-class:: classref-descriptions-group
  45. Enumerations
  46. ------------
  47. .. _enum_Shader_Mode:
  48. .. rst-class:: classref-enumeration
  49. enum **Mode**:
  50. .. _class_Shader_constant_MODE_SPATIAL:
  51. .. rst-class:: classref-enumeration-constant
  52. :ref:`Mode<enum_Shader_Mode>` **MODE_SPATIAL** = ``0``
  53. Mode used to draw all 3D objects.
  54. .. _class_Shader_constant_MODE_CANVAS_ITEM:
  55. .. rst-class:: classref-enumeration-constant
  56. :ref:`Mode<enum_Shader_Mode>` **MODE_CANVAS_ITEM** = ``1``
  57. Mode used to draw all 2D objects.
  58. .. _class_Shader_constant_MODE_PARTICLES:
  59. .. rst-class:: classref-enumeration-constant
  60. :ref:`Mode<enum_Shader_Mode>` **MODE_PARTICLES** = ``2``
  61. Mode used to calculate particle information on a per-particle basis. Not used for drawing.
  62. .. _class_Shader_constant_MODE_SKY:
  63. .. rst-class:: classref-enumeration-constant
  64. :ref:`Mode<enum_Shader_Mode>` **MODE_SKY** = ``3``
  65. Mode used for drawing skies. Only works with shaders attached to :ref:`Sky<class_Sky>` objects.
  66. .. _class_Shader_constant_MODE_FOG:
  67. .. rst-class:: classref-enumeration-constant
  68. :ref:`Mode<enum_Shader_Mode>` **MODE_FOG** = ``4``
  69. Mode used for setting the color and density of volumetric fog effect.
  70. .. rst-class:: classref-section-separator
  71. ----
  72. .. rst-class:: classref-descriptions-group
  73. Property Descriptions
  74. ---------------------
  75. .. _class_Shader_property_code:
  76. .. rst-class:: classref-property
  77. :ref:`String<class_String>` **code** = ``""``
  78. .. rst-class:: classref-property-setget
  79. - void **set_code** **(** :ref:`String<class_String>` value **)**
  80. - :ref:`String<class_String>` **get_code** **(** **)**
  81. Returns the shader's code as the user has written it, not the full generated code used internally.
  82. .. rst-class:: classref-section-separator
  83. ----
  84. .. rst-class:: classref-descriptions-group
  85. Method Descriptions
  86. -------------------
  87. .. _class_Shader_method_get_default_texture_parameter:
  88. .. rst-class:: classref-method
  89. :ref:`Texture2D<class_Texture2D>` **get_default_texture_parameter** **(** :ref:`StringName<class_StringName>` name, :ref:`int<class_int>` index=0 **)** |const|
  90. Returns the texture that is set as default for the specified parameter.
  91. \ **Note:** ``name`` must match the name of the uniform in the code exactly.
  92. \ **Note:** If the sampler array is used use ``index`` to access the specified texture.
  93. .. rst-class:: classref-item-separator
  94. ----
  95. .. _class_Shader_method_get_mode:
  96. .. rst-class:: classref-method
  97. :ref:`Mode<enum_Shader_Mode>` **get_mode** **(** **)** |const|
  98. Returns the shader mode for the shader, either :ref:`MODE_CANVAS_ITEM<class_Shader_constant_MODE_CANVAS_ITEM>`, :ref:`MODE_SPATIAL<class_Shader_constant_MODE_SPATIAL>` or :ref:`MODE_PARTICLES<class_Shader_constant_MODE_PARTICLES>`.
  99. .. rst-class:: classref-item-separator
  100. ----
  101. .. _class_Shader_method_get_shader_uniform_list:
  102. .. rst-class:: classref-method
  103. :ref:`Array<class_Array>` **get_shader_uniform_list** **(** :ref:`bool<class_bool>` get_groups=false **)**
  104. Get the list of shader uniforms that can be assigned to a :ref:`ShaderMaterial<class_ShaderMaterial>`, for use with :ref:`ShaderMaterial.set_shader_parameter<class_ShaderMaterial_method_set_shader_parameter>` and :ref:`ShaderMaterial.get_shader_parameter<class_ShaderMaterial_method_get_shader_parameter>`. The parameters returned are contained in dictionaries in a similar format to the ones returned by :ref:`Object.get_property_list<class_Object_method_get_property_list>`.
  105. If argument ``get_groups`` is true, parameter grouping hints will be provided.
  106. .. rst-class:: classref-item-separator
  107. ----
  108. .. _class_Shader_method_set_default_texture_parameter:
  109. .. rst-class:: classref-method
  110. void **set_default_texture_parameter** **(** :ref:`StringName<class_StringName>` name, :ref:`Texture2D<class_Texture2D>` texture, :ref:`int<class_int>` index=0 **)**
  111. Sets the default texture to be used with a texture uniform. The default is used if a texture is not set in the :ref:`ShaderMaterial<class_ShaderMaterial>`.
  112. \ **Note:** ``name`` must match the name of the uniform in the code exactly.
  113. \ **Note:** If the sampler array is used use ``index`` to access the specified texture.
  114. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  115. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  116. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  117. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  118. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  119. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`