class_shader.rst 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 Shader.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Shader:
  6. Shader
  7. ======
  8. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`VisualShader<class_VisualShader>`
  10. A custom shader program.
  11. Description
  12. -----------
  13. 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.
  14. Tutorials
  15. ---------
  16. - :doc:`Shaders documentation index <../tutorials/shaders/index>`
  17. Properties
  18. ----------
  19. +-----------------------------+-----------------------------------------+--------+
  20. | :ref:`String<class_String>` | :ref:`code<class_Shader_property_code>` | ``""`` |
  21. +-----------------------------+-----------------------------------------+--------+
  22. Methods
  23. -------
  24. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`Texture2D<class_Texture2D>` | :ref:`get_default_texture_param<class_Shader_method_get_default_texture_param>` **(** :ref:`StringName<class_StringName>` param, :ref:`int<class_int>` index=0 **)** |const| |
  26. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`Mode<enum_Shader_Mode>` | :ref:`get_mode<class_Shader_method_get_mode>` **(** **)** |const| |
  28. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`bool<class_bool>` | :ref:`has_param<class_Shader_method_has_param>` **(** :ref:`StringName<class_StringName>` name **)** |const| |
  30. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | void | :ref:`set_default_texture_param<class_Shader_method_set_default_texture_param>` **(** :ref:`StringName<class_StringName>` param, :ref:`Texture2D<class_Texture2D>` texture, :ref:`int<class_int>` index=0 **)** |
  32. +-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. Enumerations
  34. ------------
  35. .. _enum_Shader_Mode:
  36. .. _class_Shader_constant_MODE_SPATIAL:
  37. .. _class_Shader_constant_MODE_CANVAS_ITEM:
  38. .. _class_Shader_constant_MODE_PARTICLES:
  39. .. _class_Shader_constant_MODE_SKY:
  40. .. _class_Shader_constant_MODE_FOG:
  41. enum **Mode**:
  42. - **MODE_SPATIAL** = **0** --- Mode used to draw all 3D objects.
  43. - **MODE_CANVAS_ITEM** = **1** --- Mode used to draw all 2D objects.
  44. - **MODE_PARTICLES** = **2** --- Mode used to calculate particle information on a per-particle basis. Not used for drawing.
  45. - **MODE_SKY** = **3** --- Mode used for drawing skies. Only works with shaders attached to :ref:`Sky<class_Sky>` objects.
  46. - **MODE_FOG** = **4** --- Mode used for setting the color and density of volumetric fog effect.
  47. Property Descriptions
  48. ---------------------
  49. .. _class_Shader_property_code:
  50. - :ref:`String<class_String>` **code**
  51. +-----------+-----------------+
  52. | *Default* | ``""`` |
  53. +-----------+-----------------+
  54. | *Setter* | set_code(value) |
  55. +-----------+-----------------+
  56. | *Getter* | get_code() |
  57. +-----------+-----------------+
  58. Returns the shader's code as the user has written it, not the full generated code used internally.
  59. Method Descriptions
  60. -------------------
  61. .. _class_Shader_method_get_default_texture_param:
  62. - :ref:`Texture2D<class_Texture2D>` **get_default_texture_param** **(** :ref:`StringName<class_StringName>` param, :ref:`int<class_int>` index=0 **)** |const|
  63. Returns the texture that is set as default for the specified parameter.
  64. \ **Note:** ``param`` must match the name of the uniform in the code exactly.
  65. \ **Note:** If the sampler array is used use ``index`` to access the specified texture.
  66. ----
  67. .. _class_Shader_method_get_mode:
  68. - :ref:`Mode<enum_Shader_Mode>` **get_mode** **(** **)** |const|
  69. 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>`.
  70. ----
  71. .. _class_Shader_method_has_param:
  72. - :ref:`bool<class_bool>` **has_param** **(** :ref:`StringName<class_StringName>` name **)** |const|
  73. Returns ``true`` if the shader has this param defined as a uniform in its code.
  74. \ **Note:** ``param`` must match the name of the uniform in the code exactly.
  75. ----
  76. .. _class_Shader_method_set_default_texture_param:
  77. - void **set_default_texture_param** **(** :ref:`StringName<class_StringName>` param, :ref:`Texture2D<class_Texture2D>` texture, :ref:`int<class_int>` index=0 **)**
  78. 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>`.
  79. \ **Note:** ``param`` must match the name of the uniform in the code exactly.
  80. \ **Note:** If the sampler array is used use ``index`` to access the specified texture.
  81. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  82. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  83. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  84. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  85. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  86. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`