| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "noise.h" |
| 34 |
|
| 35 |
#include "core/object/ref_counted.h" |
| 36 |
#include "scene/resources/gradient.h" |
| 37 |
#include "scene/resources/texture.h" |
| 38 |
|
| 39 |
class NoiseTexture3D : public Texture3D { |
| 40 |
GDCLASS(NoiseTexture3D, Texture3D); |
| 41 |
|
| 42 |
private: |
| 43 |
Thread noise_thread; |
| 44 |
|
| 45 |
bool first_time = true; |
| 46 |
bool update_queued = false; |
| 47 |
bool regen_queued = false; |
| 48 |
|
| 49 |
mutable RID texture; |
| 50 |
uint32_t flags = 0; |
| 51 |
|
| 52 |
int width = 64; |
| 53 |
int height = 64; |
| 54 |
int depth = 64; |
| 55 |
bool invert = false; |
| 56 |
bool seamless = false; |
| 57 |
real_t seamless_blend_skirt = 0.1; |
| 58 |
bool normalize = true; |
| 59 |
|
| 60 |
Ref<Gradient> color_ramp; |
| 61 |
Ref<Noise> noise; |
| 62 |
|
| 63 |
Image::Format format = Image::FORMAT_L8; |
| 64 |
|
| 65 |
void _thread_done(const TypedArray<Image> &p_data); |
| 66 |
static void _thread_function(void *p_ud); |
| 67 |
|
| 68 |
void _queue_update(); |
| 69 |
TypedArray<Image> _generate_texture(); |
| 70 |
void _update_texture(); |
| 71 |
void _set_texture_data(const TypedArray<Image> &p_data); |
| 72 |
|
| 73 |
Ref<Image> _modulate_with_gradient(Ref<Image> p_image, Ref<Gradient> p_gradient); |
| 74 |
|
| 75 |
protected: |
| 76 |
static void _bind_methods(); |
| 77 |
void _validate_property(PropertyInfo &p_property) const; |
| 78 |
|
| 79 |
public: |
| 80 |
void set_noise(Ref<Noise> p_noise); |
| 81 |
Ref<Noise> get_noise(); |
| 82 |
|
| 83 |
void set_width(int p_width); |
| 84 |
void set_height(int p_height); |
| 85 |
void set_depth(int p_depth); |
| 86 |
|
| 87 |
void set_invert(bool p_invert); |
| 88 |
bool get_invert() const; |
| 89 |
|
| 90 |
void set_seamless(bool p_seamless); |
| 91 |
bool get_seamless(); |
| 92 |
|
| 93 |
void set_seamless_blend_skirt(real_t p_blend_skirt); |
| 94 |
real_t get_seamless_blend_skirt(); |
| 95 |
|
| 96 |
void set_normalize(bool p_normalize); |
| 97 |
bool is_normalized() const; |
| 98 |
|
| 99 |
void set_color_ramp(const Ref<Gradient> &p_gradient); |
| 100 |
Ref<Gradient> get_color_ramp() const; |
| 101 |
|
| 102 |
virtual int get_width() const override; |
| 103 |
virtual int get_height() const override; |
| 104 |
virtual int get_depth() const override; |
| 105 |
|
| 106 |
virtual bool has_mipmaps() const override; |
| 107 |
|
| 108 |
virtual RID get_rid() const override; |
| 109 |
|
| 110 |
virtual Vector<Ref<Image>> get_data() const override; |
| 111 |
virtual Image::Format get_format() const override; |
| 112 |
|
| 113 |
NoiseTexture3D(); |
| 114 |
virtual ~NoiseTexture3D(); |
| 115 |
}; |