class_shader.rst 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.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:`Reference<class_Reference>` **<** :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:`../tutorials/shaders/index`
  17. - :ref:`doc_introduction_to_shaders`
  18. Properties
  19. ----------
  20. +-----------------------------+-----------------------------------------+--------+
  21. | :ref:`String<class_String>` | :ref:`code<class_Shader_property_code>` | ``""`` |
  22. +-----------------------------+-----------------------------------------+--------+
  23. Methods
  24. -------
  25. +-----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`Texture2D<class_Texture2D>` | :ref:`get_default_texture_param<class_Shader_method_get_default_texture_param>` **(** :ref:`StringName<class_StringName>` param **)** const |
  27. +-----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`Mode<enum_Shader_Mode>` | :ref:`get_mode<class_Shader_method_get_mode>` **(** **)** const |
  29. +-----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`bool<class_bool>` | :ref:`has_param<class_Shader_method_has_param>` **(** :ref:`StringName<class_StringName>` name **)** const |
  31. +-----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | void | :ref:`set_default_texture_param<class_Shader_method_set_default_texture_param>` **(** :ref:`StringName<class_StringName>` param, :ref:`Texture2D<class_Texture2D>` texture **)** |
  33. +-----------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. Enumerations
  35. ------------
  36. .. _enum_Shader_Mode:
  37. .. _class_Shader_constant_MODE_SPATIAL:
  38. .. _class_Shader_constant_MODE_CANVAS_ITEM:
  39. .. _class_Shader_constant_MODE_PARTICLES:
  40. .. _class_Shader_constant_MODE_SKY:
  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. Property Descriptions
  47. ---------------------
  48. .. _class_Shader_property_code:
  49. - :ref:`String<class_String>` **code**
  50. +-----------+-----------------+
  51. | *Default* | ``""`` |
  52. +-----------+-----------------+
  53. | *Setter* | set_code(value) |
  54. +-----------+-----------------+
  55. | *Getter* | get_code() |
  56. +-----------+-----------------+
  57. Returns the shader's code as the user has written it, not the full generated code used internally.
  58. Method Descriptions
  59. -------------------
  60. .. _class_Shader_method_get_default_texture_param:
  61. - :ref:`Texture2D<class_Texture2D>` **get_default_texture_param** **(** :ref:`StringName<class_StringName>` param **)** const
  62. Returns the texture that is set as default for the specified parameter.
  63. **Note:** ``param`` must match the name of the uniform in the code exactly.
  64. ----
  65. .. _class_Shader_method_get_mode:
  66. - :ref:`Mode<enum_Shader_Mode>` **get_mode** **(** **)** const
  67. 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>`.
  68. ----
  69. .. _class_Shader_method_has_param:
  70. - :ref:`bool<class_bool>` **has_param** **(** :ref:`StringName<class_StringName>` name **)** const
  71. Returns ``true`` if the shader has this param defined as a uniform in its code.
  72. **Note:** ``param`` must match the name of the uniform in the code exactly.
  73. ----
  74. .. _class_Shader_method_set_default_texture_param:
  75. - void **set_default_texture_param** **(** :ref:`StringName<class_StringName>` param, :ref:`Texture2D<class_Texture2D>` texture **)**
  76. 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>`.
  77. **Note:** ``param`` must match the name of the uniform in the code exactly.