Files
godot-docs/classes/class_shader.rst
2025-06-07 03:33:02 +00:00

228 lines
9.9 KiB
ReStructuredText

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Shader.xml.
.. _class_Shader:
Shader
======
**Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
**Inherited By:** :ref:`VisualShader<class_VisualShader>`
A shader implemented in the Godot shading language.
.. rst-class:: classref-introduction-group
Description
-----------
A custom shader program implemented in the Godot shading language, saved with the ``.gdshader`` extension.
This class is used by a :ref:`ShaderMaterial<class_ShaderMaterial>` and allows you to write your own custom behavior for rendering visual items or updating particle information. For a detailed explanation and usage, please see the tutorials linked below.
.. rst-class:: classref-introduction-group
Tutorials
---------
- :doc:`Shaders documentation index <../tutorials/shaders/index>`
.. rst-class:: classref-reftable-group
Properties
----------
.. table::
:widths: auto
+-----------------------------+-----------------------------------------+--------+
| :ref:`String<class_String>` | :ref:`code<class_Shader_property_code>` | ``""`` |
+-----------------------------+-----------------------------------------+--------+
.. rst-class:: classref-reftable-group
Methods
-------
.. table::
:widths: auto
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Texture<class_Texture>` | :ref:`get_default_texture_parameter<class_Shader_method_get_default_texture_parameter>`\ (\ name\: :ref:`StringName<class_StringName>`, index\: :ref:`int<class_int>` = 0\ ) |const| |
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Mode<enum_Shader_Mode>` | :ref:`get_mode<class_Shader_method_get_mode>`\ (\ ) |const| |
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Array<class_Array>` | :ref:`get_shader_uniform_list<class_Shader_method_get_shader_uniform_list>`\ (\ get_groups\: :ref:`bool<class_bool>` = false\ ) |
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`inspect_native_shader_code<class_Shader_method_inspect_native_shader_code>`\ (\ ) |
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_default_texture_parameter<class_Shader_method_set_default_texture_parameter>`\ (\ name\: :ref:`StringName<class_StringName>`, texture\: :ref:`Texture<class_Texture>`, index\: :ref:`int<class_int>` = 0\ ) |
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Enumerations
------------
.. _enum_Shader_Mode:
.. rst-class:: classref-enumeration
enum **Mode**: :ref:`🔗<enum_Shader_Mode>`
.. _class_Shader_constant_MODE_SPATIAL:
.. rst-class:: classref-enumeration-constant
:ref:`Mode<enum_Shader_Mode>` **MODE_SPATIAL** = ``0``
Mode used to draw all 3D objects.
.. _class_Shader_constant_MODE_CANVAS_ITEM:
.. rst-class:: classref-enumeration-constant
:ref:`Mode<enum_Shader_Mode>` **MODE_CANVAS_ITEM** = ``1``
Mode used to draw all 2D objects.
.. _class_Shader_constant_MODE_PARTICLES:
.. rst-class:: classref-enumeration-constant
:ref:`Mode<enum_Shader_Mode>` **MODE_PARTICLES** = ``2``
Mode used to calculate particle information on a per-particle basis. Not used for drawing.
.. _class_Shader_constant_MODE_SKY:
.. rst-class:: classref-enumeration-constant
:ref:`Mode<enum_Shader_Mode>` **MODE_SKY** = ``3``
Mode used for drawing skies. Only works with shaders attached to :ref:`Sky<class_Sky>` objects.
.. _class_Shader_constant_MODE_FOG:
.. rst-class:: classref-enumeration-constant
:ref:`Mode<enum_Shader_Mode>` **MODE_FOG** = ``4``
Mode used for setting the color and density of volumetric fog effect.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Property Descriptions
---------------------
.. _class_Shader_property_code:
.. rst-class:: classref-property
:ref:`String<class_String>` **code** = ``""`` :ref:`🔗<class_Shader_property_code>`
.. rst-class:: classref-property-setget
- |void| **set_code**\ (\ value\: :ref:`String<class_String>`\ )
- :ref:`String<class_String>` **get_code**\ (\ )
Returns the shader's code as the user has written it, not the full generated code used internally.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Method Descriptions
-------------------
.. _class_Shader_method_get_default_texture_parameter:
.. rst-class:: classref-method
:ref:`Texture<class_Texture>` **get_default_texture_parameter**\ (\ name\: :ref:`StringName<class_StringName>`, index\: :ref:`int<class_int>` = 0\ ) |const| :ref:`🔗<class_Shader_method_get_default_texture_parameter>`
Returns the texture that is set as default for the specified parameter.
\ **Note:** ``name`` must match the name of the uniform in the code exactly.
\ **Note:** If the sampler array is used use ``index`` to access the specified texture.
.. rst-class:: classref-item-separator
----
.. _class_Shader_method_get_mode:
.. rst-class:: classref-method
:ref:`Mode<enum_Shader_Mode>` **get_mode**\ (\ ) |const| :ref:`🔗<class_Shader_method_get_mode>`
Returns the shader mode for the shader.
.. rst-class:: classref-item-separator
----
.. _class_Shader_method_get_shader_uniform_list:
.. rst-class:: classref-method
:ref:`Array<class_Array>` **get_shader_uniform_list**\ (\ get_groups\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_Shader_method_get_shader_uniform_list>`
Returns 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>`.
If argument ``get_groups`` is ``true``, parameter grouping hints are also included in the list.
.. rst-class:: classref-item-separator
----
.. _class_Shader_method_inspect_native_shader_code:
.. rst-class:: classref-method
|void| **inspect_native_shader_code**\ (\ ) :ref:`🔗<class_Shader_method_inspect_native_shader_code>`
Only available when running in the editor. Opens a popup that visualizes the generated shader code, including all variants and internal shader code. See also :ref:`Material.inspect_native_shader_code()<class_Material_method_inspect_native_shader_code>`.
.. rst-class:: classref-item-separator
----
.. _class_Shader_method_set_default_texture_parameter:
.. rst-class:: classref-method
|void| **set_default_texture_parameter**\ (\ name\: :ref:`StringName<class_StringName>`, texture\: :ref:`Texture<class_Texture>`, index\: :ref:`int<class_int>` = 0\ ) :ref:`🔗<class_Shader_method_set_default_texture_parameter>`
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>`.
\ **Note:** ``name`` must match the name of the uniform in the code exactly.
\ **Note:** If the sampler array is used use ``index`` to access the specified texture.
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
.. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
.. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
.. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
.. |void| replace:: :abbr:`void (No return value.)`