class_compositoreffect.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/CompositorEffect.xml.
  6. .. _class_CompositorEffect:
  7. CompositorEffect
  8. ================
  9. **Experimental:** The implementation may change as more of the rendering internals are exposed over time.
  10. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  11. This resource allows for creating a custom rendering effect.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. This resource defines a custom rendering effect that can be applied to :ref:`Viewport<class_Viewport>`\ s through the viewports' :ref:`Environment<class_Environment>`. You can implement a callback that is called during rendering at a given stage of the rendering pipeline and allows you to insert additional passes. Note that this callback happens on the rendering thread. CompositorEffect is an abstract base class and must be extended to implement specific rendering logic.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - :doc:`The Compositor <../tutorials/rendering/compositor>`
  20. .. rst-class:: classref-reftable-group
  21. Properties
  22. ----------
  23. .. table::
  24. :widths: auto
  25. +---------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  26. | :ref:`bool<class_bool>` | :ref:`access_resolved_color<class_CompositorEffect_property_access_resolved_color>` |
  27. +---------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  28. | :ref:`bool<class_bool>` | :ref:`access_resolved_depth<class_CompositorEffect_property_access_resolved_depth>` |
  29. +---------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  30. | :ref:`EffectCallbackType<enum_CompositorEffect_EffectCallbackType>` | :ref:`effect_callback_type<class_CompositorEffect_property_effect_callback_type>` |
  31. +---------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  32. | :ref:`bool<class_bool>` | :ref:`enabled<class_CompositorEffect_property_enabled>` |
  33. +---------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  34. | :ref:`bool<class_bool>` | :ref:`needs_motion_vectors<class_CompositorEffect_property_needs_motion_vectors>` |
  35. +---------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  36. | :ref:`bool<class_bool>` | :ref:`needs_normal_roughness<class_CompositorEffect_property_needs_normal_roughness>` |
  37. +---------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  38. | :ref:`bool<class_bool>` | :ref:`needs_separate_specular<class_CompositorEffect_property_needs_separate_specular>` |
  39. +---------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  40. .. rst-class:: classref-reftable-group
  41. Methods
  42. -------
  43. .. table::
  44. :widths: auto
  45. +--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | |void| | :ref:`_render_callback<class_CompositorEffect_private_method__render_callback>`\ (\ effect_callback_type\: :ref:`int<class_int>`, render_data\: :ref:`RenderData<class_RenderData>`\ ) |virtual| |
  47. +--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. .. rst-class:: classref-section-separator
  49. ----
  50. .. rst-class:: classref-descriptions-group
  51. Enumerations
  52. ------------
  53. .. _enum_CompositorEffect_EffectCallbackType:
  54. .. rst-class:: classref-enumeration
  55. enum **EffectCallbackType**: :ref:`🔗<enum_CompositorEffect_EffectCallbackType>`
  56. .. _class_CompositorEffect_constant_EFFECT_CALLBACK_TYPE_PRE_OPAQUE:
  57. .. rst-class:: classref-enumeration-constant
  58. :ref:`EffectCallbackType<enum_CompositorEffect_EffectCallbackType>` **EFFECT_CALLBACK_TYPE_PRE_OPAQUE** = ``0``
  59. The callback is called before our opaque rendering pass, but after depth prepass (if applicable).
  60. .. _class_CompositorEffect_constant_EFFECT_CALLBACK_TYPE_POST_OPAQUE:
  61. .. rst-class:: classref-enumeration-constant
  62. :ref:`EffectCallbackType<enum_CompositorEffect_EffectCallbackType>` **EFFECT_CALLBACK_TYPE_POST_OPAQUE** = ``1``
  63. The callback is called after our opaque rendering pass, but before our sky is rendered.
  64. .. _class_CompositorEffect_constant_EFFECT_CALLBACK_TYPE_POST_SKY:
  65. .. rst-class:: classref-enumeration-constant
  66. :ref:`EffectCallbackType<enum_CompositorEffect_EffectCallbackType>` **EFFECT_CALLBACK_TYPE_POST_SKY** = ``2``
  67. The callback is called after our sky is rendered, but before our back buffers are created (and if enabled, before subsurface scattering and/or screen space reflections).
  68. .. _class_CompositorEffect_constant_EFFECT_CALLBACK_TYPE_PRE_TRANSPARENT:
  69. .. rst-class:: classref-enumeration-constant
  70. :ref:`EffectCallbackType<enum_CompositorEffect_EffectCallbackType>` **EFFECT_CALLBACK_TYPE_PRE_TRANSPARENT** = ``3``
  71. The callback is called before our transparent rendering pass, but after our sky is rendered and we've created our back buffers.
  72. .. _class_CompositorEffect_constant_EFFECT_CALLBACK_TYPE_POST_TRANSPARENT:
  73. .. rst-class:: classref-enumeration-constant
  74. :ref:`EffectCallbackType<enum_CompositorEffect_EffectCallbackType>` **EFFECT_CALLBACK_TYPE_POST_TRANSPARENT** = ``4``
  75. The callback is called after our transparent rendering pass, but before any built-in post-processing effects and output to our render target.
  76. .. _class_CompositorEffect_constant_EFFECT_CALLBACK_TYPE_MAX:
  77. .. rst-class:: classref-enumeration-constant
  78. :ref:`EffectCallbackType<enum_CompositorEffect_EffectCallbackType>` **EFFECT_CALLBACK_TYPE_MAX** = ``5``
  79. Represents the size of the :ref:`EffectCallbackType<enum_CompositorEffect_EffectCallbackType>` enum.
  80. .. rst-class:: classref-section-separator
  81. ----
  82. .. rst-class:: classref-descriptions-group
  83. Property Descriptions
  84. ---------------------
  85. .. _class_CompositorEffect_property_access_resolved_color:
  86. .. rst-class:: classref-property
  87. :ref:`bool<class_bool>` **access_resolved_color** :ref:`🔗<class_CompositorEffect_property_access_resolved_color>`
  88. .. rst-class:: classref-property-setget
  89. - |void| **set_access_resolved_color**\ (\ value\: :ref:`bool<class_bool>`\ )
  90. - :ref:`bool<class_bool>` **get_access_resolved_color**\ (\ )
  91. If ``true`` and MSAA is enabled, this will trigger a color buffer resolve before the effect is run.
  92. \ **Note:** In :ref:`_render_callback<class_CompositorEffect_private_method__render_callback>`, to access the resolved buffer use:
  93. ::
  94. var render_scene_buffers : RenderSceneBuffersRD = render_data.get_render_scene_buffers()
  95. var color_buffer = render_scene_buffers.get_texture("render_buffers", "color")
  96. .. rst-class:: classref-item-separator
  97. ----
  98. .. _class_CompositorEffect_property_access_resolved_depth:
  99. .. rst-class:: classref-property
  100. :ref:`bool<class_bool>` **access_resolved_depth** :ref:`🔗<class_CompositorEffect_property_access_resolved_depth>`
  101. .. rst-class:: classref-property-setget
  102. - |void| **set_access_resolved_depth**\ (\ value\: :ref:`bool<class_bool>`\ )
  103. - :ref:`bool<class_bool>` **get_access_resolved_depth**\ (\ )
  104. If ``true`` and MSAA is enabled, this will trigger a depth buffer resolve before the effect is run.
  105. \ **Note:** In :ref:`_render_callback<class_CompositorEffect_private_method__render_callback>`, to access the resolved buffer use:
  106. ::
  107. var render_scene_buffers : RenderSceneBuffersRD = render_data.get_render_scene_buffers()
  108. var depth_buffer = render_scene_buffers.get_texture("render_buffers", "depth")
  109. .. rst-class:: classref-item-separator
  110. ----
  111. .. _class_CompositorEffect_property_effect_callback_type:
  112. .. rst-class:: classref-property
  113. :ref:`EffectCallbackType<enum_CompositorEffect_EffectCallbackType>` **effect_callback_type** :ref:`🔗<class_CompositorEffect_property_effect_callback_type>`
  114. .. rst-class:: classref-property-setget
  115. - |void| **set_effect_callback_type**\ (\ value\: :ref:`EffectCallbackType<enum_CompositorEffect_EffectCallbackType>`\ )
  116. - :ref:`EffectCallbackType<enum_CompositorEffect_EffectCallbackType>` **get_effect_callback_type**\ (\ )
  117. The type of effect that is implemented, determines at what stage of rendering the callback is called.
  118. .. rst-class:: classref-item-separator
  119. ----
  120. .. _class_CompositorEffect_property_enabled:
  121. .. rst-class:: classref-property
  122. :ref:`bool<class_bool>` **enabled** :ref:`🔗<class_CompositorEffect_property_enabled>`
  123. .. rst-class:: classref-property-setget
  124. - |void| **set_enabled**\ (\ value\: :ref:`bool<class_bool>`\ )
  125. - :ref:`bool<class_bool>` **get_enabled**\ (\ )
  126. If ``true`` this rendering effect is applied to any viewport it is added to.
  127. .. rst-class:: classref-item-separator
  128. ----
  129. .. _class_CompositorEffect_property_needs_motion_vectors:
  130. .. rst-class:: classref-property
  131. :ref:`bool<class_bool>` **needs_motion_vectors** :ref:`🔗<class_CompositorEffect_property_needs_motion_vectors>`
  132. .. rst-class:: classref-property-setget
  133. - |void| **set_needs_motion_vectors**\ (\ value\: :ref:`bool<class_bool>`\ )
  134. - :ref:`bool<class_bool>` **get_needs_motion_vectors**\ (\ )
  135. If ``true`` this triggers motion vectors being calculated during the opaque render state.
  136. \ **Note:** In :ref:`_render_callback<class_CompositorEffect_private_method__render_callback>`, to access the motion vector buffer use:
  137. ::
  138. var render_scene_buffers : RenderSceneBuffersRD = render_data.get_render_scene_buffers()
  139. var motion_buffer = render_scene_buffers.get_velocity_texture()
  140. .. rst-class:: classref-item-separator
  141. ----
  142. .. _class_CompositorEffect_property_needs_normal_roughness:
  143. .. rst-class:: classref-property
  144. :ref:`bool<class_bool>` **needs_normal_roughness** :ref:`🔗<class_CompositorEffect_property_needs_normal_roughness>`
  145. .. rst-class:: classref-property-setget
  146. - |void| **set_needs_normal_roughness**\ (\ value\: :ref:`bool<class_bool>`\ )
  147. - :ref:`bool<class_bool>` **get_needs_normal_roughness**\ (\ )
  148. If ``true`` this triggers normal and roughness data to be output during our depth pre-pass, only applicable for the Forward+ renderer.
  149. \ **Note:** In :ref:`_render_callback<class_CompositorEffect_private_method__render_callback>`, to access the roughness buffer use:
  150. ::
  151. var render_scene_buffers : RenderSceneBuffersRD = render_data.get_render_scene_buffers()
  152. var roughness_buffer = render_scene_buffers.get_texture("forward_clustered", "normal_roughness")
  153. The raw normal and roughness buffer is stored in an optimized format, different than the one available in Spatial shaders. When sampling the buffer, a conversion function must be applied. Use this function, copied from `here <https://github.com/godotengine/godot/blob/da5f39889f155658cef7f7ec3cc1abb94e17d815/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered_inc.glsl#L334-L341>`__:
  154. ::
  155. vec4 normal_roughness_compatibility(vec4 p_normal_roughness) {
  156. float roughness = p_normal_roughness.w;
  157. if (roughness > 0.5) {
  158. roughness = 1.0 - roughness;
  159. }
  160. roughness /= (127.0 / 255.0);
  161. return vec4(normalize(p_normal_roughness.xyz * 2.0 - 1.0) * 0.5 + 0.5, roughness);
  162. }
  163. .. rst-class:: classref-item-separator
  164. ----
  165. .. _class_CompositorEffect_property_needs_separate_specular:
  166. .. rst-class:: classref-property
  167. :ref:`bool<class_bool>` **needs_separate_specular** :ref:`🔗<class_CompositorEffect_property_needs_separate_specular>`
  168. .. rst-class:: classref-property-setget
  169. - |void| **set_needs_separate_specular**\ (\ value\: :ref:`bool<class_bool>`\ )
  170. - :ref:`bool<class_bool>` **get_needs_separate_specular**\ (\ )
  171. If ``true`` this triggers specular data being rendered to a separate buffer and combined after effects have been applied, only applicable for the Forward+ renderer.
  172. .. rst-class:: classref-section-separator
  173. ----
  174. .. rst-class:: classref-descriptions-group
  175. Method Descriptions
  176. -------------------
  177. .. _class_CompositorEffect_private_method__render_callback:
  178. .. rst-class:: classref-method
  179. |void| **_render_callback**\ (\ effect_callback_type\: :ref:`int<class_int>`, render_data\: :ref:`RenderData<class_RenderData>`\ ) |virtual| :ref:`🔗<class_CompositorEffect_private_method__render_callback>`
  180. Implement this function with your custom rendering code. ``effect_callback_type`` should always match the effect callback type you've specified in :ref:`effect_callback_type<class_CompositorEffect_property_effect_callback_type>`. ``render_data`` provides access to the rendering state, it is only valid during rendering and should not be stored.
  181. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  182. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  183. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  184. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  185. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  186. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  187. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  188. .. |void| replace:: :abbr:`void (No return value.)`