class_shader.rst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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/shading/index`
  17. - :doc:`../tutorials/shading/your_first_shader/what_are_shaders`
  18. Properties
  19. ----------
  20. +-----------------------------+-------------------------------------------------------------+--------+
  21. | :ref:`String<class_String>` | :ref:`code<class_Shader_property_code>` | ``""`` |
  22. +-----------------------------+-------------------------------------------------------------+--------+
  23. | :ref:`String<class_String>` | :ref:`custom_defines<class_Shader_property_custom_defines>` | ``""`` |
  24. +-----------------------------+-------------------------------------------------------------+--------+
  25. Methods
  26. -------
  27. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`Texture<class_Texture>` | :ref:`get_default_texture_param<class_Shader_method_get_default_texture_param>` **(** :ref:`String<class_String>` param **)** |const| |
  29. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Mode<enum_Shader_Mode>` | :ref:`get_mode<class_Shader_method_get_mode>` **(** **)** |const| |
  31. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`bool<class_bool>` | :ref:`has_param<class_Shader_method_has_param>` **(** :ref:`String<class_String>` name **)** |const| |
  33. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | void | :ref:`set_default_texture_param<class_Shader_method_set_default_texture_param>` **(** :ref:`String<class_String>` param, :ref:`Texture<class_Texture>` texture **)** |
  35. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. Enumerations
  37. ------------
  38. .. _enum_Shader_Mode:
  39. .. _class_Shader_constant_MODE_SPATIAL:
  40. .. _class_Shader_constant_MODE_CANVAS_ITEM:
  41. .. _class_Shader_constant_MODE_PARTICLES:
  42. enum **Mode**:
  43. - **MODE_SPATIAL** = **0** --- Mode used to draw all 3D objects.
  44. - **MODE_CANVAS_ITEM** = **1** --- Mode used to draw all 2D objects.
  45. - **MODE_PARTICLES** = **2** --- Mode used to calculate particle information on a per-particle basis. Not used for drawing.
  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. ----
  59. .. _class_Shader_property_custom_defines:
  60. - :ref:`String<class_String>` **custom_defines**
  61. +-----------+---------------------------+
  62. | *Default* | ``""`` |
  63. +-----------+---------------------------+
  64. | *Setter* | set_custom_defines(value) |
  65. +-----------+---------------------------+
  66. | *Getter* | get_custom_defines() |
  67. +-----------+---------------------------+
  68. Returns the shader's custom defines. Custom defines can be used in Godot to add GLSL preprocessor directives (e.g: extensions) required for the shader logic.
  69. **Note:** Custom defines are not validated by the Godot shader parser, so care should be taken when using them.
  70. Method Descriptions
  71. -------------------
  72. .. _class_Shader_method_get_default_texture_param:
  73. - :ref:`Texture<class_Texture>` **get_default_texture_param** **(** :ref:`String<class_String>` param **)** |const|
  74. Returns the texture that is set as default for the specified parameter.
  75. **Note:** ``param`` must match the name of the uniform in the code exactly.
  76. ----
  77. .. _class_Shader_method_get_mode:
  78. - :ref:`Mode<enum_Shader_Mode>` **get_mode** **(** **)** |const|
  79. 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>`.
  80. ----
  81. .. _class_Shader_method_has_param:
  82. - :ref:`bool<class_bool>` **has_param** **(** :ref:`String<class_String>` name **)** |const|
  83. Returns ``true`` if the shader has this param defined as a uniform in its code.
  84. **Note:** ``param`` must match the name of the uniform in the code exactly.
  85. ----
  86. .. _class_Shader_method_set_default_texture_param:
  87. - void **set_default_texture_param** **(** :ref:`String<class_String>` param, :ref:`Texture<class_Texture>` texture **)**
  88. 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>`.
  89. **Note:** ``param`` must match the name of the uniform in the code exactly.
  90. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  91. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  92. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`