| 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 NoiseTexture2D : public Texture2D { |
| 40 |
GDCLASS(NoiseTexture2D, Texture2D); |
| 41 |
|
| 42 |
private: |
| 43 |
Ref<Image> image; |
| 44 |
|
| 45 |
Thread noise_thread; |
| 46 |
|
| 47 |
bool first_time = true; |
| 48 |
bool update_queued = false; |
| 49 |
bool regen_queued = false; |
| 50 |
|
| 51 |
mutable RID texture; |
| 52 |
uint32_t flags = 0; |
| 53 |
|
| 54 |
Size2i size = Size2i(512, 512); |
| 55 |
bool invert = false; |
| 56 |
bool in_3d_space = false; |
| 57 |
bool generate_mipmaps = true; |
| 58 |
bool seamless = false; |
| 59 |
real_t seamless_blend_skirt = 0.1; |
| 60 |
bool as_normal_map = false; |
| 61 |
float bump_strength = 8.0; |
| 62 |
bool normalize = true; |
| 63 |
|
| 64 |
Ref<Gradient> color_ramp; |
| 65 |
Ref<Noise> noise; |
| 66 |
|
| 67 |
void _thread_done(const Ref<Image> &p_image); |
| 68 |
static void _thread_function(void *p_ud); |
| 69 |
|
| 70 |
void _queue_update(); |
| 71 |
Ref<Image> _generate_texture(); |
| 72 |
void _update_texture(); |
| 73 |
void _set_texture_image(const Ref<Image> &p_image); |
| 74 |
|
| 75 |
Ref<Image> _modulate_with_gradient(Ref<Image> p_image, Ref<Gradient> p_gradient); |
| 76 |
|
| 77 |
protected: |
| 78 |
static void _bind_methods(); |
| 79 |
void _validate_property(PropertyInfo &p_property) const; |
| 80 |
|
| 81 |
public: |
| 82 |
void set_noise(Ref<Noise> p_noise); |
| 83 |
Ref<Noise> get_noise(); |
| 84 |
|
| 85 |
void set_width(int p_width); |
| 86 |
void set_height(int p_height); |
| 87 |
|
| 88 |
void set_invert(bool p_invert); |
| 89 |
bool get_invert() const; |
| 90 |
|
| 91 |
void set_in_3d_space(bool p_enable); |
| 92 |
bool is_in_3d_space() const; |
| 93 |
|
| 94 |
void set_generate_mipmaps(bool p_enable); |
| 95 |
bool is_generating_mipmaps() const; |
| 96 |
|
| 97 |
void set_seamless(bool p_seamless); |
| 98 |
bool get_seamless(); |
| 99 |
|
| 100 |
void set_seamless_blend_skirt(real_t p_blend_skirt); |
| 101 |
real_t get_seamless_blend_skirt(); |
| 102 |
|
| 103 |
void set_as_normal_map(bool p_as_normal_map); |
| 104 |
bool is_normal_map(); |
| 105 |
|
| 106 |
void set_bump_strength(float p_bump_strength); |
| 107 |
float get_bump_strength(); |
| 108 |
|
| 109 |
void set_normalize(bool p_normalize); |
| 110 |
bool is_normalized() const; |
| 111 |
|
| 112 |
void set_color_ramp(const Ref<Gradient> &p_gradient); |
| 113 |
Ref<Gradient> get_color_ramp() const; |
| 114 |
|
| 115 |
int get_width() const override; |
| 116 |
int get_height() const override; |
| 117 |
|
| 118 |
virtual RID get_rid() const override; |
| 119 |
virtual bool has_alpha() const override { return false; } |
| 120 |
|
| 121 |
virtual Ref<Image> get_image() const override; |
| 122 |
|
| 123 |
NoiseTexture2D(); |
| 124 |
virtual ~NoiseTexture2D(); |
| 125 |
}; |