summaryrefslogtreecommitdiff
path: root/modules/opensimplex
diff options
context:
space:
mode:
Diffstat (limited to 'modules/opensimplex')
-rw-r--r--modules/opensimplex/doc_classes/NoiseTexture.xml1
-rw-r--r--modules/opensimplex/doc_classes/OpenSimplexNoise.xml1
-rw-r--r--modules/opensimplex/noise_texture.cpp27
-rw-r--r--modules/opensimplex/noise_texture.h18
-rw-r--r--modules/opensimplex/open_simplex_noise.cpp12
-rw-r--r--modules/opensimplex/open_simplex_noise.h10
6 files changed, 25 insertions, 44 deletions
diff --git a/modules/opensimplex/doc_classes/NoiseTexture.xml b/modules/opensimplex/doc_classes/NoiseTexture.xml
index 7df261d2ba..86e7f9cc08 100644
--- a/modules/opensimplex/doc_classes/NoiseTexture.xml
+++ b/modules/opensimplex/doc_classes/NoiseTexture.xml
@@ -32,6 +32,7 @@
</member>
<member name="seamless" type="bool" setter="set_seamless" getter="get_seamless" default="false">
Whether the texture can be tiled without visible seams or not. Seamless textures take longer to generate.
+ [b]Note:[/b] Seamless noise has a lower contrast compared to non-seamless noise. This is due to the way noise uses higher dimensions for generating seamless noise.
</member>
<member name="width" type="int" setter="set_width" getter="get_width" default="512">
Width of the generated texture.
diff --git a/modules/opensimplex/doc_classes/OpenSimplexNoise.xml b/modules/opensimplex/doc_classes/OpenSimplexNoise.xml
index dcda5c2324..ad82f87213 100644
--- a/modules/opensimplex/doc_classes/OpenSimplexNoise.xml
+++ b/modules/opensimplex/doc_classes/OpenSimplexNoise.xml
@@ -109,6 +109,7 @@
</argument>
<description>
Generate a tileable noise image in [constant Image.FORMAT_L8] format, based on the current noise parameters. Generated seamless images are always square ([code]size[/code] × [code]size[/code]).
+ [b]Note:[/b] Seamless noise has a lower contrast compared to non-seamless noise. This is due to the way noise uses higher dimensions for generating seamless noise.
</description>
</method>
</methods>
diff --git a/modules/opensimplex/noise_texture.cpp b/modules/opensimplex/noise_texture.cpp
index 1d75e46747..f5d401b058 100644
--- a/modules/opensimplex/noise_texture.cpp
+++ b/modules/opensimplex/noise_texture.cpp
@@ -33,16 +33,6 @@
#include "core/core_string_names.h"
NoiseTexture::NoiseTexture() {
- update_queued = false;
- noise_thread = nullptr;
- regen_queued = false;
- first_time = true;
-
- size = Vector2i(512, 512);
- seamless = false;
- as_normal_map = false;
- bump_strength = 8.0;
-
noise = Ref<OpenSimplexNoise>();
_queue_update();
@@ -52,10 +42,7 @@ NoiseTexture::~NoiseTexture() {
if (texture.is_valid()) {
RS::get_singleton()->free(texture);
}
- if (noise_thread) {
- Thread::wait_to_finish(noise_thread);
- memdelete(noise_thread);
- }
+ noise_thread.wait_to_finish();
}
void NoiseTexture::_bind_methods() {
@@ -109,11 +96,9 @@ void NoiseTexture::_set_texture_data(const Ref<Image> &p_image) {
void NoiseTexture::_thread_done(const Ref<Image> &p_image) {
_set_texture_data(p_image);
- Thread::wait_to_finish(noise_thread);
- memdelete(noise_thread);
- noise_thread = nullptr;
+ noise_thread.wait_to_finish();
if (regen_queued) {
- noise_thread = Thread::create(_thread_function, this);
+ noise_thread.start(_thread_function, this);
regen_queued = false;
}
}
@@ -165,8 +150,8 @@ void NoiseTexture::_update_texture() {
use_thread = false;
#endif
if (use_thread) {
- if (!noise_thread) {
- noise_thread = Thread::create(_thread_function, this);
+ if (!noise_thread.is_started()) {
+ noise_thread.start(_thread_function, this);
regen_queued = false;
} else {
regen_queued = true;
@@ -231,7 +216,7 @@ void NoiseTexture::set_as_normal_map(bool p_as_normal_map) {
}
as_normal_map = p_as_normal_map;
_queue_update();
- _change_notify();
+ notify_property_list_changed();
}
bool NoiseTexture::is_normal_map() {
diff --git a/modules/opensimplex/noise_texture.h b/modules/opensimplex/noise_texture.h
index 9f6e2cbf43..e89479d962 100644
--- a/modules/opensimplex/noise_texture.h
+++ b/modules/opensimplex/noise_texture.h
@@ -45,20 +45,20 @@ class NoiseTexture : public Texture2D {
private:
Ref<Image> data;
- Thread *noise_thread;
+ Thread noise_thread;
- bool first_time;
- bool update_queued;
- bool regen_queued;
+ bool first_time = true;
+ bool update_queued = false;
+ bool regen_queued = false;
mutable RID texture;
- uint32_t flags;
+ uint32_t flags = 0;
Ref<OpenSimplexNoise> noise;
- Vector2i size;
- bool seamless;
- bool as_normal_map;
- float bump_strength;
+ Vector2i size = Vector2i(512, 512);
+ bool seamless = false;
+ bool as_normal_map = false;
+ float bump_strength = 8.0;
void _thread_done(const Ref<Image> &p_image);
static void _thread_function(void *p_ud);
diff --git a/modules/opensimplex/open_simplex_noise.cpp b/modules/opensimplex/open_simplex_noise.cpp
index e4e2e0613a..3773946112 100644
--- a/modules/opensimplex/open_simplex_noise.cpp
+++ b/modules/opensimplex/open_simplex_noise.cpp
@@ -33,12 +33,6 @@
#include "core/core_string_names.h"
OpenSimplexNoise::OpenSimplexNoise() {
- seed = 0;
- persistence = 0.5;
- octaves = 3;
- period = 64;
- lacunarity = 2.0;
-
_init_seeds();
}
@@ -131,10 +125,10 @@ Ref<Image> OpenSimplexNoise::get_seamless_image(int p_size) const {
float ii = (float)i / (float)p_size;
float jj = (float)j / (float)p_size;
- ii *= 2.0 * Math_PI;
- jj *= 2.0 * Math_PI;
+ ii *= Math_TAU;
+ jj *= Math_TAU;
- float radius = p_size / (2.0 * Math_PI);
+ float radius = p_size / Math_TAU;
float x = radius * Math::sin(jj);
float y = radius * Math::cos(jj);
diff --git a/modules/opensimplex/open_simplex_noise.h b/modules/opensimplex/open_simplex_noise.h
index f18dd4d798..847c157409 100644
--- a/modules/opensimplex/open_simplex_noise.h
+++ b/modules/opensimplex/open_simplex_noise.h
@@ -48,11 +48,11 @@ class OpenSimplexNoise : public Resource {
osn_context contexts[MAX_OCTAVES];
- int seed;
- float persistence; // Controls details, value in [0,1]. Higher increases grain, lower increases smoothness.
- int octaves; // Number of noise layers
- float period; // Distance above which we start to see similarities. The higher, the longer "hills" will be on a terrain.
- float lacunarity; // Controls period change across octaves. 2 is usually a good value to address all detail levels.
+ int seed = 0;
+ float persistence = 0.5; // Controls details, value in [0,1]. Higher increases grain, lower increases smoothness.
+ int octaves = 3; // Number of noise layers
+ float period = 64.0; // Distance above which we start to see similarities. The higher, the longer "hills" will be on a terrain.
+ float lacunarity = 2.0; // Controls period change across octaves. 2 is usually a good value to address all detail levels.
public:
OpenSimplexNoise();