diff options
Diffstat (limited to 'modules/opensimplex')
-rw-r--r-- | modules/opensimplex/SCsub | 33 | ||||
-rw-r--r-- | modules/opensimplex/config.py | 17 | ||||
-rw-r--r-- | modules/opensimplex/doc_classes/NoiseTexture.xml | 44 | ||||
-rw-r--r-- | modules/opensimplex/doc_classes/OpenSimplexNoise.xml | 112 | ||||
-rw-r--r-- | modules/opensimplex/icons/NoiseTexture.svg | 1 | ||||
-rw-r--r-- | modules/opensimplex/noise_texture.cpp | 276 | ||||
-rw-r--r-- | modules/opensimplex/noise_texture.h | 107 | ||||
-rw-r--r-- | modules/opensimplex/open_simplex_noise.cpp | 250 | ||||
-rw-r--r-- | modules/opensimplex/open_simplex_noise.h | 99 | ||||
-rw-r--r-- | modules/opensimplex/register_types.cpp | 41 | ||||
-rw-r--r-- | modules/opensimplex/register_types.h | 37 |
11 files changed, 0 insertions, 1017 deletions
diff --git a/modules/opensimplex/SCsub b/modules/opensimplex/SCsub deleted file mode 100644 index 86d77c3dfb..0000000000 --- a/modules/opensimplex/SCsub +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env python - -Import("env") -Import("env_modules") - -env_opensimplex = env_modules.Clone() - -# Thirdparty source files - -thirdparty_obj = [] - -thirdparty_dir = "#thirdparty/misc/" -thirdparty_sources = [ - "open-simplex-noise.c", -] -thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] - -env_opensimplex.Prepend(CPPPATH=[thirdparty_dir]) - -env_thirdparty = env_opensimplex.Clone() -env_thirdparty.disable_warnings() -env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources) -env.modules_sources += thirdparty_obj - -# Godot source files - -module_obj = [] - -env_opensimplex.add_source_files(module_obj, "*.cpp") -env.modules_sources += module_obj - -# Needed to force rebuilding the module files when the thirdparty library is updated. -env.Depends(module_obj, thirdparty_obj) diff --git a/modules/opensimplex/config.py b/modules/opensimplex/config.py deleted file mode 100644 index 90b85dbd70..0000000000 --- a/modules/opensimplex/config.py +++ /dev/null @@ -1,17 +0,0 @@ -def can_build(env, platform): - return True - - -def configure(env): - pass - - -def get_doc_classes(): - return [ - "NoiseTexture", - "OpenSimplexNoise", - ] - - -def get_doc_path(): - return "doc_classes" diff --git a/modules/opensimplex/doc_classes/NoiseTexture.xml b/modules/opensimplex/doc_classes/NoiseTexture.xml deleted file mode 100644 index 16fea228b1..0000000000 --- a/modules/opensimplex/doc_classes/NoiseTexture.xml +++ /dev/null @@ -1,44 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="NoiseTexture" inherits="Texture2D" version="4.0"> - <brief_description> - [OpenSimplexNoise] filled texture. - </brief_description> - <description> - Uses an [OpenSimplexNoise] to fill the texture data. You can specify the texture size but keep in mind that larger textures will take longer to generate and seamless noise only works with square sized textures. - NoiseTexture can also generate normal map textures. - The class uses [Thread]s to generate the texture data internally, so [method Texture2D.get_image] may return [code]null[/code] if the generation process has not completed yet. In that case, you need to wait for the texture to be generated before accessing the image and the generated byte data: - [codeblock] - var texture = NoiseTexture.new() - texture.noise = OpenSimplexNoise.new() - await texture.changed - var image = texture.get_image() - var data = image.get_data() - [/codeblock] - </description> - <tutorials> - </tutorials> - <members> - <member name="as_normal_map" type="bool" setter="set_as_normal_map" getter="is_normal_map" default="false"> - 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" default="8.0"> - Strength of the bump maps used in this texture. A higher value will make the bump maps appear larger while a lower value will make them appear softer. - </member> - <member name="height" type="int" setter="set_height" getter="get_height" default="512"> - Height of the generated texture. - </member> - <member name="noise" type="OpenSimplexNoise" setter="set_noise" getter="get_noise"> - The [OpenSimplexNoise] instance used to generate the noise. - </member> - <member name="noise_offset" type="Vector2" setter="set_noise_offset" getter="get_noise_offset" default="Vector2(0, 0)"> - An offset used to specify the noise space coordinate of the top left corner of the generated noise. This value is ignored if [member seamless] is enabled. - </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. - </member> - </members> -</class> diff --git a/modules/opensimplex/doc_classes/OpenSimplexNoise.xml b/modules/opensimplex/doc_classes/OpenSimplexNoise.xml deleted file mode 100644 index 604b07b645..0000000000 --- a/modules/opensimplex/doc_classes/OpenSimplexNoise.xml +++ /dev/null @@ -1,112 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="OpenSimplexNoise" inherits="Resource" version="4.0"> - <brief_description> - Noise generator based on Open Simplex. - </brief_description> - <description> - This resource allows you to configure and sample a fractal noise space. Here is a brief usage example that configures an OpenSimplexNoise and gets samples at various positions and dimensions: - [codeblock] - var noise = OpenSimplexNoise.new() - - # Configure - noise.seed = randi() - noise.octaves = 4 - noise.period = 20.0 - noise.persistence = 0.8 - - # Sample - print("Values:") - print(noise.get_noise_2d(1.0, 1.0)) - print(noise.get_noise_3d(0.5, 3.0, 15.0)) - print(noise.get_noise_4d(0.5, 1.9, 4.7, 0.0)) - [/codeblock] - </description> - <tutorials> - </tutorials> - <methods> - <method name="get_image" qualifiers="const"> - <return type="Image" /> - <argument index="0" name="width" type="int" /> - <argument index="1" name="height" type="int" /> - <argument index="2" name="noise_offset" type="Vector2" default="Vector2(0, 0)" /> - <description> - Generate a noise image in [constant Image.FORMAT_L8] format with the requested [code]width[/code] and [code]height[/code], based on the current noise parameters. If [code]noise_offset[/code] is specified, then the offset value is used as the coordinates of the top-left corner of the generated noise. - </description> - </method> - <method name="get_noise_1d" qualifiers="const"> - <return type="float" /> - <argument index="0" name="x" type="float" /> - <description> - Returns the 1D noise value [code][-1,1][/code] at the given x-coordinate. - [b]Note:[/b] This method actually returns the 2D noise value [code][-1,1][/code] with fixed y-coordinate value 0.0. - </description> - </method> - <method name="get_noise_2d" qualifiers="const"> - <return type="float" /> - <argument index="0" name="x" type="float" /> - <argument index="1" name="y" type="float" /> - <description> - Returns the 2D noise value [code][-1,1][/code] at the given position. - </description> - </method> - <method name="get_noise_2dv" qualifiers="const"> - <return type="float" /> - <argument index="0" name="pos" type="Vector2" /> - <description> - Returns the 2D noise value [code][-1,1][/code] at the given position. - </description> - </method> - <method name="get_noise_3d" qualifiers="const"> - <return type="float" /> - <argument index="0" name="x" type="float" /> - <argument index="1" name="y" type="float" /> - <argument index="2" name="z" type="float" /> - <description> - Returns the 3D noise value [code][-1,1][/code] at the given position. - </description> - </method> - <method name="get_noise_3dv" qualifiers="const"> - <return type="float" /> - <argument index="0" name="pos" type="Vector3" /> - <description> - Returns the 3D noise value [code][-1,1][/code] at the given position. - </description> - </method> - <method name="get_noise_4d" qualifiers="const"> - <return type="float" /> - <argument index="0" name="x" type="float" /> - <argument index="1" name="y" type="float" /> - <argument index="2" name="z" type="float" /> - <argument index="3" name="w" type="float" /> - <description> - Returns the 4D noise value [code][-1,1][/code] at the given position. - </description> - </method> - <method name="get_seamless_image" qualifiers="const"> - <return type="Image" /> - <argument index="0" name="size" type="int" /> - <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> - <members> - <member name="lacunarity" type="float" setter="set_lacunarity" getter="get_lacunarity" default="2.0"> - Difference in period between [member octaves]. - </member> - <member name="octaves" type="int" setter="set_octaves" getter="get_octaves" default="3"> - Number of OpenSimplex noise layers that are sampled to get the fractal noise. Higher values result in more detailed noise but take more time to generate. - [b]Note:[/b] The maximum allowed value is 9. - </member> - <member name="period" type="float" setter="set_period" getter="get_period" default="64.0"> - Period of the base octave. A lower period results in a higher-frequency noise (more value changes across the same distance). - </member> - <member name="persistence" type="float" setter="set_persistence" getter="get_persistence" default="0.5"> - Contribution factor of the different octaves. A [code]persistence[/code] value of 1 means all the octaves have the same contribution, a value of 0.5 means each octave contributes half as much as the previous one. - </member> - <member name="seed" type="int" setter="set_seed" getter="get_seed" default="0"> - Seed used to generate random values, different seeds will generate different noise maps. - </member> - </members> -</class> diff --git a/modules/opensimplex/icons/NoiseTexture.svg b/modules/opensimplex/icons/NoiseTexture.svg deleted file mode 100644 index 479684cde2..0000000000 --- a/modules/opensimplex/icons/NoiseTexture.svg +++ /dev/null @@ -1 +0,0 @@ -<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m2 1c-.55228 0-1 .44772-1 1v12c0 .55228.44772 1 1 1h12c.55228 0 1-.44772 1-1v-12c0-.55228-.44772-1-1-1zm1 2h10v8h-10zm3 1v2h2v-2zm2 2v2h2v2h2v-6h-2v2zm0 2h-2v-2h-2v4h4z" fill="#e0e0e0" fill-opacity=".99608"/></svg> diff --git a/modules/opensimplex/noise_texture.cpp b/modules/opensimplex/noise_texture.cpp deleted file mode 100644 index e36dcfcea5..0000000000 --- a/modules/opensimplex/noise_texture.cpp +++ /dev/null @@ -1,276 +0,0 @@ -/*************************************************************************/ -/* noise_texture.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "noise_texture.h" - -#include "core/core_string_names.h" - -NoiseTexture::NoiseTexture() { - noise = Ref<OpenSimplexNoise>(); - - _queue_update(); -} - -NoiseTexture::~NoiseTexture() { - if (texture.is_valid()) { - RS::get_singleton()->free(texture); - } - noise_thread.wait_to_finish(); -} - -void NoiseTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_width", "width"), &NoiseTexture::set_width); - ClassDB::bind_method(D_METHOD("set_height", "height"), &NoiseTexture::set_height); - - ClassDB::bind_method(D_METHOD("set_noise", "noise"), &NoiseTexture::set_noise); - ClassDB::bind_method(D_METHOD("get_noise"), &NoiseTexture::get_noise); - - ClassDB::bind_method(D_METHOD("set_noise_offset", "noise_offset"), &NoiseTexture::set_noise_offset); - ClassDB::bind_method(D_METHOD("get_noise_offset"), &NoiseTexture::get_noise_offset); - - ClassDB::bind_method(D_METHOD("set_seamless", "seamless"), &NoiseTexture::set_seamless); - ClassDB::bind_method(D_METHOD("get_seamless"), &NoiseTexture::get_seamless); - - ClassDB::bind_method(D_METHOD("set_as_normal_map", "as_normal_map"), &NoiseTexture::set_as_normal_map); - ClassDB::bind_method(D_METHOD("is_normal_map"), &NoiseTexture::is_normal_map); - - 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); - - ADD_PROPERTY(PropertyInfo(Variant::INT, "width", PROPERTY_HINT_RANGE, "1,2048,1,or_greater"), "set_width", "get_width"); - 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_normal_map"), "set_as_normal_map", "is_normal_map"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "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"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "noise_offset"), "set_noise_offset", "get_noise_offset"); -} - -void NoiseTexture::_validate_property(PropertyInfo &property) const { - if (property.name == "bump_strength") { - if (!as_normal_map) { - property.usage = PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL; - } - } -} - -void NoiseTexture::_set_texture_image(const Ref<Image> &p_image) { - image = p_image; - if (image.is_valid()) { - if (texture.is_valid()) { - RID new_texture = RS::get_singleton()->texture_2d_create(p_image); - RS::get_singleton()->texture_replace(texture, new_texture); - } else { - texture = RS::get_singleton()->texture_2d_create(p_image); - } - } - emit_changed(); -} - -void NoiseTexture::_thread_done(const Ref<Image> &p_image) { - _set_texture_image(p_image); - noise_thread.wait_to_finish(); - if (regen_queued) { - noise_thread.start(_thread_function, this); - regen_queued = false; - } -} - -void NoiseTexture::_thread_function(void *p_ud) { - NoiseTexture *tex = (NoiseTexture *)p_ud; - tex->call_deferred(SNAME("_thread_done"), tex->_generate_texture()); -} - -void NoiseTexture::_queue_update() { - if (update_queued) { - return; - } - - update_queued = true; - call_deferred(SNAME("_update_texture")); -} - -Ref<Image> NoiseTexture::_generate_texture() { - // Prevent memdelete due to unref() on other thread. - Ref<OpenSimplexNoise> ref_noise = noise; - - if (ref_noise.is_null()) { - return Ref<Image>(); - } - - Ref<Image> image; - - if (seamless) { - image = ref_noise->get_seamless_image(size.x); - } else { - image = ref_noise->get_image(size.x, size.y, noise_offset); - } - - if (as_normal_map) { - image->bump_map_to_normal_map(bump_strength); - } - - return image; -} - -void NoiseTexture::_update_texture() { - bool use_thread = true; - if (first_time) { - use_thread = false; - first_time = false; - } -#ifdef NO_THREADS - use_thread = false; -#endif - if (use_thread) { - if (!noise_thread.is_started()) { - noise_thread.start(_thread_function, this); - regen_queued = false; - } else { - regen_queued = true; - } - - } else { - Ref<Image> image = _generate_texture(); - _set_texture_image(image); - } - update_queued = false; -} - -void NoiseTexture::set_noise(Ref<OpenSimplexNoise> p_noise) { - if (p_noise == noise) { - return; - } - if (noise.is_valid()) { - noise->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &NoiseTexture::_queue_update)); - } - noise = p_noise; - if (noise.is_valid()) { - noise->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &NoiseTexture::_queue_update)); - } - _queue_update(); -} - -Ref<OpenSimplexNoise> NoiseTexture::get_noise() { - return noise; -} - -void NoiseTexture::set_width(int p_width) { - ERR_FAIL_COND(p_width <= 0); - if (p_width == size.x) { - return; - } - size.x = p_width; - _queue_update(); -} - -void NoiseTexture::set_height(int p_height) { - ERR_FAIL_COND(p_height <= 0); - if (p_height == size.y) { - return; - } - size.y = p_height; - _queue_update(); -} - -void NoiseTexture::set_noise_offset(Vector2 p_noise_offset) { - if (noise_offset == p_noise_offset) { - return; - } - noise_offset = p_noise_offset; - _queue_update(); -} - -void NoiseTexture::set_seamless(bool p_seamless) { - if (p_seamless == seamless) { - return; - } - seamless = p_seamless; - _queue_update(); -} - -bool NoiseTexture::get_seamless() { - return seamless; -} - -void NoiseTexture::set_as_normal_map(bool p_as_normal_map) { - if (p_as_normal_map == as_normal_map) { - return; - } - as_normal_map = p_as_normal_map; - _queue_update(); - notify_property_list_changed(); -} - -bool NoiseTexture::is_normal_map() { - return as_normal_map; -} - -void NoiseTexture::set_bump_strength(float p_bump_strength) { - if (p_bump_strength == bump_strength) { - return; - } - bump_strength = p_bump_strength; - if (as_normal_map) { - _queue_update(); - } -} - -float NoiseTexture::get_bump_strength() { - return bump_strength; -} - -int NoiseTexture::get_width() const { - return size.x; -} - -int NoiseTexture::get_height() const { - return size.y; -} - -Vector2 NoiseTexture::get_noise_offset() const { - return noise_offset; -} - -RID NoiseTexture::get_rid() const { - if (!texture.is_valid()) { - texture = RS::get_singleton()->texture_2d_placeholder_create(); - } - - return texture; -} - -Ref<Image> NoiseTexture::get_image() const { - return image; -} diff --git a/modules/opensimplex/noise_texture.h b/modules/opensimplex/noise_texture.h deleted file mode 100644 index 6237b6460d..0000000000 --- a/modules/opensimplex/noise_texture.h +++ /dev/null @@ -1,107 +0,0 @@ -/*************************************************************************/ -/* noise_texture.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef NOISE_TEXTURE_H -#define NOISE_TEXTURE_H - -#include "open_simplex_noise.h" - -#include "core/io/image.h" -#include "core/object/ref_counted.h" -#include "editor/editor_node.h" -#include "editor/editor_plugin.h" -#include "editor/property_editor.h" - -class NoiseTexture : public Texture2D { - GDCLASS(NoiseTexture, Texture2D); - -private: - Ref<Image> image; - - Thread noise_thread; - - bool first_time = true; - bool update_queued = false; - bool regen_queued = false; - - mutable RID texture; - uint32_t flags = 0; - - Ref<OpenSimplexNoise> noise; - Vector2i size = Vector2i(512, 512); - Vector2 noise_offset; - 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); - - void _queue_update(); - Ref<Image> _generate_texture(); - void _update_texture(); - void _set_texture_image(const Ref<Image> &p_image); - -protected: - static void _bind_methods(); - virtual void _validate_property(PropertyInfo &property) const override; - -public: - void set_noise(Ref<OpenSimplexNoise> p_noise); - Ref<OpenSimplexNoise> get_noise(); - - void set_width(int p_width); - void set_height(int p_height); - - void set_noise_offset(Vector2 p_noise_offset); - Vector2 get_noise_offset() const; - - void set_seamless(bool p_seamless); - bool get_seamless(); - - void set_as_normal_map(bool p_as_normal_map); - bool is_normal_map(); - - void set_bump_strength(float p_bump_strength); - float get_bump_strength(); - - int get_width() const override; - int get_height() const override; - - virtual RID get_rid() const override; - virtual bool has_alpha() const override { return false; } - - virtual Ref<Image> get_image() const override; - - NoiseTexture(); - virtual ~NoiseTexture(); -}; - -#endif // NOISE_TEXTURE_H diff --git a/modules/opensimplex/open_simplex_noise.cpp b/modules/opensimplex/open_simplex_noise.cpp deleted file mode 100644 index f0a8867284..0000000000 --- a/modules/opensimplex/open_simplex_noise.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/*************************************************************************/ -/* open_simplex_noise.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "open_simplex_noise.h" - -#include "core/core_string_names.h" - -OpenSimplexNoise::OpenSimplexNoise() { - _init_seeds(); -} - -OpenSimplexNoise::~OpenSimplexNoise() { -} - -void OpenSimplexNoise::_init_seeds() { - for (int i = 0; i < MAX_OCTAVES; ++i) { - open_simplex_noise(seed + i * 2, &(contexts[i])); - } -} - -void OpenSimplexNoise::set_seed(int p_seed) { - if (seed == p_seed) { - return; - } - - seed = p_seed; - - _init_seeds(); - - emit_changed(); -} - -int OpenSimplexNoise::get_seed() const { - return seed; -} - -void OpenSimplexNoise::set_octaves(int p_octaves) { - if (p_octaves == octaves) { - return; - } - - ERR_FAIL_COND_MSG(p_octaves > MAX_OCTAVES, vformat("The number of OpenSimplexNoise octaves is limited to %d; ignoring the new value.", MAX_OCTAVES)); - - octaves = CLAMP(p_octaves, 1, MAX_OCTAVES); - emit_changed(); -} - -void OpenSimplexNoise::set_period(float p_period) { - if (p_period == period) { - return; - } - period = p_period; - emit_changed(); -} - -void OpenSimplexNoise::set_persistence(float p_persistence) { - if (p_persistence == persistence) { - return; - } - persistence = p_persistence; - emit_changed(); -} - -void OpenSimplexNoise::set_lacunarity(float p_lacunarity) { - if (p_lacunarity == lacunarity) { - return; - } - lacunarity = p_lacunarity; - emit_changed(); -} - -Ref<Image> OpenSimplexNoise::get_image(int p_width, int p_height, const Vector2 &p_noise_offset) const { - Vector<uint8_t> data; - data.resize(p_width * p_height); - - uint8_t *wd8 = data.ptrw(); - - for (int i = 0; i < p_height; i++) { - for (int j = 0; j < p_width; j++) { - float v = get_noise_2d(float(j) + p_noise_offset.x, float(i) + p_noise_offset.y); - v = v * 0.5 + 0.5; // Normalize [0..1] - wd8[(i * p_width + j)] = uint8_t(CLAMP(v * 255.0, 0, 255)); - } - } - - Ref<Image> image = memnew(Image(p_width, p_height, false, Image::FORMAT_L8, data)); - return image; -} - -Ref<Image> OpenSimplexNoise::get_seamless_image(int p_size) const { - Vector<uint8_t> data; - data.resize(p_size * p_size); - - uint8_t *wd8 = data.ptrw(); - - for (int i = 0; i < p_size; i++) { - for (int j = 0; j < p_size; j++) { - float ii = (float)i / (float)p_size; - float jj = (float)j / (float)p_size; - - ii *= Math_TAU; - jj *= Math_TAU; - - float radius = p_size / Math_TAU; - - float x = radius * Math::sin(jj); - float y = radius * Math::cos(jj); - float z = radius * Math::sin(ii); - float w = radius * Math::cos(ii); - float v = get_noise_4d(x, y, z, w); - - v = v * 0.5 + 0.5; // Normalize [0..1] - wd8[(i * p_size + j)] = uint8_t(CLAMP(v * 255.0, 0, 255)); - } - } - - Ref<Image> image = memnew(Image(p_size, p_size, false, Image::FORMAT_L8, data)); - return image; -} - -void OpenSimplexNoise::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_seed"), &OpenSimplexNoise::get_seed); - ClassDB::bind_method(D_METHOD("set_seed", "seed"), &OpenSimplexNoise::set_seed); - - ClassDB::bind_method(D_METHOD("set_octaves", "octave_count"), &OpenSimplexNoise::set_octaves); - ClassDB::bind_method(D_METHOD("get_octaves"), &OpenSimplexNoise::get_octaves); - - ClassDB::bind_method(D_METHOD("set_period", "period"), &OpenSimplexNoise::set_period); - ClassDB::bind_method(D_METHOD("get_period"), &OpenSimplexNoise::get_period); - - ClassDB::bind_method(D_METHOD("set_persistence", "persistence"), &OpenSimplexNoise::set_persistence); - ClassDB::bind_method(D_METHOD("get_persistence"), &OpenSimplexNoise::get_persistence); - - ClassDB::bind_method(D_METHOD("set_lacunarity", "lacunarity"), &OpenSimplexNoise::set_lacunarity); - ClassDB::bind_method(D_METHOD("get_lacunarity"), &OpenSimplexNoise::get_lacunarity); - - ClassDB::bind_method(D_METHOD("get_image", "width", "height", "noise_offset"), &OpenSimplexNoise::get_image, DEFVAL(Vector2())); - 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); - - ClassDB::bind_method(D_METHOD("get_noise_2dv", "pos"), &OpenSimplexNoise::get_noise_2dv); - ClassDB::bind_method(D_METHOD("get_noise_3dv", "pos"), &OpenSimplexNoise::get_noise_3dv); - - ADD_PROPERTY(PropertyInfo(Variant::INT, "seed"), "set_seed", "get_seed"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "octaves", PROPERTY_HINT_RANGE, vformat("1,%d,1", MAX_OCTAVES)), "set_octaves", "get_octaves"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "period", PROPERTY_HINT_RANGE, "0.1,256.0,0.1"), "set_period", "get_period"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "persistence", PROPERTY_HINT_RANGE, "0.0,1.0,0.001"), "set_persistence", "get_persistence"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lacunarity", PROPERTY_HINT_RANGE, "0.1,4.0,0.01"), "set_lacunarity", "get_lacunarity"); -} - -float OpenSimplexNoise::get_noise_1d(float x) const { - return get_noise_2d(x, 1.0); -} - -float OpenSimplexNoise::get_noise_2d(float x, float y) const { - x /= period; - y /= period; - - float amp = 1.0; - float max = 1.0; - float sum = _get_octave_noise_2d(0, x, y); - - int i = 0; - while (++i < octaves) { - x *= lacunarity; - y *= lacunarity; - amp *= persistence; - max += amp; - sum += _get_octave_noise_2d(i, x, y) * amp; - } - - return sum / max; -} - -float OpenSimplexNoise::get_noise_3d(float x, float y, float z) const { - x /= period; - y /= period; - z /= period; - - float amp = 1.0; - float max = 1.0; - float sum = _get_octave_noise_3d(0, x, y, z); - - int i = 0; - while (++i < octaves) { - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - amp *= persistence; - max += amp; - sum += _get_octave_noise_3d(i, x, y, z) * amp; - } - - return sum / max; -} - -float OpenSimplexNoise::get_noise_4d(float x, float y, float z, float w) const { - x /= period; - y /= period; - z /= period; - w /= period; - - float amp = 1.0; - float max = 1.0; - float sum = _get_octave_noise_4d(0, x, y, z, w); - - int i = 0; - while (++i < octaves) { - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - w *= lacunarity; - amp *= persistence; - max += amp; - sum += _get_octave_noise_4d(i, x, y, z, w) * amp; - } - - return sum / max; -} diff --git a/modules/opensimplex/open_simplex_noise.h b/modules/opensimplex/open_simplex_noise.h deleted file mode 100644 index dcf922a8bf..0000000000 --- a/modules/opensimplex/open_simplex_noise.h +++ /dev/null @@ -1,99 +0,0 @@ -/*************************************************************************/ -/* open_simplex_noise.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef OPEN_SIMPLEX_NOISE_H -#define OPEN_SIMPLEX_NOISE_H - -#include "core/io/image.h" -#include "core/object/ref_counted.h" -#include "scene/resources/texture.h" - -#include "thirdparty/misc/open-simplex-noise.h" - -class OpenSimplexNoise : public Resource { - GDCLASS(OpenSimplexNoise, Resource); - OBJ_SAVE_TYPE(OpenSimplexNoise); - - // The maximum number of octaves allowed. Note that these are statically allocated. - // Higher values become exponentially slower, so this shouldn't be set too high - // to avoid freezing the editor for long periods of time. - static const int MAX_OCTAVES = 9; - - osn_context contexts[MAX_OCTAVES]; - - 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(); - ~OpenSimplexNoise(); - - void _init_seeds(); - - void set_seed(int seed); - int get_seed() const; - - void set_octaves(int p_octaves); - int get_octaves() const { return octaves; } - - void set_period(float p_period); - float get_period() const { return period; } - - void set_persistence(float p_persistence); - float get_persistence() const { return persistence; } - - void set_lacunarity(float p_lacunarity); - float get_lacunarity() const { return lacunarity; } - - Ref<Image> get_image(int p_width, int p_height, const Vector2 &p_noise_offset = Vector2()) const; - Ref<Image> get_seamless_image(int p_size) const; - - float get_noise_1d(float x) const; - float get_noise_2d(float x, float y) const; - float get_noise_3d(float x, float y, float z) const; - float get_noise_4d(float x, float y, float z, float w) const; - - _FORCE_INLINE_ float _get_octave_noise_2d(int octave, float x, float y) const { return open_simplex_noise2(&(contexts[octave]), x, y); } - _FORCE_INLINE_ float _get_octave_noise_3d(int octave, float x, float y, float z) const { return open_simplex_noise3(&(contexts[octave]), x, y, z); } - _FORCE_INLINE_ float _get_octave_noise_4d(int octave, float x, float y, float z, float w) const { return open_simplex_noise4(&(contexts[octave]), x, y, z, w); } - - // Convenience - - _FORCE_INLINE_ float get_noise_2dv(const Vector2 &v) const { return get_noise_2d(v.x, v.y); } - _FORCE_INLINE_ float get_noise_3dv(const Vector3 &v) const { return get_noise_3d(v.x, v.y, v.z); } - -protected: - static void _bind_methods(); -}; - -#endif // OPEN_SIMPLEX_NOISE_H diff --git a/modules/opensimplex/register_types.cpp b/modules/opensimplex/register_types.cpp deleted file mode 100644 index d6f9f3436d..0000000000 --- a/modules/opensimplex/register_types.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************/ -/* register_types.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "register_types.h" -#include "noise_texture.h" -#include "open_simplex_noise.h" - -void register_opensimplex_types() { - GDREGISTER_CLASS(OpenSimplexNoise); - GDREGISTER_CLASS(NoiseTexture); -} - -void unregister_opensimplex_types() { -} diff --git a/modules/opensimplex/register_types.h b/modules/opensimplex/register_types.h deleted file mode 100644 index d72e37e3a3..0000000000 --- a/modules/opensimplex/register_types.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************/ -/* register_types.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef OPENSIMPLEX_REGISTER_TYPES_H -#define OPENSIMPLEX_REGISTER_TYPES_H - -void register_opensimplex_types(); -void unregister_opensimplex_types(); - -#endif // OPENSIMPLEX_REGISTER_TYPES_H |