Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/noise/noise_texture_3d.h
10278 views
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
31
#pragma once
32
33
#include "noise.h"
34
35
#include "core/object/ref_counted.h"
36
#include "scene/resources/texture.h"
37
38
class NoiseTexture3D : public Texture3D {
39
GDCLASS(NoiseTexture3D, Texture3D);
40
41
private:
42
Thread noise_thread;
43
44
bool first_time = true;
45
bool update_queued = false;
46
bool regen_queued = false;
47
48
mutable RID texture;
49
uint32_t flags = 0;
50
51
int width = 64;
52
int height = 64;
53
int depth = 64;
54
bool invert = false;
55
bool seamless = false;
56
real_t seamless_blend_skirt = 0.1;
57
bool normalize = true;
58
59
Ref<Gradient> color_ramp;
60
Ref<Noise> noise;
61
62
Image::Format format = Image::FORMAT_L8;
63
64
void _thread_done(const TypedArray<Image> &p_data);
65
static void _thread_function(void *p_ud);
66
67
void _queue_update();
68
TypedArray<Image> _generate_texture();
69
void _update_texture();
70
void _set_texture_data(const TypedArray<Image> &p_data);
71
72
Ref<Image> _modulate_with_gradient(Ref<Image> p_image, Ref<Gradient> p_gradient);
73
74
protected:
75
static void _bind_methods();
76
void _validate_property(PropertyInfo &p_property) const;
77
78
public:
79
void set_noise(Ref<Noise> p_noise);
80
Ref<Noise> get_noise();
81
82
void set_width(int p_width);
83
void set_height(int p_height);
84
void set_depth(int p_depth);
85
86
void set_invert(bool p_invert);
87
bool get_invert() const;
88
89
void set_seamless(bool p_seamless);
90
bool get_seamless();
91
92
void set_seamless_blend_skirt(real_t p_blend_skirt);
93
real_t get_seamless_blend_skirt();
94
95
void set_normalize(bool p_normalize);
96
bool is_normalized() const;
97
98
void set_color_ramp(const Ref<Gradient> &p_gradient);
99
Ref<Gradient> get_color_ramp() const;
100
101
virtual int get_width() const override;
102
virtual int get_height() const override;
103
virtual int get_depth() const override;
104
105
virtual bool has_mipmaps() const override;
106
107
virtual RID get_rid() const override;
108
109
virtual Vector<Ref<Image>> get_data() const override;
110
virtual Image::Format get_format() const override;
111
112
NoiseTexture3D();
113
virtual ~NoiseTexture3D();
114
};
115
116