light_2d.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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. }
  136. bool Light2D::is_shadow_enabled() const {
  137. return shadow;
  138. }
  139. void Light2D::set_shadow_filter(ShadowFilter p_filter) {
  140. ERR_FAIL_INDEX(p_filter, SHADOW_FILTER_MAX);
  141. shadow_filter = p_filter;
  142. RS::get_singleton()->canvas_light_set_shadow_filter(canvas_light, RS::CanvasLightShadowFilter(p_filter));
  143. notify_property_list_changed();
  144. }
  145. Light2D::ShadowFilter Light2D::get_shadow_filter() const {
  146. return shadow_filter;
  147. }
  148. void Light2D::set_shadow_color(const Color &p_shadow_color) {
  149. shadow_color = p_shadow_color;
  150. RS::get_singleton()->canvas_light_set_shadow_color(canvas_light, shadow_color);
  151. }
  152. Color Light2D::get_shadow_color() const {
  153. return shadow_color;
  154. }
  155. void Light2D::set_blend_mode(BlendMode p_mode) {
  156. blend_mode = p_mode;
  157. RS::get_singleton()->canvas_light_set_blend_mode(_get_light(), RS::CanvasLightBlendMode(p_mode));
  158. }
  159. Light2D::BlendMode Light2D::get_blend_mode() const {
  160. return blend_mode;
  161. }
  162. void Light2D::_physics_interpolated_changed() {
  163. RenderingServer::get_singleton()->canvas_light_set_interpolated(canvas_light, is_physics_interpolated());
  164. }
  165. void Light2D::_notification(int p_what) {
  166. switch (p_what) {
  167. case NOTIFICATION_ENTER_CANVAS: {
  168. RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, get_canvas());
  169. _update_light_visibility();
  170. } break;
  171. case NOTIFICATION_TRANSFORM_CHANGED: {
  172. RS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform());
  173. } break;
  174. case NOTIFICATION_VISIBILITY_CHANGED: {
  175. _update_light_visibility();
  176. } break;
  177. case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
  178. if (is_visible_in_tree() && is_physics_interpolated_and_enabled()) {
  179. // Explicitly make sure the transform is up to date in RenderingServer before
  180. // resetting. This is necessary because NOTIFICATION_TRANSFORM_CHANGED
  181. // is normally deferred, and a client change to transform will not always be sent
  182. // before the reset, so we need to guarantee this.
  183. RS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform());
  184. RS::get_singleton()->canvas_light_reset_physics_interpolation(canvas_light);
  185. }
  186. } break;
  187. case NOTIFICATION_EXIT_CANVAS: {
  188. RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, RID());
  189. _update_light_visibility();
  190. } break;
  191. }
  192. }
  193. void Light2D::set_shadow_smooth(real_t p_amount) {
  194. shadow_smooth = p_amount;
  195. RS::get_singleton()->canvas_light_set_shadow_smooth(canvas_light, shadow_smooth);
  196. }
  197. real_t Light2D::get_shadow_smooth() const {
  198. return shadow_smooth;
  199. }
  200. void Light2D::_validate_property(PropertyInfo &p_property) const {
  201. if (!Engine::get_singleton()->is_editor_hint()) {
  202. return;
  203. }
  204. if (shadow && p_property.name == "shadow_filter_smooth" && shadow_filter == SHADOW_FILTER_NONE) {
  205. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  206. }
  207. }
  208. void Light2D::_bind_methods() {
  209. ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &Light2D::set_enabled);
  210. ClassDB::bind_method(D_METHOD("is_enabled"), &Light2D::is_enabled);
  211. ClassDB::bind_method(D_METHOD("set_editor_only", "editor_only"), &Light2D::set_editor_only);
  212. ClassDB::bind_method(D_METHOD("is_editor_only"), &Light2D::is_editor_only);
  213. ClassDB::bind_method(D_METHOD("set_color", "color"), &Light2D::set_color);
  214. ClassDB::bind_method(D_METHOD("get_color"), &Light2D::get_color);
  215. ClassDB::bind_method(D_METHOD("set_energy", "energy"), &Light2D::set_energy);
  216. ClassDB::bind_method(D_METHOD("get_energy"), &Light2D::get_energy);
  217. ClassDB::bind_method(D_METHOD("set_z_range_min", "z"), &Light2D::set_z_range_min);
  218. ClassDB::bind_method(D_METHOD("get_z_range_min"), &Light2D::get_z_range_min);
  219. ClassDB::bind_method(D_METHOD("set_z_range_max", "z"), &Light2D::set_z_range_max);
  220. ClassDB::bind_method(D_METHOD("get_z_range_max"), &Light2D::get_z_range_max);
  221. ClassDB::bind_method(D_METHOD("set_layer_range_min", "layer"), &Light2D::set_layer_range_min);
  222. ClassDB::bind_method(D_METHOD("get_layer_range_min"), &Light2D::get_layer_range_min);
  223. ClassDB::bind_method(D_METHOD("set_layer_range_max", "layer"), &Light2D::set_layer_range_max);
  224. ClassDB::bind_method(D_METHOD("get_layer_range_max"), &Light2D::get_layer_range_max);
  225. ClassDB::bind_method(D_METHOD("set_item_cull_mask", "item_cull_mask"), &Light2D::set_item_cull_mask);
  226. ClassDB::bind_method(D_METHOD("get_item_cull_mask"), &Light2D::get_item_cull_mask);
  227. ClassDB::bind_method(D_METHOD("set_item_shadow_cull_mask", "item_shadow_cull_mask"), &Light2D::set_item_shadow_cull_mask);
  228. ClassDB::bind_method(D_METHOD("get_item_shadow_cull_mask"), &Light2D::get_item_shadow_cull_mask);
  229. ClassDB::bind_method(D_METHOD("set_shadow_enabled", "enabled"), &Light2D::set_shadow_enabled);
  230. ClassDB::bind_method(D_METHOD("is_shadow_enabled"), &Light2D::is_shadow_enabled);
  231. ClassDB::bind_method(D_METHOD("set_shadow_smooth", "smooth"), &Light2D::set_shadow_smooth);
  232. ClassDB::bind_method(D_METHOD("get_shadow_smooth"), &Light2D::get_shadow_smooth);
  233. ClassDB::bind_method(D_METHOD("set_shadow_filter", "filter"), &Light2D::set_shadow_filter);
  234. ClassDB::bind_method(D_METHOD("get_shadow_filter"), &Light2D::get_shadow_filter);
  235. ClassDB::bind_method(D_METHOD("set_shadow_color", "shadow_color"), &Light2D::set_shadow_color);
  236. ClassDB::bind_method(D_METHOD("get_shadow_color"), &Light2D::get_shadow_color);
  237. ClassDB::bind_method(D_METHOD("set_blend_mode", "mode"), &Light2D::set_blend_mode);
  238. ClassDB::bind_method(D_METHOD("get_blend_mode"), &Light2D::get_blend_mode);
  239. ClassDB::bind_method(D_METHOD("set_height", "height"), &Light2D::set_height);
  240. ClassDB::bind_method(D_METHOD("get_height"), &Light2D::get_height);
  241. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
  242. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "is_editor_only");
  243. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
  244. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_energy", "get_energy");
  245. ADD_PROPERTY(PropertyInfo(Variant::INT, "blend_mode", PROPERTY_HINT_ENUM, "Add,Subtract,Mix"), "set_blend_mode", "get_blend_mode");
  246. ADD_GROUP("Range", "range_");
  247. 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");
  248. 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");
  249. ADD_PROPERTY(PropertyInfo(Variant::INT, "range_layer_min", PROPERTY_HINT_RANGE, itos(RS::CANVAS_LAYER_MIN) + "," + itos(RS::CANVAS_LAYER_MAX) + ",1"), "set_layer_range_min", "get_layer_range_min");
  250. ADD_PROPERTY(PropertyInfo(Variant::INT, "range_layer_max", PROPERTY_HINT_RANGE, itos(RS::CANVAS_LAYER_MIN) + "," + itos(RS::CANVAS_LAYER_MAX) + ",1"), "set_layer_range_max", "get_layer_range_max");
  251. ADD_PROPERTY(PropertyInfo(Variant::INT, "range_item_cull_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_item_cull_mask", "get_item_cull_mask");
  252. ADD_GROUP("Shadow", "shadow_");
  253. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shadow_enabled", PROPERTY_HINT_GROUP_ENABLE), "set_shadow_enabled", "is_shadow_enabled");
  254. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "shadow_color"), "set_shadow_color", "get_shadow_color");
  255. ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_filter", PROPERTY_HINT_ENUM, "None (Fast),PCF5 (Average),PCF13 (Slow)"), "set_shadow_filter", "get_shadow_filter");
  256. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "shadow_filter_smooth", PROPERTY_HINT_RANGE, "0,64,0.1"), "set_shadow_smooth", "get_shadow_smooth");
  257. ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_item_cull_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_item_shadow_cull_mask", "get_item_shadow_cull_mask");
  258. BIND_ENUM_CONSTANT(SHADOW_FILTER_NONE);
  259. BIND_ENUM_CONSTANT(SHADOW_FILTER_PCF5);
  260. BIND_ENUM_CONSTANT(SHADOW_FILTER_PCF13);
  261. BIND_ENUM_CONSTANT(BLEND_MODE_ADD);
  262. BIND_ENUM_CONSTANT(BLEND_MODE_SUB);
  263. BIND_ENUM_CONSTANT(BLEND_MODE_MIX);
  264. }
  265. Light2D::Light2D() {
  266. canvas_light = RenderingServer::get_singleton()->canvas_light_create();
  267. set_notify_transform(true);
  268. }
  269. Light2D::~Light2D() {
  270. ERR_FAIL_NULL(RenderingServer::get_singleton());
  271. RenderingServer::get_singleton()->free(canvas_light);
  272. }
  273. //////////////////////////////
  274. #ifdef TOOLS_ENABLED
  275. Dictionary PointLight2D::_edit_get_state() const {
  276. Dictionary state = Node2D::_edit_get_state();
  277. state["offset"] = get_texture_offset();
  278. return state;
  279. }
  280. void PointLight2D::_edit_set_state(const Dictionary &p_state) {
  281. Node2D::_edit_set_state(p_state);
  282. set_texture_offset(p_state["offset"]);
  283. }
  284. void PointLight2D::_edit_set_pivot(const Point2 &p_pivot) {
  285. set_position(get_transform().xform(p_pivot));
  286. set_texture_offset(get_texture_offset() - p_pivot);
  287. }
  288. Point2 PointLight2D::_edit_get_pivot() const {
  289. return Vector2();
  290. }
  291. bool PointLight2D::_edit_use_pivot() const {
  292. return true;
  293. }
  294. #endif // TOOLS_ENABLED
  295. #ifdef DEBUG_ENABLED
  296. Rect2 PointLight2D::_edit_get_rect() const {
  297. if (texture.is_null()) {
  298. return Rect2();
  299. }
  300. Size2 s = texture->get_size() * _scale;
  301. return Rect2(texture_offset - s / 2.0, s);
  302. }
  303. bool PointLight2D::_edit_use_rect() const {
  304. return texture.is_valid();
  305. }
  306. #endif // DEBUG_ENABLED
  307. Rect2 PointLight2D::get_anchorable_rect() const {
  308. if (texture.is_null()) {
  309. return Rect2();
  310. }
  311. Size2 s = texture->get_size() * _scale;
  312. return Rect2(texture_offset - s / 2.0, s);
  313. }
  314. void PointLight2D::set_texture(const Ref<Texture2D> &p_texture) {
  315. texture = p_texture;
  316. if (texture.is_valid()) {
  317. #ifdef DEBUG_ENABLED
  318. if (
  319. p_texture->is_class("AnimatedTexture") ||
  320. p_texture->is_class("AtlasTexture") ||
  321. p_texture->is_class("CameraTexture") ||
  322. p_texture->is_class("CanvasTexture") ||
  323. p_texture->is_class("MeshTexture") ||
  324. p_texture->is_class("Texture2DRD") ||
  325. p_texture->is_class("ViewportTexture")) {
  326. WARN_PRINT(vformat("%s cannot be used as a PointLight2D texture (%s). As a workaround, assign the value returned by %s's `get_image()` instead.", p_texture->get_class(), get_path(), p_texture->get_class()));
  327. }
  328. #endif
  329. RS::get_singleton()->canvas_light_set_texture(_get_light(), texture->get_rid());
  330. } else {
  331. RS::get_singleton()->canvas_light_set_texture(_get_light(), RID());
  332. }
  333. update_configuration_warnings();
  334. }
  335. Ref<Texture2D> PointLight2D::get_texture() const {
  336. return texture;
  337. }
  338. void PointLight2D::set_texture_offset(const Vector2 &p_offset) {
  339. texture_offset = p_offset;
  340. RS::get_singleton()->canvas_light_set_texture_offset(_get_light(), texture_offset);
  341. item_rect_changed();
  342. }
  343. Vector2 PointLight2D::get_texture_offset() const {
  344. return texture_offset;
  345. }
  346. PackedStringArray PointLight2D::get_configuration_warnings() const {
  347. PackedStringArray warnings = Light2D::get_configuration_warnings();
  348. if (texture.is_null()) {
  349. warnings.push_back(RTR("A texture with the shape of the light must be supplied to the \"Texture\" property."));
  350. }
  351. return warnings;
  352. }
  353. void PointLight2D::set_texture_scale(real_t p_scale) {
  354. _scale = p_scale;
  355. // Avoid having 0 scale values, can lead to errors in physics and rendering.
  356. if (_scale == 0) {
  357. _scale = CMP_EPSILON;
  358. }
  359. RS::get_singleton()->canvas_light_set_texture_scale(_get_light(), _scale);
  360. item_rect_changed();
  361. }
  362. real_t PointLight2D::get_texture_scale() const {
  363. return _scale;
  364. }
  365. #ifndef DISABLE_DEPRECATED
  366. bool PointLight2D::_set(const StringName &p_name, const Variant &p_value) {
  367. if (p_name == "mode" && p_value.is_num()) { // Compatibility with Godot 3.x.
  368. set_blend_mode((BlendMode)(int)p_value);
  369. return true;
  370. }
  371. return false;
  372. }
  373. #endif // DISABLE_DEPRECATED
  374. void PointLight2D::_bind_methods() {
  375. ClassDB::bind_method(D_METHOD("set_texture", "texture"), &PointLight2D::set_texture);
  376. ClassDB::bind_method(D_METHOD("get_texture"), &PointLight2D::get_texture);
  377. ClassDB::bind_method(D_METHOD("set_texture_offset", "texture_offset"), &PointLight2D::set_texture_offset);
  378. ClassDB::bind_method(D_METHOD("get_texture_offset"), &PointLight2D::get_texture_offset);
  379. ClassDB::bind_method(D_METHOD("set_texture_scale", "texture_scale"), &PointLight2D::set_texture_scale);
  380. ClassDB::bind_method(D_METHOD("get_texture_scale"), &PointLight2D::get_texture_scale);
  381. // Only allow texture types that display correctly.
  382. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D,-AnimatedTexture,-AtlasTexture,-CameraTexture,-CanvasTexture,-MeshTexture,-Texture2DRD,-ViewportTexture"), "set_texture", "get_texture");
  383. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset", PROPERTY_HINT_NONE, "suffix:px"), "set_texture_offset", "get_texture_offset");
  384. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "texture_scale", PROPERTY_HINT_RANGE, "0.01,50,0.01"), "set_texture_scale", "get_texture_scale");
  385. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0,1024,1,or_greater,suffix:px"), "set_height", "get_height");
  386. }
  387. PointLight2D::PointLight2D() {
  388. RS::get_singleton()->canvas_light_set_mode(_get_light(), RS::CANVAS_LIGHT_MODE_POINT);
  389. set_hide_clip_children(true);
  390. }
  391. //////////
  392. void DirectionalLight2D::set_max_distance(real_t p_distance) {
  393. max_distance = p_distance;
  394. RS::get_singleton()->canvas_light_set_directional_distance(_get_light(), max_distance);
  395. }
  396. real_t DirectionalLight2D::get_max_distance() const {
  397. return max_distance;
  398. }
  399. void DirectionalLight2D::_bind_methods() {
  400. ClassDB::bind_method(D_METHOD("set_max_distance", "pixels"), &DirectionalLight2D::set_max_distance);
  401. ClassDB::bind_method(D_METHOD("get_max_distance"), &DirectionalLight2D::get_max_distance);
  402. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_height", "get_height");
  403. 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");
  404. }
  405. DirectionalLight2D::DirectionalLight2D() {
  406. RS::get_singleton()->canvas_light_set_mode(_get_light(), RS::CANVAS_LIGHT_MODE_DIRECTIONAL);
  407. set_max_distance(max_distance); // Update RenderingServer.
  408. set_hide_clip_children(true);
  409. }