class_light.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 Light.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Light:
  6. Light
  7. =====
  8. **Inherits:** :ref:`VisualInstance<class_VisualInstance>` **<** :ref:`CullInstance<class_CullInstance>` **<** :ref:`Spatial<class_Spatial>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`DirectionalLight<class_DirectionalLight>`, :ref:`OmniLight<class_OmniLight>`, :ref:`SpotLight<class_SpotLight>`
  10. Provides a base class for different kinds of light nodes.
  11. Description
  12. -----------
  13. Light is the *abstract* base class for light nodes. As it can't be instanced, it shouldn't be used directly. Other types of light nodes inherit from it. Light contains the common variables and parameters used for lighting.
  14. Tutorials
  15. ---------
  16. - :doc:`../tutorials/3d/lights_and_shadows`
  17. - `Third Person Shooter Demo <https://godotengine.org/asset-library/asset/678>`__
  18. Properties
  19. ----------
  20. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  21. | :ref:`bool<class_bool>` | :ref:`editor_only<class_Light_property_editor_only>` | ``false`` |
  22. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  23. | :ref:`BakeMode<enum_Light_BakeMode>` | :ref:`light_bake_mode<class_Light_property_light_bake_mode>` | ``1`` |
  24. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  25. | :ref:`Color<class_Color>` | :ref:`light_color<class_Light_property_light_color>` | ``Color( 1, 1, 1, 1 )`` |
  26. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  27. | :ref:`int<class_int>` | :ref:`light_cull_mask<class_Light_property_light_cull_mask>` | ``4294967295`` |
  28. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  29. | :ref:`float<class_float>` | :ref:`light_energy<class_Light_property_light_energy>` | ``1.0`` |
  30. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  31. | :ref:`float<class_float>` | :ref:`light_indirect_energy<class_Light_property_light_indirect_energy>` | ``1.0`` |
  32. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  33. | :ref:`bool<class_bool>` | :ref:`light_negative<class_Light_property_light_negative>` | ``false`` |
  34. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  35. | :ref:`float<class_float>` | :ref:`light_size<class_Light_property_light_size>` | ``0.0`` |
  36. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  37. | :ref:`float<class_float>` | :ref:`light_specular<class_Light_property_light_specular>` | ``0.5`` |
  38. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  39. | :ref:`float<class_float>` | :ref:`shadow_bias<class_Light_property_shadow_bias>` | ``0.15`` |
  40. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  41. | :ref:`Color<class_Color>` | :ref:`shadow_color<class_Light_property_shadow_color>` | ``Color( 0, 0, 0, 1 )`` |
  42. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  43. | :ref:`float<class_float>` | :ref:`shadow_contact<class_Light_property_shadow_contact>` | ``0.0`` |
  44. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  45. | :ref:`bool<class_bool>` | :ref:`shadow_enabled<class_Light_property_shadow_enabled>` | ``false`` |
  46. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`shadow_reverse_cull_face<class_Light_property_shadow_reverse_cull_face>` | ``false`` |
  48. +--------------------------------------+--------------------------------------------------------------------------------+-------------------------+
  49. Methods
  50. -------
  51. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`float<class_float>` | :ref:`get_param<class_Light_method_get_param>` **(** :ref:`Param<enum_Light_Param>` param **)** |const| |
  53. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------+
  54. | void | :ref:`set_param<class_Light_method_set_param>` **(** :ref:`Param<enum_Light_Param>` param, :ref:`float<class_float>` value **)** |
  55. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------+
  56. Enumerations
  57. ------------
  58. .. _enum_Light_Param:
  59. .. _class_Light_constant_PARAM_ENERGY:
  60. .. _class_Light_constant_PARAM_INDIRECT_ENERGY:
  61. .. _class_Light_constant_PARAM_SIZE:
  62. .. _class_Light_constant_PARAM_SPECULAR:
  63. .. _class_Light_constant_PARAM_RANGE:
  64. .. _class_Light_constant_PARAM_ATTENUATION:
  65. .. _class_Light_constant_PARAM_SPOT_ANGLE:
  66. .. _class_Light_constant_PARAM_SPOT_ATTENUATION:
  67. .. _class_Light_constant_PARAM_CONTACT_SHADOW_SIZE:
  68. .. _class_Light_constant_PARAM_SHADOW_MAX_DISTANCE:
  69. .. _class_Light_constant_PARAM_SHADOW_SPLIT_1_OFFSET:
  70. .. _class_Light_constant_PARAM_SHADOW_SPLIT_2_OFFSET:
  71. .. _class_Light_constant_PARAM_SHADOW_SPLIT_3_OFFSET:
  72. .. _class_Light_constant_PARAM_SHADOW_NORMAL_BIAS:
  73. .. _class_Light_constant_PARAM_SHADOW_BIAS:
  74. .. _class_Light_constant_PARAM_SHADOW_BIAS_SPLIT_SCALE:
  75. .. _class_Light_constant_PARAM_MAX:
  76. enum **Param**:
  77. - **PARAM_ENERGY** = **0** --- Constant for accessing :ref:`light_energy<class_Light_property_light_energy>`.
  78. - **PARAM_INDIRECT_ENERGY** = **1** --- Constant for accessing :ref:`light_indirect_energy<class_Light_property_light_indirect_energy>`.
  79. - **PARAM_SIZE** = **2** --- Constant for accessing :ref:`light_size<class_Light_property_light_size>`.
  80. - **PARAM_SPECULAR** = **3** --- Constant for accessing :ref:`light_specular<class_Light_property_light_specular>`.
  81. - **PARAM_RANGE** = **4** --- Constant for accessing :ref:`OmniLight.omni_range<class_OmniLight_property_omni_range>` or :ref:`SpotLight.spot_range<class_SpotLight_property_spot_range>`.
  82. - **PARAM_ATTENUATION** = **5** --- Constant for accessing :ref:`OmniLight.omni_attenuation<class_OmniLight_property_omni_attenuation>` or :ref:`SpotLight.spot_attenuation<class_SpotLight_property_spot_attenuation>`.
  83. - **PARAM_SPOT_ANGLE** = **6** --- Constant for accessing :ref:`SpotLight.spot_angle<class_SpotLight_property_spot_angle>`.
  84. - **PARAM_SPOT_ATTENUATION** = **7** --- Constant for accessing :ref:`SpotLight.spot_angle_attenuation<class_SpotLight_property_spot_angle_attenuation>`.
  85. - **PARAM_CONTACT_SHADOW_SIZE** = **8** --- Constant for accessing :ref:`shadow_contact<class_Light_property_shadow_contact>`.
  86. - **PARAM_SHADOW_MAX_DISTANCE** = **9** --- Constant for accessing :ref:`DirectionalLight.directional_shadow_max_distance<class_DirectionalLight_property_directional_shadow_max_distance>`.
  87. - **PARAM_SHADOW_SPLIT_1_OFFSET** = **10** --- Constant for accessing :ref:`DirectionalLight.directional_shadow_split_1<class_DirectionalLight_property_directional_shadow_split_1>`.
  88. - **PARAM_SHADOW_SPLIT_2_OFFSET** = **11** --- Constant for accessing :ref:`DirectionalLight.directional_shadow_split_2<class_DirectionalLight_property_directional_shadow_split_2>`.
  89. - **PARAM_SHADOW_SPLIT_3_OFFSET** = **12** --- Constant for accessing :ref:`DirectionalLight.directional_shadow_split_3<class_DirectionalLight_property_directional_shadow_split_3>`.
  90. - **PARAM_SHADOW_NORMAL_BIAS** = **13** --- Constant for accessing :ref:`DirectionalLight.directional_shadow_normal_bias<class_DirectionalLight_property_directional_shadow_normal_bias>`.
  91. - **PARAM_SHADOW_BIAS** = **14** --- Constant for accessing :ref:`shadow_bias<class_Light_property_shadow_bias>`.
  92. - **PARAM_SHADOW_BIAS_SPLIT_SCALE** = **15** --- Constant for accessing :ref:`DirectionalLight.directional_shadow_bias_split_scale<class_DirectionalLight_property_directional_shadow_bias_split_scale>`.
  93. - **PARAM_MAX** = **16** --- Represents the size of the :ref:`Param<enum_Light_Param>` enum.
  94. ----
  95. .. _enum_Light_BakeMode:
  96. .. _class_Light_constant_BAKE_DISABLED:
  97. .. _class_Light_constant_BAKE_INDIRECT:
  98. .. _class_Light_constant_BAKE_ALL:
  99. enum **BakeMode**:
  100. - **BAKE_DISABLED** = **0** --- Light is ignored when baking.
  101. **Note:** Hiding a light does *not* affect baking.
  102. - **BAKE_INDIRECT** = **1** --- Only indirect lighting will be baked (default).
  103. - **BAKE_ALL** = **2** --- Both direct and indirect light will be baked.
  104. **Note:** You should hide the light if you don't want it to appear twice (dynamic and baked).
  105. Property Descriptions
  106. ---------------------
  107. .. _class_Light_property_editor_only:
  108. - :ref:`bool<class_bool>` **editor_only**
  109. +-----------+------------------------+
  110. | *Default* | ``false`` |
  111. +-----------+------------------------+
  112. | *Setter* | set_editor_only(value) |
  113. +-----------+------------------------+
  114. | *Getter* | is_editor_only() |
  115. +-----------+------------------------+
  116. If ``true``, the light only appears in the editor and will not be visible at runtime.
  117. ----
  118. .. _class_Light_property_light_bake_mode:
  119. - :ref:`BakeMode<enum_Light_BakeMode>` **light_bake_mode**
  120. +-----------+----------------------+
  121. | *Default* | ``1`` |
  122. +-----------+----------------------+
  123. | *Setter* | set_bake_mode(value) |
  124. +-----------+----------------------+
  125. | *Getter* | get_bake_mode() |
  126. +-----------+----------------------+
  127. The light's bake mode. See :ref:`BakeMode<enum_Light_BakeMode>`.
  128. ----
  129. .. _class_Light_property_light_color:
  130. - :ref:`Color<class_Color>` **light_color**
  131. +-----------+-------------------------+
  132. | *Default* | ``Color( 1, 1, 1, 1 )`` |
  133. +-----------+-------------------------+
  134. | *Setter* | set_color(value) |
  135. +-----------+-------------------------+
  136. | *Getter* | get_color() |
  137. +-----------+-------------------------+
  138. The light's color. An *overbright* color can be used to achieve a result equivalent to increasing the light's :ref:`light_energy<class_Light_property_light_energy>`.
  139. ----
  140. .. _class_Light_property_light_cull_mask:
  141. - :ref:`int<class_int>` **light_cull_mask**
  142. +-----------+----------------------+
  143. | *Default* | ``4294967295`` |
  144. +-----------+----------------------+
  145. | *Setter* | set_cull_mask(value) |
  146. +-----------+----------------------+
  147. | *Getter* | get_cull_mask() |
  148. +-----------+----------------------+
  149. The light will affect objects in the selected layers.
  150. ----
  151. .. _class_Light_property_light_energy:
  152. - :ref:`float<class_float>` **light_energy**
  153. +-----------+------------------+
  154. | *Default* | ``1.0`` |
  155. +-----------+------------------+
  156. | *Setter* | set_param(value) |
  157. +-----------+------------------+
  158. | *Getter* | get_param() |
  159. +-----------+------------------+
  160. The light's strength multiplier (this is not a physical unit). For :ref:`OmniLight<class_OmniLight>` and :ref:`SpotLight<class_SpotLight>`, changing this value will only change the light color's intensity, not the light's radius.
  161. ----
  162. .. _class_Light_property_light_indirect_energy:
  163. - :ref:`float<class_float>` **light_indirect_energy**
  164. +-----------+------------------+
  165. | *Default* | ``1.0`` |
  166. +-----------+------------------+
  167. | *Setter* | set_param(value) |
  168. +-----------+------------------+
  169. | *Getter* | get_param() |
  170. +-----------+------------------+
  171. Secondary multiplier used with indirect light (light bounces). This works on both :ref:`BakedLightmap<class_BakedLightmap>` and :ref:`GIProbe<class_GIProbe>`.
  172. ----
  173. .. _class_Light_property_light_negative:
  174. - :ref:`bool<class_bool>` **light_negative**
  175. +-----------+---------------------+
  176. | *Default* | ``false`` |
  177. +-----------+---------------------+
  178. | *Setter* | set_negative(value) |
  179. +-----------+---------------------+
  180. | *Getter* | is_negative() |
  181. +-----------+---------------------+
  182. If ``true``, the light's effect is reversed, darkening areas and casting bright shadows.
  183. ----
  184. .. _class_Light_property_light_size:
  185. - :ref:`float<class_float>` **light_size**
  186. +-----------+------------------+
  187. | *Default* | ``0.0`` |
  188. +-----------+------------------+
  189. | *Setter* | set_param(value) |
  190. +-----------+------------------+
  191. | *Getter* | get_param() |
  192. +-----------+------------------+
  193. The size of the light in Godot units. Only considered in baked lightmaps and only if :ref:`light_bake_mode<class_Light_property_light_bake_mode>` is set to :ref:`BAKE_ALL<class_Light_constant_BAKE_ALL>`. Increasing this value will make the shadows appear blurrier. This can be used to simulate area lights to an extent.
  194. ----
  195. .. _class_Light_property_light_specular:
  196. - :ref:`float<class_float>` **light_specular**
  197. +-----------+------------------+
  198. | *Default* | ``0.5`` |
  199. +-----------+------------------+
  200. | *Setter* | set_param(value) |
  201. +-----------+------------------+
  202. | *Getter* | get_param() |
  203. +-----------+------------------+
  204. The intensity of the specular blob in objects affected by the light. At ``0``, the light becomes a pure diffuse light. When not baking emission, this can be used to avoid unrealistic reflections when placing lights above an emissive surface.
  205. ----
  206. .. _class_Light_property_shadow_bias:
  207. - :ref:`float<class_float>` **shadow_bias**
  208. +-----------+------------------+
  209. | *Default* | ``0.15`` |
  210. +-----------+------------------+
  211. | *Setter* | set_param(value) |
  212. +-----------+------------------+
  213. | *Getter* | get_param() |
  214. +-----------+------------------+
  215. Used to adjust shadow appearance. Too small a value results in self-shadowing ("shadow acne"), while too large a value causes shadows to separate from casters ("peter-panning"). Adjust as needed.
  216. ----
  217. .. _class_Light_property_shadow_color:
  218. - :ref:`Color<class_Color>` **shadow_color**
  219. +-----------+-------------------------+
  220. | *Default* | ``Color( 0, 0, 0, 1 )`` |
  221. +-----------+-------------------------+
  222. | *Setter* | set_shadow_color(value) |
  223. +-----------+-------------------------+
  224. | *Getter* | get_shadow_color() |
  225. +-----------+-------------------------+
  226. The color of shadows cast by this light.
  227. ----
  228. .. _class_Light_property_shadow_contact:
  229. - :ref:`float<class_float>` **shadow_contact**
  230. +-----------+------------------+
  231. | *Default* | ``0.0`` |
  232. +-----------+------------------+
  233. | *Setter* | set_param(value) |
  234. +-----------+------------------+
  235. | *Getter* | get_param() |
  236. +-----------+------------------+
  237. Attempts to reduce :ref:`shadow_bias<class_Light_property_shadow_bias>` gap by rendering screen-space contact shadows. This has a performance impact, especially at higher values.
  238. **Note:** Contact shadows can look broken, so leaving this property to ``0.0`` is recommended.
  239. ----
  240. .. _class_Light_property_shadow_enabled:
  241. - :ref:`bool<class_bool>` **shadow_enabled**
  242. +-----------+-------------------+
  243. | *Default* | ``false`` |
  244. +-----------+-------------------+
  245. | *Setter* | set_shadow(value) |
  246. +-----------+-------------------+
  247. | *Getter* | has_shadow() |
  248. +-----------+-------------------+
  249. If ``true``, the light will cast shadows.
  250. ----
  251. .. _class_Light_property_shadow_reverse_cull_face:
  252. - :ref:`bool<class_bool>` **shadow_reverse_cull_face**
  253. +-----------+-------------------------------------+
  254. | *Default* | ``false`` |
  255. +-----------+-------------------------------------+
  256. | *Setter* | set_shadow_reverse_cull_face(value) |
  257. +-----------+-------------------------------------+
  258. | *Getter* | get_shadow_reverse_cull_face() |
  259. +-----------+-------------------------------------+
  260. If ``true``, reverses the backface culling of the mesh. This can be useful when you have a flat mesh that has a light behind it. If you need to cast a shadow on both sides of the mesh, set the mesh to use double-sided shadows with :ref:`GeometryInstance.SHADOW_CASTING_SETTING_DOUBLE_SIDED<class_GeometryInstance_constant_SHADOW_CASTING_SETTING_DOUBLE_SIDED>`.
  261. Method Descriptions
  262. -------------------
  263. .. _class_Light_method_get_param:
  264. - :ref:`float<class_float>` **get_param** **(** :ref:`Param<enum_Light_Param>` param **)** |const|
  265. Returns the value of the specified :ref:`Param<enum_Light_Param>` parameter.
  266. ----
  267. .. _class_Light_method_set_param:
  268. - void **set_param** **(** :ref:`Param<enum_Light_Param>` param, :ref:`float<class_float>` value **)**
  269. Sets the value of the specified :ref:`Param<enum_Light_Param>` parameter.
  270. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  271. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  272. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`