noise_texture_2d.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**************************************************************************/
  2. /* noise_texture_2d.h */
  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. #ifndef NOISE_TEXTURE_2D_H
  31. #define NOISE_TEXTURE_2D_H
  32. #include "noise.h"
  33. #include "core/object/ref_counted.h"
  34. #include "scene/resources/texture.h"
  35. class NoiseTexture2D : public Texture2D {
  36. GDCLASS(NoiseTexture2D, Texture2D);
  37. private:
  38. Ref<Image> image;
  39. Thread noise_thread;
  40. bool first_time = true;
  41. bool update_queued = false;
  42. bool regen_queued = false;
  43. mutable RID texture;
  44. uint32_t flags = 0;
  45. Size2i size = Size2i(512, 512);
  46. bool invert = false;
  47. bool in_3d_space = false;
  48. bool generate_mipmaps = true;
  49. bool seamless = false;
  50. real_t seamless_blend_skirt = 0.1;
  51. bool as_normal_map = false;
  52. float bump_strength = 8.0;
  53. bool normalize = true;
  54. Ref<Gradient> color_ramp;
  55. Ref<Noise> noise;
  56. void _thread_done(const Ref<Image> &p_image);
  57. static void _thread_function(void *p_ud);
  58. void _queue_update();
  59. Ref<Image> _generate_texture();
  60. void _update_texture();
  61. void _set_texture_image(const Ref<Image> &p_image);
  62. Ref<Image> _modulate_with_gradient(Ref<Image> p_image, Ref<Gradient> p_gradient);
  63. protected:
  64. static void _bind_methods();
  65. void _validate_property(PropertyInfo &p_property) const;
  66. public:
  67. void set_noise(Ref<Noise> p_noise);
  68. Ref<Noise> get_noise();
  69. void set_width(int p_width);
  70. void set_height(int p_height);
  71. void set_invert(bool p_invert);
  72. bool get_invert() const;
  73. void set_in_3d_space(bool p_enable);
  74. bool is_in_3d_space() const;
  75. void set_generate_mipmaps(bool p_enable);
  76. bool is_generating_mipmaps() const;
  77. void set_seamless(bool p_seamless);
  78. bool get_seamless();
  79. void set_seamless_blend_skirt(real_t p_blend_skirt);
  80. real_t get_seamless_blend_skirt();
  81. void set_as_normal_map(bool p_as_normal_map);
  82. bool is_normal_map();
  83. void set_bump_strength(float p_bump_strength);
  84. float get_bump_strength();
  85. void set_normalize(bool p_normalize);
  86. bool is_normalized() const;
  87. void set_color_ramp(const Ref<Gradient> &p_gradient);
  88. Ref<Gradient> get_color_ramp() const;
  89. int get_width() const override;
  90. int get_height() const override;
  91. virtual RID get_rid() const override;
  92. virtual bool has_alpha() const override { return false; }
  93. virtual Ref<Image> get_image() const override;
  94. NoiseTexture2D();
  95. virtual ~NoiseTexture2D();
  96. };
  97. #endif // NOISE_TEXTURE_2D_H