noise_texture.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*************************************************************************/
  2. /* noise_texture.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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. #ifndef NOISE_TEXTURE_H
  31. #define NOISE_TEXTURE_H
  32. #include "open_simplex_noise.h"
  33. #include "core/image.h"
  34. #include "core/reference.h"
  35. #include "editor/editor_node.h"
  36. #include "editor/editor_plugin.h"
  37. #include "editor/property_editor.h"
  38. class NoiseTexture : public Texture {
  39. GDCLASS(NoiseTexture, Texture)
  40. private:
  41. Ref<Image> data;
  42. Thread *noise_thread;
  43. bool first_time;
  44. bool update_queued;
  45. bool regen_queued;
  46. RID texture;
  47. uint32_t flags;
  48. Ref<OpenSimplexNoise> noise;
  49. Vector2i size;
  50. bool seamless;
  51. bool as_normalmap;
  52. float bump_strength;
  53. void _thread_done(const Ref<Image> &p_image);
  54. static void _thread_function(void *p_ud);
  55. void _queue_update();
  56. Ref<Image> _generate_texture();
  57. void _update_texture();
  58. void _set_texture_data(const Ref<Image> &p_image);
  59. protected:
  60. static void _bind_methods();
  61. virtual void _validate_property(PropertyInfo &property) const;
  62. public:
  63. void set_noise(Ref<OpenSimplexNoise> p_noise);
  64. Ref<OpenSimplexNoise> get_noise();
  65. void set_width(int p_width);
  66. void set_height(int p_hieght);
  67. void set_seamless(bool p_seamless);
  68. bool get_seamless();
  69. void set_as_normalmap(bool p_seamless);
  70. bool is_normalmap();
  71. void set_bump_strength(float p_bump_strength);
  72. float get_bump_strength();
  73. int get_width() const;
  74. int get_height() const;
  75. virtual void set_flags(uint32_t p_flags);
  76. virtual uint32_t get_flags() const;
  77. virtual RID get_rid() const { return texture; }
  78. virtual bool has_alpha() const { return false; }
  79. virtual Ref<Image> get_data() const;
  80. NoiseTexture();
  81. virtual ~NoiseTexture();
  82. };
  83. #endif // NOISE_TEXTURE_H