noise_texture_3d.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**************************************************************************/
  2. /* noise_texture_3d.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_3D_H
  31. #define NOISE_TEXTURE_3D_H
  32. #include "noise.h"
  33. #include "core/object/ref_counted.h"
  34. #include "scene/resources/texture.h"
  35. class NoiseTexture3D : public Texture3D {
  36. GDCLASS(NoiseTexture3D, Texture3D);
  37. private:
  38. Thread noise_thread;
  39. bool first_time = true;
  40. bool update_queued = false;
  41. bool regen_queued = false;
  42. mutable RID texture;
  43. uint32_t flags = 0;
  44. int width = 64;
  45. int height = 64;
  46. int depth = 64;
  47. bool invert = false;
  48. bool seamless = false;
  49. real_t seamless_blend_skirt = 0.1;
  50. bool normalize = true;
  51. Ref<Gradient> color_ramp;
  52. Ref<Noise> noise;
  53. Image::Format format = Image::FORMAT_L8;
  54. void _thread_done(const TypedArray<Image> &p_data);
  55. static void _thread_function(void *p_ud);
  56. void _queue_update();
  57. TypedArray<Image> _generate_texture();
  58. void _update_texture();
  59. void _set_texture_data(const TypedArray<Image> &p_data);
  60. Ref<Image> _modulate_with_gradient(Ref<Image> p_image, Ref<Gradient> p_gradient);
  61. protected:
  62. static void _bind_methods();
  63. void _validate_property(PropertyInfo &p_property) const;
  64. public:
  65. void set_noise(Ref<Noise> p_noise);
  66. Ref<Noise> get_noise();
  67. void set_width(int p_width);
  68. void set_height(int p_height);
  69. void set_depth(int p_depth);
  70. void set_invert(bool p_invert);
  71. bool get_invert() const;
  72. void set_seamless(bool p_seamless);
  73. bool get_seamless();
  74. void set_seamless_blend_skirt(real_t p_blend_skirt);
  75. real_t get_seamless_blend_skirt();
  76. void set_normalize(bool p_normalize);
  77. bool is_normalized() const;
  78. void set_color_ramp(const Ref<Gradient> &p_gradient);
  79. Ref<Gradient> get_color_ramp() const;
  80. virtual int get_width() const override;
  81. virtual int get_height() const override;
  82. virtual int get_depth() const override;
  83. virtual RID get_rid() const override;
  84. virtual Vector<Ref<Image>> get_data() const override;
  85. virtual Image::Format get_format() const override;
  86. NoiseTexture3D();
  87. virtual ~NoiseTexture3D();
  88. };
  89. #endif // NOISE_TEXTURE_3D_H