diff options
Diffstat (limited to 'modules/opensimplex')
-rw-r--r-- | modules/opensimplex/SCsub | 2 | ||||
-rw-r--r-- | modules/opensimplex/doc_classes/NoiseTexture.xml | 8 | ||||
-rw-r--r-- | modules/opensimplex/doc_classes/OpenSimplexNoise.xml | 12 | ||||
-rw-r--r-- | modules/opensimplex/noise_texture.cpp | 30 | ||||
-rw-r--r-- | modules/opensimplex/noise_texture.h | 5 | ||||
-rw-r--r-- | modules/opensimplex/open_simplex_noise.cpp | 6 | ||||
-rw-r--r-- | modules/opensimplex/open_simplex_noise.h | 1 |
7 files changed, 55 insertions, 9 deletions
diff --git a/modules/opensimplex/SCsub b/modules/opensimplex/SCsub index 4235f6a0b9..311d33b047 100644 --- a/modules/opensimplex/SCsub +++ b/modules/opensimplex/SCsub @@ -12,7 +12,7 @@ thirdparty_sources = [ ] thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] -env_opensimplex.Append(CPPPATH=[thirdparty_dir]) +env_opensimplex.Prepend(CPPPATH=[thirdparty_dir]) env_thirdparty = env_opensimplex.Clone() env_thirdparty.disable_warnings() diff --git a/modules/opensimplex/doc_classes/NoiseTexture.xml b/modules/opensimplex/doc_classes/NoiseTexture.xml index ba54160a90..c789724fc4 100644 --- a/modules/opensimplex/doc_classes/NoiseTexture.xml +++ b/modules/opensimplex/doc_classes/NoiseTexture.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="NoiseTexture" inherits="Texture" category="Core" version="3.1"> +<class name="NoiseTexture" inherits="Texture" category="Core" version="3.2"> <brief_description> [OpenSimplexNoise] filled texture. </brief_description> @@ -9,13 +9,13 @@ </description> <tutorials> </tutorials> - <demos> - </demos> <methods> </methods> <members> <member name="as_normalmap" type="bool" setter="set_as_normalmap" getter="is_normalmap"> - If true, the resulting texture contains a normal map created from the original noise interpreted as a bump map. + If [code]true[/code], the resulting texture contains a normal map created from the original noise interpreted as a bump map. + </member> + <member name="bump_strength" type="float" setter="set_bump_strength" getter="get_bump_strength"> </member> <member name="height" type="int" setter="set_height" getter="get_height"> Height of the generated texture. diff --git a/modules/opensimplex/doc_classes/OpenSimplexNoise.xml b/modules/opensimplex/doc_classes/OpenSimplexNoise.xml index 31f13f341c..dc7fc7fe31 100644 --- a/modules/opensimplex/doc_classes/OpenSimplexNoise.xml +++ b/modules/opensimplex/doc_classes/OpenSimplexNoise.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="OpenSimplexNoise" inherits="Resource" category="Core" version="3.1"> +<class name="OpenSimplexNoise" inherits="Resource" category="Core" version="3.2"> <brief_description> Noise generator based on Open Simplex. </brief_description> @@ -23,8 +23,6 @@ </description> <tutorials> </tutorials> - <demos> - </demos> <methods> <method name="get_image"> <return type="Image"> @@ -37,6 +35,14 @@ Generate a noise image with the requested [code]width[/code] and [code]height[/code], based on the current noise parameters. </description> </method> + <method name="get_noise_1d"> + <return type="float"> + </return> + <argument index="0" name="x" type="float"> + </argument> + <description> + </description> + </method> <method name="get_noise_2d"> <return type="float"> </return> diff --git a/modules/opensimplex/noise_texture.cpp b/modules/opensimplex/noise_texture.cpp index b8126ab775..9240183265 100644 --- a/modules/opensimplex/noise_texture.cpp +++ b/modules/opensimplex/noise_texture.cpp @@ -41,6 +41,7 @@ NoiseTexture::NoiseTexture() { size = Vector2i(512, 512); seamless = false; as_normalmap = false; + bump_strength = 8.0; flags = FLAGS_DEFAULT; noise = Ref<OpenSimplexNoise>(); @@ -68,6 +69,9 @@ void NoiseTexture::_bind_methods() { ClassDB::bind_method(D_METHOD("set_as_normalmap", "as_normalmap"), &NoiseTexture::set_as_normalmap); ClassDB::bind_method(D_METHOD("is_normalmap"), &NoiseTexture::is_normalmap); + ClassDB::bind_method(D_METHOD("set_bump_strength", "bump_strength"), &NoiseTexture::set_bump_strength); + ClassDB::bind_method(D_METHOD("get_bump_strength"), &NoiseTexture::get_bump_strength); + ClassDB::bind_method(D_METHOD("_update_texture"), &NoiseTexture::_update_texture); ClassDB::bind_method(D_METHOD("_generate_texture"), &NoiseTexture::_generate_texture); ClassDB::bind_method(D_METHOD("_thread_done", "image"), &NoiseTexture::_thread_done); @@ -76,9 +80,19 @@ void NoiseTexture::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "height", PROPERTY_HINT_RANGE, "1,2048,1,or_greater"), "set_height", "get_height"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "seamless"), "set_seamless", "get_seamless"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "as_normalmap"), "set_as_normalmap", "is_normalmap"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "bump_strength", PROPERTY_HINT_RANGE, "0,32,0.1,or_greater"), "set_bump_strength", "get_bump_strength"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "noise", PROPERTY_HINT_RESOURCE_TYPE, "OpenSimplexNoise"), "set_noise", "get_noise"); } +void NoiseTexture::_validate_property(PropertyInfo &property) const { + + if (property.name == "bump_strength") { + if (!as_normalmap) { + property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; + } + } +} + void NoiseTexture::_set_texture_data(const Ref<Image> &p_image) { data = p_image; if (data.is_valid()) { @@ -129,7 +143,7 @@ Ref<Image> NoiseTexture::_generate_texture() { } if (as_normalmap) { - image->bumpmap_to_normalmap(); + image->bumpmap_to_normalmap(bump_strength); } return image; @@ -202,12 +216,26 @@ void NoiseTexture::set_as_normalmap(bool p_as_normalmap) { if (p_as_normalmap == as_normalmap) return; as_normalmap = p_as_normalmap; _queue_update(); + _change_notify(); } bool NoiseTexture::is_normalmap() { return as_normalmap; } +void NoiseTexture::set_bump_strength(float p_bump_strength) { + + if (p_bump_strength == bump_strength) return; + bump_strength = p_bump_strength; + if (as_normalmap) + _queue_update(); +} + +float NoiseTexture::get_bump_strength() { + + return bump_strength; +} + int NoiseTexture::get_width() const { return size.x; diff --git a/modules/opensimplex/noise_texture.h b/modules/opensimplex/noise_texture.h index d1705f4070..0d00ee154d 100644 --- a/modules/opensimplex/noise_texture.h +++ b/modules/opensimplex/noise_texture.h @@ -58,6 +58,7 @@ private: Vector2i size; bool seamless; bool as_normalmap; + float bump_strength; void _thread_done(const Ref<Image> &p_image); static void _thread_function(void *p_ud); @@ -69,6 +70,7 @@ private: protected: static void _bind_methods(); + virtual void _validate_property(PropertyInfo &property) const; public: void set_noise(Ref<OpenSimplexNoise> p_noise); @@ -83,6 +85,9 @@ public: void set_as_normalmap(bool p_seamless); bool is_normalmap(); + void set_bump_strength(float p_bump_strength); + float get_bump_strength(); + int get_width() const; int get_height() const; diff --git a/modules/opensimplex/open_simplex_noise.cpp b/modules/opensimplex/open_simplex_noise.cpp index b2d6b5e718..3a3a698e5c 100644 --- a/modules/opensimplex/open_simplex_noise.cpp +++ b/modules/opensimplex/open_simplex_noise.cpp @@ -173,6 +173,7 @@ void OpenSimplexNoise::_bind_methods() { ClassDB::bind_method(D_METHOD("get_image", "width", "height"), &OpenSimplexNoise::get_image); ClassDB::bind_method(D_METHOD("get_seamless_image", "size"), &OpenSimplexNoise::get_seamless_image); + ClassDB::bind_method(D_METHOD("get_noise_1d", "x"), &OpenSimplexNoise::get_noise_1d); ClassDB::bind_method(D_METHOD("get_noise_2d", "x", "y"), &OpenSimplexNoise::get_noise_2d); ClassDB::bind_method(D_METHOD("get_noise_3d", "x", "y", "z"), &OpenSimplexNoise::get_noise_3d); ClassDB::bind_method(D_METHOD("get_noise_4d", "x", "y", "z", "w"), &OpenSimplexNoise::get_noise_4d); @@ -187,6 +188,11 @@ void OpenSimplexNoise::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "lacunarity", PROPERTY_HINT_RANGE, "0.1,4.0,0.01"), "set_lacunarity", "get_lacunarity"); } +float OpenSimplexNoise::get_noise_1d(float x) { + + return get_noise_2d(x, 1.0); +} + float OpenSimplexNoise::get_noise_2d(float x, float y) { x /= period; diff --git a/modules/opensimplex/open_simplex_noise.h b/modules/opensimplex/open_simplex_noise.h index ac4c6e361f..96885f5893 100644 --- a/modules/opensimplex/open_simplex_noise.h +++ b/modules/opensimplex/open_simplex_noise.h @@ -73,6 +73,7 @@ public: Ref<Image> get_image(int p_width, int p_height); Ref<Image> get_seamless_image(int p_size); + float get_noise_1d(float x); float get_noise_2d(float x, float y); float get_noise_3d(float x, float y, float z); float get_noise_4d(float x, float y, float z, float w); |