diff options
Diffstat (limited to 'modules/noise')
-rw-r--r-- | modules/noise/fastnoise_lite.cpp | 53 | ||||
-rw-r--r-- | modules/noise/fastnoise_lite.h | 3 | ||||
-rw-r--r-- | modules/noise/noise_texture.cpp | 4 |
3 files changed, 38 insertions, 22 deletions
diff --git a/modules/noise/fastnoise_lite.cpp b/modules/noise/fastnoise_lite.cpp index a8d38dee62..b21e3247d7 100644 --- a/modules/noise/fastnoise_lite.cpp +++ b/modules/noise/fastnoise_lite.cpp @@ -30,6 +30,24 @@ #include "fastnoise_lite.h" +_FastNoiseLite::FractalType FastNoiseLite::_convert_domain_warp_fractal_type_enum(DomainWarpFractalType p_domain_warp_fractal_type) { + _FastNoiseLite::FractalType type; + switch (p_domain_warp_fractal_type) { + case DOMAIN_WARP_FRACTAL_NONE: + type = _FastNoiseLite::FractalType_None; + break; + case DOMAIN_WARP_FRACTAL_PROGRESSIVE: + type = _FastNoiseLite::FractalType_DomainWarpProgressive; + break; + case DOMAIN_WARP_FRACTAL_INDEPENDENT: + type = _FastNoiseLite::FractalType_DomainWarpIndependent; + break; + default: + type = _FastNoiseLite::FractalType_None; + } + return type; +} + FastNoiseLite::FastNoiseLite() { _noise.SetNoiseType((_FastNoiseLite::NoiseType)noise_type); _noise.SetSeed(seed); @@ -50,7 +68,7 @@ FastNoiseLite::FastNoiseLite() { _domain_warp_noise.SetSeed(seed); _domain_warp_noise.SetDomainWarpAmp(domain_warp_amplitude); _domain_warp_noise.SetFrequency(domain_warp_frequency); - _domain_warp_noise.SetFractalType(_FastNoiseLite::FractalType_None); + _domain_warp_noise.SetFractalType(_convert_domain_warp_fractal_type_enum(domain_warp_fractal_type)); _domain_warp_noise.SetFractalOctaves(domain_warp_fractal_octaves); _domain_warp_noise.SetFractalLacunarity(domain_warp_fractal_lacunarity); _domain_warp_noise.SetFractalGain(domain_warp_fractal_gain); @@ -241,23 +259,7 @@ real_t FastNoiseLite::get_domain_warp_frequency() const { void FastNoiseLite::set_domain_warp_fractal_type(DomainWarpFractalType p_domain_warp_fractal_type) { domain_warp_fractal_type = p_domain_warp_fractal_type; - // This needs manual conversion because Godots Inspector property API does not support discontiguous enum indices. - _FastNoiseLite::FractalType type; - switch (p_domain_warp_fractal_type) { - case DOMAIN_WARP_FRACTAL_NONE: - type = _FastNoiseLite::FractalType_None; - break; - case DOMAIN_WARP_FRACTAL_PROGRESSIVE: - type = _FastNoiseLite::FractalType_DomainWarpProgressive; - break; - case DOMAIN_WARP_FRACTAL_INDEPENDENT: - type = _FastNoiseLite::FractalType_DomainWarpIndependent; - break; - default: - type = _FastNoiseLite::FractalType_None; - } - - _domain_warp_noise.SetFractalType(type); + _domain_warp_noise.SetFractalType(_convert_domain_warp_fractal_type_enum(p_domain_warp_fractal_type)); emit_changed(); } @@ -298,6 +300,12 @@ real_t FastNoiseLite::get_domain_warp_fractal_gain() const { // Noise interface functions. real_t FastNoiseLite::get_noise_1d(real_t p_x) const { + p_x += offset.x; + if (domain_warp_enabled) { + // Needed since DomainWarp expects a reference. + real_t y_dummy = 0; + _domain_warp_noise.DomainWarp(p_x, y_dummy); + } return get_noise_2d(p_x, 0.0); } @@ -306,10 +314,12 @@ real_t FastNoiseLite::get_noise_2dv(Vector2 p_v) const { } real_t FastNoiseLite::get_noise_2d(real_t p_x, real_t p_y) const { + p_x += offset.x; + p_y += offset.y; if (domain_warp_enabled) { _domain_warp_noise.DomainWarp(p_x, p_y); } - return _noise.GetNoise(p_x + offset.x, p_y + offset.y); + return _noise.GetNoise(p_x, p_y); } real_t FastNoiseLite::get_noise_3dv(Vector3 p_v) const { @@ -317,10 +327,13 @@ real_t FastNoiseLite::get_noise_3dv(Vector3 p_v) const { } real_t FastNoiseLite::get_noise_3d(real_t p_x, real_t p_y, real_t p_z) const { + p_x += offset.x; + p_y += offset.y; + p_z += offset.z; if (domain_warp_enabled) { _domain_warp_noise.DomainWarp(p_x, p_y, p_z); } - return _noise.GetNoise(p_x + offset.x, p_y + offset.y, p_z + offset.z); + return _noise.GetNoise(p_x, p_y, p_z); } void FastNoiseLite::_changed() { diff --git a/modules/noise/fastnoise_lite.h b/modules/noise/fastnoise_lite.h index 0a4251868b..fe8cd7ce6e 100644 --- a/modules/noise/fastnoise_lite.h +++ b/modules/noise/fastnoise_lite.h @@ -127,6 +127,9 @@ private: real_t domain_warp_fractal_lacunarity = 6; real_t domain_warp_fractal_gain = 0.5; + // This needs manual conversion because Godots Inspector property API does not support discontiguous enum indices. + _FastNoiseLite::FractalType _convert_domain_warp_fractal_type_enum(DomainWarpFractalType p_domain_warp_fractal_type); + public: FastNoiseLite(); ~FastNoiseLite(); diff --git a/modules/noise/noise_texture.cpp b/modules/noise/noise_texture.cpp index e9d16e548c..ca55d3b96d 100644 --- a/modules/noise/noise_texture.cpp +++ b/modules/noise/noise_texture.cpp @@ -81,8 +81,8 @@ void NoiseTexture::_bind_methods() { ClassDB::bind_method(D_METHOD("set_noise", "noise"), &NoiseTexture::set_noise); ClassDB::bind_method(D_METHOD("get_noise"), &NoiseTexture::get_noise); - 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::INT, "width", PROPERTY_HINT_RANGE, "1,2048,1,or_greater,suffix:px"), "set_width", "get_width"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "height", PROPERTY_HINT_RANGE, "1,2048,1,or_greater,suffix:px"), "set_height", "get_height"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "invert"), "set_invert", "get_invert"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "in_3d_space"), "set_in_3d_space", "is_in_3d_space"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "generate_mipmaps"), "set_generate_mipmaps", "is_generating_mipmaps"); |