light_2d.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /**************************************************************************/
  2. /* light_2d.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "light_2d.h"
  31. void Light2D::owner_changed_notify() {
  32. // For cases where owner changes _after_ entering tree (as example, editor editing).
  33. _update_light_visibility();
  34. }
  35. void Light2D::_update_light_visibility() {
  36. if (!is_inside_tree()) {
  37. return;
  38. }
  39. bool editor_ok = true;
  40. #ifdef TOOLS_ENABLED
  41. if (editor_only) {
  42. if (!Engine::get_singleton()->is_editor_hint()) {
  43. editor_ok = false;
  44. } else {
  45. editor_ok = (get_tree()->get_edited_scene_root() && (this == get_tree()->get_edited_scene_root() || get_owner() == get_tree()->get_edited_scene_root()));
  46. }
  47. }
  48. #else
  49. if (editor_only) {
  50. editor_ok = false;
  51. }
  52. #endif // TOOLS_ENABLED
  53. RS::get_singleton()->canvas_light_set_enabled(canvas_light, enabled && is_visible_in_tree() && editor_ok);
  54. }
  55. void Light2D::set_enabled(bool p_enabled) {
  56. enabled = p_enabled;
  57. _update_light_visibility();
  58. }
  59. bool Light2D::is_enabled() const {
  60. return enabled;
  61. }
  62. void Light2D::set_editor_only(bool p_editor_only) {
  63. editor_only = p_editor_only;
  64. _update_light_visibility();
  65. }
  66. bool Light2D::is_editor_only() const {
  67. return editor_only;
  68. }
  69. void Light2D::set_color(const Color &p_color) {
  70. color = p_color;
  71. RS::get_singleton()->canvas_light_set_color(canvas_light, color);
  72. }
  73. Color Light2D::get_color() const {
  74. return color;
  75. }
  76. void Light2D::set_height(real_t p_height) {
  77. height = p_height;
  78. RS::get_singleton()->canvas_light_set_height(canvas_light, height);
  79. }
  80. real_t Light2D::get_height() const {
  81. return height;
  82. }
  83. void Light2D::set_energy(real_t p_energy) {
  84. energy = p_energy;
  85. RS::get_singleton()->canvas_light_set_energy(canvas_light, energy);
  86. }
  87. real_t Light2D::get_energy() const {
  88. return energy;
  89. }
  90. void Light2D::set_z_range_min(int p_min_z) {
  91. z_min = p_min_z;
  92. RS::get_singleton()->canvas_light_set_z_range(canvas_light, z_min, z_max);
  93. }
  94. int Light2D::get_z_range_min() const {
  95. return z_min;
  96. }
  97. void Light2D::set_z_range_max(int p_max_z) {
  98. z_max = p_max_z;
  99. RS::get_singleton()->canvas_light_set_z_range(canvas_light, z_min, z_max);
  100. }
  101. int Light2D::get_z_range_max() const {
  102. return z_max;
  103. }
  104. void Light2D::set_layer_range_min(int p_min_layer) {
  105. layer_min = p_min_layer;
  106. RS::get_singleton()->canvas_light_set_layer_range(canvas_light, layer_min, layer_max);
  107. }
  108. int Light2D::get_layer_range_min() const {
  109. return layer_min;
  110. }
  111. void Light2D::set_layer_range_max(int p_max_layer) {
  112. layer_max = p_max_layer;
  113. RS::get_singleton()->canvas_light_set_layer_range(canvas_light, layer_min, layer_max);
  114. }
  115. int Light2D::get_layer_range_max() const {
  116. return layer_max;
  117. }
  118. void Light2D::set_item_cull_mask(int p_mask) {
  119. item_mask = p_mask;
  120. RS::get_singleton()->canvas_light_set_item_cull_mask(canvas_light, item_mask);
  121. }
  122. int Light2D::get_item_cull_mask() const {
  123. return item_mask;
  124. }
  125. void Light2D::set_item_shadow_cull_mask(int p_mask) {
  126. item_shadow_mask = p_mask;
  127. RS::get_singleton()->canvas_light_set_item_shadow_cull_mask(canvas_light, item_shadow_mask);
  128. }
  129. int Light2D::get_item_shadow_cull_mask() const {
  130. return item_shadow_mask;
  131. }
  132. void Light2D::set_shadow_enabled(bool p_enabled) {
  133. shadow = p_enabled;
  134. RS::get_singleton()->canvas_light_set_shadow_enabled(canvas_light, shadow);
  135. notify_property_list_changed();
  136. }
  137. bool Light2D::is_shadow_enabled() const {
  138. return shadow;
  139. }
  140. void Light2D::set_shadow_filter(ShadowFilter p_filter) {
  141. ERR_FAIL_INDEX(p_filter, SHADOW_FILTER_MAX);
  142. shadow_filter = p_filter;
  143. RS::get_singleton()->canvas_light_set_shadow_filter(canvas_light, RS::CanvasLightShadowFilter(p_filter));
  144. notify_property_list_changed();
  145. }
  146. Light2D::ShadowFilter Light2D::get_shadow_filter() const {
  147. return shadow_filter;
  148. }
  149. void Light2D::set_shadow_color(const Color &p_shadow_color) {
  150. shadow_color = p_shadow_color;
  151. RS::get_singleton()->canvas_light_set_shadow_color(canvas_light, shadow_color);
  152. }
  153. Color Light2D::get_shadow_color() const {
  154. return shadow_color;
  155. }
  156. void Light2D::set_blend_mode(BlendMode p_mode) {
  157. blend_mode = p_mode;
  158. RS::get_singleton()->canvas_light_set_blend_mode(_get_light(), RS::CanvasLightBlendMode(p_mode));
  159. }
  160. Light2D::BlendMode Light2D::get_blend_mode() const {
  161. return blend_mode;
  162. }
  163. void Light2D::_physics_interpolated_changed() {
  164. RenderingServer::get_singleton()->canvas_light_set_interpolated(canvas_light, is_physics_interpolated());
  165. }
  166. void Light2D::_notification(int p_what) {
  167. switch (p_what) {
  168. case NOTIFICATION_ENTER_CANVAS: {
  169. RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, get_canvas());
  170. _update_light_visibility();
  171. } break;
  172. case NOTIFICATION_TRANSFORM_CHANGED: {
  173. RS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform());
  174. } break;
  175. case NOTIFICATION_VISIBILITY_CHANGED: {
  176. _update_light_visibility();
  177. } break;
  178. case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
  179. if (is_visible_in_tree() && is_physics_interpolated()) {
  180. // Explicitly make sure the transform is up to date in RenderingServer before
  181. // resetting. This is necessary because NOTIFICATION_TRANSFORM_CHANGED
  182. // is normally deferred, and a client change to transform will not always be sent
  183. // before the reset, so we need to guarantee this.
  184. RS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform());
  185. RS::get_singleton()->canvas_light_reset_physics_interpolation(canvas_light);
  186. }
  187. } break;
  188. case NOTIFICATION_EXIT_CANVAS: {
  189. RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, RID());
  190. _update_light_visibility();
  191. } break;
  192. }
  193. }
  194. void Light2D::set_shadow_smooth(real_t p_amount) {
  195. shadow_smooth = p_amount;
  196. RS::get_singleton()->canvas_light_set_shadow_smooth(canvas_light, shadow_smooth);
  197. }
  198. real_t Light2D::get_shadow_smooth() const {
  199. return shadow_smooth;
  200. }
  201. void Light2D::_validate_property(PropertyInfo &p_property) const {
  202. if (!shadow && (p_property.name == "shadow_color" || p_property.name == "shadow_filter" || p_property.name == "shadow_filter_smooth" || p_property.name == "shadow_item_cull_mask")) {
  203. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  204. }
  205. if (shadow && p_property.name == "shadow_filter_smooth" && shadow_filter == SHADOW_FILTER_NONE) {
  206. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  207. }
  208. }
  209. void Light2D::_bind_methods() {
  210. ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &Light2D::set_enabled);
  211. ClassDB::bind_method(D_METHOD("is_enabled"), &Light2D::is_enabled);
  212. ClassDB::bind_method(D_METHOD("set_editor_only", "editor_only"), &Light2D::set_editor_only);
  213. ClassDB::bind_method(D_METHOD("is_editor_only"), &Light2D::is_editor_only);
  214. ClassDB::bind_method(D_METHOD("set_color", "color"), &Light2D::set_color);
  215. ClassDB::bind_method(D_METHOD("get_color"), &Light2D::get_color);
  216. ClassDB::bind_method(D_METHOD("set_energy", "energy"), &Light2D::set_energy);
  217. ClassDB::bind_method(D_METHOD("get_energy"), &Light2D::get_energy);
  218. ClassDB::bind_method(D_METHOD("set_z_range_min", "z"), &Light2D::set_z_range_min);
  219. ClassDB::bind_method(D_METHOD("get_z_range_min"), &Light2D::get_z_range_min);
  220. ClassDB::bind_method(D_METHOD("set_z_range_max", "z"), &Light2D::set_z_range_max);
  221. ClassDB::bind_method(D_METHOD("get_z_range_max"), &Light2D::get_z_range_max);
  222. ClassDB::bind_method(D_METHOD("set_layer_range_min", "layer"), &Light2D::set_layer_range_min);
  223. ClassDB::bind_method(D_METHOD("get_layer_range_min"), &Light2D::get_layer_range_min);
  224. ClassDB::bind_method(D_METHOD("set_layer_range_max", "layer"), &Light2D::set_layer_range_max);
  225. ClassDB::bind_method(D_METHOD("get_layer_range_max"), &Light2D::get_layer_range_max);
  226. ClassDB::bind_method(D_METHOD("set_item_cull_mask", "item_cull_mask"), &Light2D::set_item_cull_mask);
  227. ClassDB::bind_method(D_METHOD("get_item_cull_mask"), &Light2D::get_item_cull_mask);
  228. ClassDB::bind_method(D_METHOD("set_item_shadow_cull_mask", "item_shadow_cull_mask"), &Light2D::set_item_shadow_cull_mask);
  229. ClassDB::bind_method(D_METHOD("get_item_shadow_cull_mask"), &Light2D::get_item_shadow_cull_mask);
  230. ClassDB::bind_method(D_METHOD("set_shadow_enabled", "enabled"), &Light2D::set_shadow_enabled);
  231. ClassDB::bind_method(D_METHOD("is_shadow_enabled"), &Light2D::is_shadow_enabled);
  232. ClassDB::bind_method(D_METHOD("set_shadow_smooth", "smooth"), &Light2D::set_shadow_smooth);
  233. ClassDB::bind_method(D_METHOD("get_shadow_smooth"), &Light2D::get_shadow_smooth);
  234. ClassDB::bind_method(D_METHOD("set_shadow_filter", "filter"), &Light2D::set_shadow_filter);
  235. ClassDB::bind_method(D_METHOD("get_shadow_filter"), &Light2D::get_shadow_filter);
  236. ClassDB::bind_method(D_METHOD("set_shadow_color", "shadow_color"), &Light2D::set_shadow_color);
  237. ClassDB::bind_method(D_METHOD("get_shadow_color"), &Light2D::get_shadow_color);
  238. ClassDB::bind_method(D_METHOD("set_blend_mode", "mode"), &Light2D::set_blend_mode);
  239. ClassDB::bind_method(D_METHOD("get_blend_mode"), &Light2D::get_blend_mode);
  240. ClassDB::bind_method(D_METHOD("set_height", "height"), &Light2D::set_height);
  241. ClassDB::bind_method(D_METHOD("get_height"), &Light2D::get_height);
  242. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
  243. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "is_editor_only");
  244. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
  245. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_energy", "get_energy");
  246. ADD_PROPERTY(PropertyInfo(Variant::INT, "blend_mode", PROPERTY_HINT_ENUM, "Add,Subtract,Mix"), "set_blend_mode", "get_blend_mode");
  247. ADD_GROUP("Range", "range_");
  248. ADD_PROPERTY(PropertyInfo(Variant::INT, "range_z_min", PROPERTY_HINT_RANGE, itos(RS::CANVAS_ITEM_Z_MIN) + "," + itos(RS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_range_min", "get_z_range_min");
  249. ADD_PROPERTY(PropertyInfo(Variant::INT, "range_z_max", PROPERTY_HINT_RANGE, itos(RS::CANVAS_ITEM_Z_MIN) + "," + itos(RS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_range_max", "get_z_range_max");
  250. ADD_PROPERTY(PropertyInfo(Variant::INT, "range_layer_min", PROPERTY_HINT_RANGE, "-512,512,1"), "set_layer_range_min", "get_layer_range_min");
  251. ADD_PROPERTY(PropertyInfo(Variant::INT, "range_layer_max", PROPERTY_HINT_RANGE, "-512,512,1"), "set_layer_range_max", "get_layer_range_max");
  252. ADD_PROPERTY(PropertyInfo(Variant::INT, "range_item_cull_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_item_cull_mask", "get_item_cull_mask");
  253. ADD_GROUP("Shadow", "shadow_");
  254. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shadow_enabled"), "set_shadow_enabled", "is_shadow_enabled");
  255. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "shadow_color"), "set_shadow_color", "get_shadow_color");
  256. ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_filter", PROPERTY_HINT_ENUM, "None (Fast),PCF5 (Average),PCF13 (Slow)"), "set_shadow_filter", "get_shadow_filter");
  257. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "shadow_filter_smooth", PROPERTY_HINT_RANGE, "0,64,0.1"), "set_shadow_smooth", "get_shadow_smooth");
  258. ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_item_cull_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_item_shadow_cull_mask", "get_item_shadow_cull_mask");
  259. BIND_ENUM_CONSTANT(SHADOW_FILTER_NONE);
  260. BIND_ENUM_CONSTANT(SHADOW_FILTER_PCF5);
  261. BIND_ENUM_CONSTANT(SHADOW_FILTER_PCF13);
  262. BIND_ENUM_CONSTANT(BLEND_MODE_ADD);
  263. BIND_ENUM_CONSTANT(BLEND_MODE_SUB);
  264. BIND_ENUM_CONSTANT(BLEND_MODE_MIX);
  265. }
  266. Light2D::Light2D() {
  267. canvas_light = RenderingServer::get_singleton()->canvas_light_create();
  268. set_notify_transform(true);
  269. }
  270. Light2D::~Light2D() {
  271. ERR_FAIL_NULL(RenderingServer::get_singleton());
  272. RenderingServer::get_singleton()->free(canvas_light);
  273. }
  274. //////////////////////////////
  275. #ifdef TOOLS_ENABLED
  276. Dictionary PointLight2D::_edit_get_state() const {
  277. Dictionary state = Node2D::_edit_get_state();
  278. state["offset"] = get_texture_offset();
  279. return state;
  280. }
  281. void PointLight2D::_edit_set_state(const Dictionary &p_state) {
  282. Node2D::_edit_set_state(p_state);
  283. set_texture_offset(p_state["offset"]);
  284. }
  285. void PointLight2D::_edit_set_pivot(const Point2 &p_pivot) {
  286. set_position(get_transform().xform(p_pivot));
  287. set_texture_offset(get_texture_offset() - p_pivot);
  288. }
  289. Point2 PointLight2D::_edit_get_pivot() const {
  290. return Vector2();
  291. }
  292. bool PointLight2D::_edit_use_pivot() const {
  293. return true;
  294. }
  295. #endif // TOOLS_ENABLED
  296. #ifdef DEBUG_ENABLED
  297. Rect2 PointLight2D::_edit_get_rect() const {
  298. if (texture.is_null()) {
  299. return Rect2();
  300. }
  301. Size2 s = texture->get_size() * _scale;
  302. return Rect2(texture_offset - s / 2.0, s);
  303. }
  304. bool PointLight2D::_edit_use_rect() const {
  305. return !texture.is_null();
  306. }
  307. #endif // DEBUG_ENABLED
  308. Rect2 PointLight2D::get_anchorable_rect() const {
  309. if (texture.is_null()) {
  310. return Rect2();
  311. }
  312. Size2 s = texture->get_size() * _scale;
  313. return Rect2(texture_offset - s / 2.0, s);
  314. }
  315. void PointLight2D::set_texture(const Ref<Texture2D> &p_texture) {
  316. texture = p_texture;
  317. if (texture.is_valid()) {
  318. RS::get_singleton()->canvas_light_set_texture(_get_light(), texture->get_rid());
  319. } else {
  320. RS::get_singleton()->canvas_light_set_texture(_get_light(), RID());
  321. }
  322. update_configuration_warnings();
  323. }
  324. Ref<Texture2D> PointLight2D::get_texture() const {
  325. return texture;
  326. }
  327. void PointLight2D::set_texture_offset(const Vector2 &p_offset) {
  328. texture_offset = p_offset;
  329. RS::get_singleton()->canvas_light_set_texture_offset(_get_light(), texture_offset);
  330. item_rect_changed();
  331. }
  332. Vector2 PointLight2D::get_texture_offset() const {
  333. return texture_offset;
  334. }
  335. PackedStringArray PointLight2D::get_configuration_warnings() const {
  336. PackedStringArray warnings = Light2D::get_configuration_warnings();
  337. if (!texture.is_valid()) {
  338. warnings.push_back(RTR("A texture with the shape of the light must be supplied to the \"Texture\" property."));
  339. }
  340. return warnings;
  341. }
  342. void PointLight2D::set_texture_scale(real_t p_scale) {
  343. _scale = p_scale;
  344. // Avoid having 0 scale values, can lead to errors in physics and rendering.
  345. if (_scale == 0) {
  346. _scale = CMP_EPSILON;
  347. }
  348. RS::get_singleton()->canvas_light_set_texture_scale(_get_light(), _scale);
  349. item_rect_changed();
  350. }
  351. real_t PointLight2D::get_texture_scale() const {
  352. return _scale;
  353. }
  354. #ifndef DISABLE_DEPRECATED
  355. bool PointLight2D::_set(const StringName &p_name, const Variant &p_value) {
  356. if (p_name == "mode" && p_value.is_num()) { // Compatibility with Godot 3.x.
  357. set_blend_mode((BlendMode)(int)p_value);
  358. return true;
  359. }
  360. return false;
  361. }
  362. #endif // DISABLE_DEPRECATED
  363. void PointLight2D::_bind_methods() {
  364. ClassDB::bind_method(D_METHOD("set_texture", "texture"), &PointLight2D::set_texture);
  365. ClassDB::bind_method(D_METHOD("get_texture"), &PointLight2D::get_texture);
  366. ClassDB::bind_method(D_METHOD("set_texture_offset", "texture_offset"), &PointLight2D::set_texture_offset);
  367. ClassDB::bind_method(D_METHOD("get_texture_offset"), &PointLight2D::get_texture_offset);
  368. ClassDB::bind_method(D_METHOD("set_texture_scale", "texture_scale"), &PointLight2D::set_texture_scale);
  369. ClassDB::bind_method(D_METHOD("get_texture_scale"), &PointLight2D::get_texture_scale);
  370. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture");
  371. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset", PROPERTY_HINT_NONE, "suffix:px"), "set_texture_offset", "get_texture_offset");
  372. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "texture_scale", PROPERTY_HINT_RANGE, "0.01,50,0.01"), "set_texture_scale", "get_texture_scale");
  373. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0,1024,1,or_greater,suffix:px"), "set_height", "get_height");
  374. }
  375. PointLight2D::PointLight2D() {
  376. RS::get_singleton()->canvas_light_set_mode(_get_light(), RS::CANVAS_LIGHT_MODE_POINT);
  377. set_hide_clip_children(true);
  378. }
  379. //////////
  380. void DirectionalLight2D::set_max_distance(real_t p_distance) {
  381. max_distance = p_distance;
  382. RS::get_singleton()->canvas_light_set_directional_distance(_get_light(), max_distance);
  383. }
  384. real_t DirectionalLight2D::get_max_distance() const {
  385. return max_distance;
  386. }
  387. void DirectionalLight2D::_bind_methods() {
  388. ClassDB::bind_method(D_METHOD("set_max_distance", "pixels"), &DirectionalLight2D::set_max_distance);
  389. ClassDB::bind_method(D_METHOD("get_max_distance"), &DirectionalLight2D::get_max_distance);
  390. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_height", "get_height");
  391. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_distance", PROPERTY_HINT_RANGE, "0,16384.0,1.0,or_greater,suffix:px"), "set_max_distance", "get_max_distance");
  392. }
  393. DirectionalLight2D::DirectionalLight2D() {
  394. RS::get_singleton()->canvas_light_set_mode(_get_light(), RS::CANVAS_LIGHT_MODE_DIRECTIONAL);
  395. set_max_distance(max_distance); // Update RenderingServer.
  396. set_hide_clip_children(true);
  397. }