Fix compilation now Godot comes with its own FastNoiseLite.

The version shipped with the module is now prefixed.
Removed usages of OpenSimplexNoise.
master
Marc Gilleron 2022-04-03 20:07:17 +01:00
parent 68f8aa6092
commit e0008d3335
24 changed files with 379 additions and 425 deletions

7
SCsub
View File

@ -35,11 +35,8 @@ voxel_files = [
"util/godot/*.cpp",
#"util/noise/*.cpp",
"util/noise/fast_noise_lite.cpp",
"util/noise/fast_noise_lite_gradient.cpp",
"util/noise/fast_noise_lite_range.cpp",
"util/noise/osn_noise_range.cpp",
"util/noise/fast_noise_lite/*.cpp",
"util/noise/gd_noise_range.cpp",
"util/tasks/*.cpp",

View File

@ -65,6 +65,7 @@ Godot 4 is required from this version.
- `VoxelStreamScript`: renamed `_emerge_block` => `_load_voxel_block`
- `VoxelStreamScript`: renamed `_immerge_block` => `_save_voxel_block`
- `VoxelGeneratorGraph`: the `Select` node's `threshold` port is now a parameter instead.
- `FastNoiseLite` was renamed `ZN_FastNoiseLite`, as now Godot 4 comes with its own implementation, with a few differences.
- Known issues
- Some nodes and resources no longer start with predefined properties due to a warning introduced in Godot4 when properties are resources.

View File

@ -1,19 +1,19 @@
#include "fast_noise_lite_editor_plugin.h"
#include "../../util/noise/fast_noise_lite.h"
#include "../../util/noise/fast_noise_lite_gradient.h"
#include "../../util/noise/fast_noise_lite/fast_noise_lite.h"
#include "../../util/noise/fast_noise_lite/fast_noise_lite_gradient.h"
#include <core/core_string_names.h>
#include <editor/editor_scale.h>
namespace zylann {
class FastNoiseLiteViewer : public Control {
GDCLASS(FastNoiseLiteViewer, Control)
class ZN_FastNoiseLiteViewer : public Control {
GDCLASS(ZN_FastNoiseLiteViewer, Control)
public:
static const int PREVIEW_WIDTH = 300;
static const int PREVIEW_HEIGHT = 150;
FastNoiseLiteViewer() {
ZN_FastNoiseLiteViewer() {
set_custom_minimum_size(Vector2(0, EDSCALE * PREVIEW_HEIGHT));
_texture_rect = memnew(TextureRect);
@ -22,25 +22,25 @@ public:
add_child(_texture_rect);
}
// ~FastNoiseLiteViewer() {
// ~ZN_FastNoiseLiteViewer() {
// }
void set_noise(Ref<FastNoiseLite> noise) {
void set_noise(Ref<ZN_FastNoiseLite> noise) {
if (_noise == noise) {
return;
}
if (_noise.is_valid()) {
_noise->disconnect(CoreStringNames::get_singleton()->changed,
callable_mp(this, &FastNoiseLiteViewer::_on_noise_changed));
callable_mp(this, &ZN_FastNoiseLiteViewer::_on_noise_changed));
}
_noise = noise;
if (_noise.is_valid()) {
set_noise_gradient(Ref<FastNoiseLiteGradient>());
set_noise_gradient(Ref<ZN_FastNoiseLiteGradient>());
_noise->connect(CoreStringNames::get_singleton()->changed,
callable_mp(this, &FastNoiseLiteViewer::_on_noise_changed));
callable_mp(this, &ZN_FastNoiseLiteViewer::_on_noise_changed));
set_process(true);
update_preview();
@ -50,22 +50,22 @@ public:
}
}
void set_noise_gradient(Ref<FastNoiseLiteGradient> noise_gradient) {
void set_noise_gradient(Ref<ZN_FastNoiseLiteGradient> noise_gradient) {
if (_noise_gradient == noise_gradient) {
return;
}
if (_noise_gradient.is_valid()) {
_noise_gradient->disconnect(CoreStringNames::get_singleton()->changed,
callable_mp(this, &FastNoiseLiteViewer::_on_noise_changed));
callable_mp(this, &ZN_FastNoiseLiteViewer::_on_noise_changed));
}
_noise_gradient = noise_gradient;
if (_noise_gradient.is_valid()) {
set_noise(Ref<FastNoiseLite>());
set_noise(Ref<ZN_FastNoiseLite>());
_noise_gradient->connect(CoreStringNames::get_singleton()->changed,
callable_mp(this, &FastNoiseLiteViewer::_on_noise_changed));
callable_mp(this, &ZN_FastNoiseLiteViewer::_on_noise_changed));
set_process(true);
update_preview();
@ -140,36 +140,37 @@ private:
// ClassDB::bind_method(D_METHOD("_on_noise_changed"), &FastNoiseLiteViewer::_on_noise_changed);
}
Ref<FastNoiseLite> _noise;
Ref<FastNoiseLiteGradient> _noise_gradient;
Ref<ZN_FastNoiseLite> _noise;
Ref<ZN_FastNoiseLiteGradient> _noise_gradient;
float _time_before_update = -1.f;
TextureRect *_texture_rect = nullptr;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class FastNoiseLiteEditorInspectorPlugin : public EditorInspectorPlugin {
GDCLASS(FastNoiseLiteEditorInspectorPlugin, EditorInspectorPlugin)
class ZN_FastNoiseLiteEditorInspectorPlugin : public EditorInspectorPlugin {
GDCLASS(ZN_FastNoiseLiteEditorInspectorPlugin, EditorInspectorPlugin)
public:
bool can_handle(Object *p_object) override {
return Object::cast_to<FastNoiseLite>(p_object) != nullptr || Object::cast_to<FastNoiseLiteGradient>(p_object);
return Object::cast_to<ZN_FastNoiseLite>(p_object) != nullptr ||
Object::cast_to<ZN_FastNoiseLiteGradient>(p_object);
}
void parse_begin(Object *p_object) override {
FastNoiseLite *noise_ptr = Object::cast_to<FastNoiseLite>(p_object);
ZN_FastNoiseLite *noise_ptr = Object::cast_to<ZN_FastNoiseLite>(p_object);
if (noise_ptr) {
Ref<FastNoiseLite> noise(noise_ptr);
Ref<ZN_FastNoiseLite> noise(noise_ptr);
FastNoiseLiteViewer *viewer = memnew(FastNoiseLiteViewer);
ZN_FastNoiseLiteViewer *viewer = memnew(ZN_FastNoiseLiteViewer);
viewer->set_noise(noise);
add_custom_control(viewer);
return;
}
FastNoiseLiteGradient *noise_gradient_ptr = Object::cast_to<FastNoiseLiteGradient>(p_object);
ZN_FastNoiseLiteGradient *noise_gradient_ptr = Object::cast_to<ZN_FastNoiseLiteGradient>(p_object);
if (noise_gradient_ptr) {
Ref<FastNoiseLiteGradient> noise_gradient(noise_gradient_ptr);
Ref<ZN_FastNoiseLiteGradient> noise_gradient(noise_gradient_ptr);
FastNoiseLiteViewer *viewer = memnew(FastNoiseLiteViewer);
ZN_FastNoiseLiteViewer *viewer = memnew(ZN_FastNoiseLiteViewer);
viewer->set_noise_gradient(noise_gradient);
add_custom_control(viewer);
return;
@ -179,10 +180,14 @@ public:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FastNoiseLiteEditorPlugin::FastNoiseLiteEditorPlugin() {
Ref<FastNoiseLiteEditorInspectorPlugin> plugin;
ZN_FastNoiseLiteEditorPlugin::ZN_FastNoiseLiteEditorPlugin() {
Ref<ZN_FastNoiseLiteEditorInspectorPlugin> plugin;
plugin.instantiate();
add_inspector_plugin(plugin);
}
String ZN_FastNoiseLiteEditorPlugin::get_name() const {
return ZN_FastNoiseLite::get_class_static();
}
} // namespace zylann

View File

@ -1,20 +1,18 @@
#ifndef FAST_NOISE_LITE_EDITOR_PLUGIN_H
#define FAST_NOISE_LITE_EDITOR_PLUGIN_H
#ifndef ZN_FAST_NOISE_LITE_EDITOR_PLUGIN_H
#define ZN_FAST_NOISE_LITE_EDITOR_PLUGIN_H
#include <editor/editor_plugin.h>
namespace zylann {
class FastNoiseLiteEditorPlugin : public EditorPlugin {
GDCLASS(FastNoiseLiteEditorPlugin, EditorPlugin)
class ZN_FastNoiseLiteEditorPlugin : public EditorPlugin {
GDCLASS(ZN_FastNoiseLiteEditorPlugin, EditorPlugin)
public:
String get_name() const override {
return "FastNoiseLite";
}
String get_name() const override;
FastNoiseLiteEditorPlugin();
ZN_FastNoiseLiteEditorPlugin();
};
} // namespace zylann
#endif // FAST_NOISE_LITE_EDITOR_PLUGIN_H
#endif // ZN_FAST_NOISE_LITE_EDITOR_PLUGIN_H

View File

@ -1,9 +1,9 @@
#include "voxel_graph_node_db.h"
#include "../../constants/voxel_constants.h"
#include "../../util/math/sdf.h"
#include "../../util/noise/fast_noise_lite.h"
#include "../../util/noise/fast_noise_lite_range.h"
#include "../../util/noise/osn_noise_range.h"
#include "../../util/noise/fast_noise_lite/fast_noise_lite.h"
#include "../../util/noise/fast_noise_lite/fast_noise_lite_range.h"
#include "../../util/noise/gd_noise_range.h"
#include "../../util/profiling.h"
#include "image_range_grid.h"
#include "range_utility.h"
@ -12,7 +12,7 @@
#include "../../util/noise/fast_noise_2.h"
#endif
#include <modules/opensimplex/open_simplex_noise.h>
#include <modules/noise/noise.h>
#include <scene/resources/curve.h>
namespace zylann::voxel {
@ -871,7 +871,9 @@ VoxelGraphNodeDB::VoxelGraphNodeDB() {
}
{
struct Params {
const OpenSimplexNoise *noise;
// TODO Cannot be `const` because of an oversight in Godot, but the devs are not sure to do it
// TODO We therefore have no guarantee it is thread-safe to use...
Noise *noise;
};
NodeType &t = types[VoxelGeneratorGraph::NODE_NOISE_2D];
@ -880,12 +882,12 @@ VoxelGraphNodeDB::VoxelGraphNodeDB() {
t.inputs.push_back(Port("x"));
t.inputs.push_back(Port("y"));
t.outputs.push_back(Port("out"));
t.params.push_back(Param("noise", OpenSimplexNoise::get_class_static()));
t.params.push_back(Param("noise", Noise::get_class_static()));
t.compile_func = [](CompileContext &ctx) {
Ref<OpenSimplexNoise> noise = ctx.get_param(0);
Ref<Noise> noise = ctx.get_param(0);
if (noise.is_null()) {
ctx.make_error("OpenSimplexNoise instance is null");
ctx.make_error("Noise instance is null");
return;
}
Params p;
@ -909,12 +911,14 @@ VoxelGraphNodeDB::VoxelGraphNodeDB() {
const Interval y = ctx.get_input(1);
const Params p = ctx.get_params<Params>();
// Shouldn't be null, it is checked when the graph is compiled
ctx.set_output(0, get_osn_range_2d(*p.noise, x, y));
ctx.set_output(0, get_range_2d(*p.noise, x, y));
};
}
{
struct Params {
const OpenSimplexNoise *noise;
// TODO Cannot be `const` because of an oversight in Godot, but the devs are not sure to do it
// TODO We therefore have no guarantee it is thread-safe to use...
Noise *noise;
};
NodeType &t = types[VoxelGeneratorGraph::NODE_NOISE_3D];
@ -924,10 +928,10 @@ VoxelGraphNodeDB::VoxelGraphNodeDB() {
t.inputs.push_back(Port("y"));
t.inputs.push_back(Port("z"));
t.outputs.push_back(Port("out"));
t.params.push_back(Param("noise", OpenSimplexNoise::get_class_static()));
t.params.push_back(Param("noise", Noise::get_class_static()));
t.compile_func = [](CompileContext &ctx) {
Ref<OpenSimplexNoise> noise = ctx.get_param(0);
Ref<Noise> noise = ctx.get_param(0);
if (noise.is_null()) {
ctx.make_error("OpenSimplexNoise instance is null");
return;
@ -955,7 +959,7 @@ VoxelGraphNodeDB::VoxelGraphNodeDB() {
const Interval z = ctx.get_input(2);
const Params p = ctx.get_params<Params>();
// Shouldn't be null, it is checked when the graph is compiled
ctx.set_output(0, get_osn_range_3d(*p.noise, x, y, z));
ctx.set_output(0, get_range_3d(*p.noise, x, y, z));
};
}
{
@ -1490,7 +1494,7 @@ VoxelGraphNodeDB::VoxelGraphNodeDB() {
}
{
struct Params {
const FastNoiseLite *noise;
const ZN_FastNoiseLite *noise;
};
NodeType &t = types[VoxelGeneratorGraph::NODE_FAST_NOISE_2D];
@ -1499,12 +1503,12 @@ VoxelGraphNodeDB::VoxelGraphNodeDB() {
t.inputs.push_back(Port("x"));
t.inputs.push_back(Port("y"));
t.outputs.push_back(Port("out"));
t.params.push_back(Param("noise", FastNoiseLite::get_class_static()));
t.params.push_back(Param("noise", ZN_FastNoiseLite::get_class_static()));
t.compile_func = [](CompileContext &ctx) {
Ref<FastNoiseLite> noise = ctx.get_param(0);
Ref<ZN_FastNoiseLite> noise = ctx.get_param(0);
if (noise.is_null()) {
ctx.make_error("FastNoiseLite instance is null");
ctx.make_error(ZN_FastNoiseLite::get_class_static() + " instance is null");
return;
}
Params p;
@ -1533,7 +1537,7 @@ VoxelGraphNodeDB::VoxelGraphNodeDB() {
}
{
struct Params {
const FastNoiseLite *noise;
const ZN_FastNoiseLite *noise;
};
NodeType &t = types[VoxelGeneratorGraph::NODE_FAST_NOISE_3D];
@ -1543,10 +1547,10 @@ VoxelGraphNodeDB::VoxelGraphNodeDB() {
t.inputs.push_back(Port("y"));
t.inputs.push_back(Port("z"));
t.outputs.push_back(Port("out"));
t.params.push_back(Param("noise", FastNoiseLite::get_class_static()));
t.params.push_back(Param("noise", ZN_FastNoiseLite::get_class_static()));
t.compile_func = [](CompileContext &ctx) {
Ref<FastNoiseLite> noise = ctx.get_param(0);
Ref<ZN_FastNoiseLite> noise = ctx.get_param(0);
if (noise.is_null()) {
ctx.make_error("FastNoiseLite instance is null");
return;
@ -1579,7 +1583,7 @@ VoxelGraphNodeDB::VoxelGraphNodeDB() {
}
{
struct Params {
FastNoiseLiteGradient *noise;
ZN_FastNoiseLiteGradient *noise;
};
NodeType &t = types[VoxelGeneratorGraph::NODE_FAST_NOISE_GRADIENT_2D];
@ -1589,10 +1593,10 @@ VoxelGraphNodeDB::VoxelGraphNodeDB() {
t.inputs.push_back(Port("y"));
t.outputs.push_back(Port("out_x"));
t.outputs.push_back(Port("out_y"));
t.params.push_back(Param("noise", FastNoiseLiteGradient::get_class_static()));
t.params.push_back(Param("noise", ZN_FastNoiseLiteGradient::get_class_static()));
t.compile_func = [](CompileContext &ctx) {
Ref<FastNoiseLiteGradient> noise = ctx.get_param(0);
Ref<ZN_FastNoiseLiteGradient> noise = ctx.get_param(0);
if (noise.is_null()) {
ctx.make_error("FastNoiseLiteGradient instance is null");
return;
@ -1630,7 +1634,7 @@ VoxelGraphNodeDB::VoxelGraphNodeDB() {
}
{
struct Params {
FastNoiseLiteGradient *noise;
ZN_FastNoiseLiteGradient *noise;
};
NodeType &t = types[VoxelGeneratorGraph::NODE_FAST_NOISE_GRADIENT_3D];
@ -1642,10 +1646,10 @@ VoxelGraphNodeDB::VoxelGraphNodeDB() {
t.outputs.push_back(Port("out_x"));
t.outputs.push_back(Port("out_y"));
t.outputs.push_back(Port("out_z"));
t.params.push_back(Param("noise", FastNoiseLiteGradient::get_class_static()));
t.params.push_back(Param("noise", ZN_FastNoiseLiteGradient::get_class_static()));
t.compile_func = [](CompileContext &ctx) {
Ref<FastNoiseLiteGradient> noise = ctx.get_param(0);
Ref<ZN_FastNoiseLiteGradient> noise = ctx.get_param(0);
if (noise.is_null()) {
ctx.make_error("FastNoiseLiteGradient instance is null");
return;

View File

@ -8,7 +8,7 @@ VoxelGeneratorNoise::VoxelGeneratorNoise() {}
VoxelGeneratorNoise::~VoxelGeneratorNoise() {}
void VoxelGeneratorNoise::set_noise(Ref<OpenSimplexNoise> noise) {
void VoxelGeneratorNoise::set_noise(Ref<Noise> noise) {
if (_noise == noise) {
return;
}
@ -17,7 +17,7 @@ void VoxelGeneratorNoise::set_noise(Ref<OpenSimplexNoise> noise) {
CoreStringNames::get_singleton()->changed, callable_mp(this, &VoxelGeneratorNoise::_on_noise_changed));
}
_noise = noise;
Ref<OpenSimplexNoise> copy;
Ref<Noise> copy;
if (_noise.is_valid()) {
_noise->connect(
CoreStringNames::get_singleton()->changed, callable_mp(this, &VoxelGeneratorNoise::_on_noise_changed));
@ -60,7 +60,7 @@ int VoxelGeneratorNoise::get_used_channels_mask() const {
return (1 << _parameters.channel);
}
Ref<OpenSimplexNoise> VoxelGeneratorNoise::get_noise() const {
Ref<Noise> VoxelGeneratorNoise::get_noise() const {
return _noise;
}
@ -87,6 +87,7 @@ real_t VoxelGeneratorNoise::get_height_range() const {
return _parameters.height_range;
}
/*
// For isosurface use cases, noise can be "shaped" by calculating only the first octave,
// and discarding the next ones if beyond some distance away from the isosurface,
// because then we assume next octaves won't change the sign (which crosses the surface).
@ -119,6 +120,7 @@ static inline float get_shaped_noise(OpenSimplexNoise &noise, float x, float y,
return sum / max;
}
*/
VoxelGenerator::Result VoxelGeneratorNoise::generate_block(VoxelGenerator::VoxelQueryData &input) {
Parameters params;
@ -129,7 +131,7 @@ VoxelGenerator::Result VoxelGeneratorNoise::generate_block(VoxelGenerator::Voxel
ERR_FAIL_COND_V(params.noise.is_null(), Result());
OpenSimplexNoise &noise = **params.noise;
Noise &noise = **params.noise;
VoxelBufferInternal &buffer = input.voxel_buffer;
Vector3i origin_in_voxels = input.origin_in_voxels;
int lod = input.lod;
@ -167,10 +169,10 @@ VoxelGenerator::Result VoxelGeneratorNoise::generate_block(VoxelGenerator::Voxel
result.max_lod_hint = true;
} else {
const float iso_scale = noise.get_period() * 0.1;
const float iso_scale = 0.1f;
const Vector3i size = buffer.get_size();
const float height_range_inv = 1.f / params.height_range;
const float one_minus_persistence = 1.f - noise.get_persistence();
//const float one_minus_persistence = 1.f - noise.get_persistence();
for (int z = 0; z < size.z; ++z) {
int lz = origin_in_voxels.z + (z << lod);
@ -205,12 +207,13 @@ VoxelGenerator::Result VoxelGeneratorNoise::generate_block(VoxelGenerator::Voxel
}
// Bias is what makes noise become "matter" the lower we go, and "air" the higher we go
float t = (ly - params.height_start) * height_range_inv;
float bias = 2.0 * t - 1.0;
const float t = (ly - params.height_start) * height_range_inv;
const float bias = 2.0 * t - 1.0;
// We are near the isosurface, need to calculate noise value
float n = get_shaped_noise(noise, lx, ly, lz, one_minus_persistence, bias);
float d = (n + bias) * iso_scale;
//float n = get_shaped_noise(noise, lx, ly, lz, one_minus_persistence, bias);
const float n = noise.get_noise_3d(lx, ly, lz);
const float d = (n + bias) * iso_scale;
if (params.channel == VoxelBufferInternal::CHANNEL_SDF) {
buffer.set_voxel_f(d, x, y, z, params.channel);
@ -252,9 +255,8 @@ void VoxelGeneratorNoise::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "channel", PROPERTY_HINT_ENUM, gd::VoxelBuffer::CHANNEL_ID_HINT_STRING),
"set_channel", "get_channel");
ADD_PROPERTY(
PropertyInfo(Variant::OBJECT, "noise", PROPERTY_HINT_RESOURCE_TYPE, OpenSimplexNoise::get_class_static(),
PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT),
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "noise", PROPERTY_HINT_RESOURCE_TYPE, Noise::get_class_static(),
PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT),
"set_noise", "get_noise");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height_start"), "set_height_start", "get_height_start");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height_range"), "set_height_range", "get_height_range");

View File

@ -3,7 +3,7 @@
#include "../../storage/voxel_buffer_gd.h"
#include "../voxel_generator.h"
#include <modules/opensimplex/open_simplex_noise.h>
#include <modules/noise/noise.h>
namespace zylann::voxel {
@ -19,8 +19,8 @@ public:
int get_used_channels_mask() const override;
void set_noise(Ref<OpenSimplexNoise> noise);
Ref<OpenSimplexNoise> get_noise() const;
void set_noise(Ref<Noise> noise);
Ref<Noise> get_noise() const;
void set_height_start(real_t y);
real_t get_height_start() const;
@ -38,11 +38,11 @@ private:
static void _bind_methods();
Ref<OpenSimplexNoise> _noise;
Ref<Noise> _noise;
struct Parameters {
VoxelBufferInternal::ChannelId channel = VoxelBufferInternal::CHANNEL_SDF;
Ref<OpenSimplexNoise> noise;
Ref<Noise> noise;
float height_start = 0;
float height_range = 300;
};

View File

@ -1,6 +1,8 @@
#include "voxel_generator_noise_2d.h"
#include <core/config/engine.h>
#include <core/core_string_names.h>
#include <modules/noise/noise.h>
#include <scene/resources/curve.h>
namespace zylann::voxel {
@ -8,7 +10,7 @@ VoxelGeneratorNoise2D::VoxelGeneratorNoise2D() {}
VoxelGeneratorNoise2D::~VoxelGeneratorNoise2D() {}
void VoxelGeneratorNoise2D::set_noise(Ref<OpenSimplexNoise> noise) {
void VoxelGeneratorNoise2D::set_noise(Ref<Noise> noise) {
if (_noise == noise) {
return;
}
@ -17,7 +19,7 @@ void VoxelGeneratorNoise2D::set_noise(Ref<OpenSimplexNoise> noise) {
callable_mp(this, &VoxelGeneratorNoise2D::_on_noise_changed));
}
_noise = noise;
Ref<OpenSimplexNoise> copy;
Ref<Noise> copy;
if (_noise.is_valid()) {
_noise->connect(CoreStringNames::get_singleton()->changed,
callable_mp(this, &VoxelGeneratorNoise2D::_on_noise_changed));
@ -28,7 +30,7 @@ void VoxelGeneratorNoise2D::set_noise(Ref<OpenSimplexNoise> noise) {
_parameters.noise = copy;
}
Ref<OpenSimplexNoise> VoxelGeneratorNoise2D::get_noise() const {
Ref<Noise> VoxelGeneratorNoise2D::get_noise() const {
return _noise;
}
@ -67,7 +69,7 @@ VoxelGenerator::Result VoxelGeneratorNoise2D::generate_block(VoxelGenerator::Vox
Result result;
ERR_FAIL_COND_V(params.noise.is_null(), result);
OpenSimplexNoise &noise = **params.noise;
Noise &noise = **params.noise;
VoxelBufferInternal &out_buffer = input.voxel_buffer;
@ -111,9 +113,8 @@ void VoxelGeneratorNoise2D::_bind_methods() {
// ClassDB::bind_method(D_METHOD("_on_noise_changed"), &VoxelGeneratorNoise2D::_on_noise_changed);
// ClassDB::bind_method(D_METHOD("_on_curve_changed"), &VoxelGeneratorNoise2D::_on_curve_changed);
ADD_PROPERTY(
PropertyInfo(Variant::OBJECT, "noise", PROPERTY_HINT_RESOURCE_TYPE, OpenSimplexNoise::get_class_static(),
PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT),
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "noise", PROPERTY_HINT_RESOURCE_TYPE, Noise::get_class_static(),
PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT),
"set_noise", "get_noise");
ADD_PROPERTY(
PropertyInfo(Variant::OBJECT, "curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve", "get_curve");

View File

@ -2,7 +2,9 @@
#define VOXEL_GENERATOR_NOISE_2D_H
#include "voxel_generator_heightmap.h"
#include <modules/opensimplex/open_simplex_noise.h>
class Curve;
class Noise;
namespace zylann::voxel {
@ -13,8 +15,8 @@ public:
VoxelGeneratorNoise2D();
~VoxelGeneratorNoise2D();
void set_noise(Ref<OpenSimplexNoise> noise);
Ref<OpenSimplexNoise> get_noise() const;
void set_noise(Ref<Noise> noise);
Ref<Noise> get_noise() const;
void set_curve(Ref<Curve> curve);
Ref<Curve> get_curve() const;
@ -28,11 +30,11 @@ private:
static void _bind_methods();
private:
Ref<OpenSimplexNoise> _noise;
Ref<Noise> _noise;
Ref<Curve> _curve;
struct Parameters {
Ref<OpenSimplexNoise> noise;
Ref<Noise> noise;
Ref<Curve> curve;
};

View File

@ -36,8 +36,8 @@
#include "terrain/voxel_mesh_block.h"
#include "terrain/voxel_viewer.h"
#include "util/macros.h"
#include "util/noise/fast_noise_lite.h"
#include "util/noise/fast_noise_lite_gradient.h"
#include "util/noise/fast_noise_lite/fast_noise_lite.h"
#include "util/noise/fast_noise_lite/fast_noise_lite_gradient.h"
#ifdef VOXEL_ENABLE_FAST_NOISE_2
#include "util/noise/fast_noise_2.h"
@ -129,8 +129,8 @@ void register_voxel_types() {
ClassDB::register_abstract_class<VoxelToolBuffer>();
ClassDB::register_class<gd::VoxelBlockSerializer>();
ClassDB::register_class<VoxelVoxLoader>();
ClassDB::register_class<FastNoiseLite>();
ClassDB::register_class<FastNoiseLiteGradient>();
ClassDB::register_class<ZN_FastNoiseLite>();
ClassDB::register_class<ZN_FastNoiseLiteGradient>();
// See SCsub
#ifdef VOXEL_ENABLE_FAST_NOISE_2
ClassDB::register_class<FastNoise2>();
@ -164,7 +164,7 @@ void register_voxel_types() {
EditorPlugins::add_by_type<VoxelGraphEditorPlugin>();
EditorPlugins::add_by_type<VoxelTerrainEditorPlugin>();
EditorPlugins::add_by_type<VoxelInstanceLibraryEditorPlugin>();
EditorPlugins::add_by_type<FastNoiseLiteEditorPlugin>();
EditorPlugins::add_by_type<ZN_FastNoiseLiteEditorPlugin>();
EditorPlugins::add_by_type<magica::VoxEditorPlugin>();
EditorPlugins::add_by_type<VoxelInstancerEditorPlugin>();
#ifdef VOXEL_ENABLE_FAST_NOISE_2

View File

@ -609,7 +609,7 @@ bool VoxelInstanceGenerator::get_random_rotation() const {
return _random_rotation;
}
void VoxelInstanceGenerator::set_noise(Ref<FastNoiseLite> noise) {
void VoxelInstanceGenerator::set_noise(Ref<Noise> noise) {
if (_noise == noise) {
return;
}
@ -625,7 +625,7 @@ void VoxelInstanceGenerator::set_noise(Ref<FastNoiseLite> noise) {
emit_changed();
}
Ref<FastNoiseLite> VoxelInstanceGenerator::get_noise() const {
Ref<Noise> VoxelInstanceGenerator::get_noise() const {
return _noise;
}

View File

@ -3,7 +3,7 @@
//#include "../../storage/voxel_buffer.h"
#include "../../util/math/vector3i.h"
#include "../../util/noise/fast_noise_lite.h"
#include <modules/noise/noise.h>
#include <limits>
#include <vector>
@ -102,8 +102,8 @@ public:
void set_random_rotation(bool enabled);
bool get_random_rotation() const;
void set_noise(Ref<FastNoiseLite> noise);
Ref<FastNoiseLite> get_noise() const;
void set_noise(Ref<Noise> noise);
Ref<Noise> get_noise() const;
void set_noise_dimension(Dimension dim);
Dimension get_noise_dimension() const;
@ -133,7 +133,7 @@ private:
bool _random_rotation = true;
EmitMode _emit_mode = EMIT_FROM_VERTICES;
Distribution _scale_distribution = DISTRIBUTION_QUADRATIC;
Ref<FastNoiseLite> _noise;
Ref<Noise> _noise;
Dimension _noise_dimension = DIMENSION_3D;
float _noise_on_scale = 0.f;

View File

@ -1,9 +1,8 @@
#include "../util/math/funcs.h"
#include "../util/noise/fast_noise_lite.h"
#include "../util/noise/fast_noise_lite/fast_noise_lite.h"
#include "tests.h"
#include <core/io/image.h>
#include <modules/opensimplex/open_simplex_noise.h>
namespace zylann::voxel::noise_tests {
@ -234,16 +233,10 @@ void test_fnl_noise(fast_noise_lite::FastNoiseLite &fnl, String name, int tests)
}
void test_noises() {
Ref<FastNoiseLite> noise;
noise.instantiate();
fast_noise_lite::FastNoiseLite fn;
fn.SetFractalType(fast_noise_lite::FastNoiseLite::FractalType_None);
fn.SetFrequency(1.f);
osn_context osn_ctx;
open_simplex_noise(131183, &osn_ctx);
// According to OpenSimplex2 author, the 3D version is supposed to have a max derivative around 4.23718
// https://www.wolframalpha.com/input/?i=max+d%2Fdx+32.69428253173828125+*+x+*+%28%280.6-x%5E2%29%5E4%29+from+-0.6+to+0.6
// But empiric measures have shown it around 8. Discontinuities do exist in this noise though,
@ -310,11 +303,6 @@ void test_noises() {
}
}
test_noise(
"OpenSimplex1", TEST_MIN_MAX | TEST_DERIVATIVES,
[&osn_ctx](double x, double y) { return open_simplex_noise2(&osn_ctx, x, y); },
[&osn_ctx](double x, double y, double z) { return open_simplex_noise3(&osn_ctx, x, y, z); });
// Spreadsheet helper:
print_line("Steps:");
for (int i = 0; i < STEP_RESOLUTION_COUNT; ++i) {

View File

@ -1,10 +1,10 @@
#include "fast_noise_lite.h"
#include "../math/funcs.h"
#include "../../math/funcs.h"
#include <core/core_string_names.h>
namespace zylann {
FastNoiseLite::FastNoiseLite() {
ZN_FastNoiseLite::ZN_FastNoiseLite() {
_fn.SetNoiseType(static_cast<_FastNoise::NoiseType>(_noise_type));
_fn.SetSeed(_seed);
_fn.SetFrequency(1.f / _period);
@ -23,7 +23,7 @@ FastNoiseLite::FastNoiseLite() {
_fn.SetRotationType3D(static_cast<_FastNoise::RotationType3D>(_rotation_type_3d));
}
void FastNoiseLite::set_noise_type(NoiseType type) {
void ZN_FastNoiseLite::set_noise_type(NoiseType type) {
if (_noise_type == type) {
return;
}
@ -32,11 +32,11 @@ void FastNoiseLite::set_noise_type(NoiseType type) {
emit_changed();
}
FastNoiseLite::NoiseType FastNoiseLite::get_noise_type() const {
ZN_FastNoiseLite::NoiseType ZN_FastNoiseLite::get_noise_type() const {
return _noise_type;
}
void FastNoiseLite::set_seed(int seed) {
void ZN_FastNoiseLite::set_seed(int seed) {
if (_seed == seed) {
return;
}
@ -45,11 +45,11 @@ void FastNoiseLite::set_seed(int seed) {
emit_changed();
}
int FastNoiseLite::get_seed() const {
int ZN_FastNoiseLite::get_seed() const {
return _seed;
}
void FastNoiseLite::set_period(float p) {
void ZN_FastNoiseLite::set_period(float p) {
if (p < 0.0001f) {
p = 0.0001f;
}
@ -61,35 +61,35 @@ void FastNoiseLite::set_period(float p) {
emit_changed();
}
float FastNoiseLite::get_period() const {
float ZN_FastNoiseLite::get_period() const {
return _period;
}
void FastNoiseLite::set_warp_noise(Ref<FastNoiseLiteGradient> warp_noise) {
void ZN_FastNoiseLite::set_warp_noise(Ref<ZN_FastNoiseLiteGradient> warp_noise) {
if (_warp_noise == warp_noise) {
return;
}
if (_warp_noise.is_valid()) {
_warp_noise->disconnect(
CoreStringNames::get_singleton()->changed, callable_mp(this, &FastNoiseLite::_on_warp_noise_changed));
_warp_noise->disconnect(CoreStringNames::get_singleton()->changed,
callable_mp(this, &ZN_FastNoiseLite::_on_warp_noise_changed));
}
_warp_noise = warp_noise;
if (_warp_noise.is_valid()) {
_warp_noise->connect(
CoreStringNames::get_singleton()->changed, callable_mp(this, &FastNoiseLite::_on_warp_noise_changed));
_warp_noise->connect(CoreStringNames::get_singleton()->changed,
callable_mp(this, &ZN_FastNoiseLite::_on_warp_noise_changed));
}
emit_changed();
}
Ref<FastNoiseLiteGradient> FastNoiseLite::get_warp_noise() const {
Ref<ZN_FastNoiseLiteGradient> ZN_FastNoiseLite::get_warp_noise() const {
return _warp_noise;
}
void FastNoiseLite::set_fractal_type(FractalType type) {
void ZN_FastNoiseLite::set_fractal_type(FractalType type) {
if (_fractal_type == type) {
return;
}
@ -98,11 +98,11 @@ void FastNoiseLite::set_fractal_type(FractalType type) {
emit_changed();
}
FastNoiseLite::FractalType FastNoiseLite::get_fractal_type() const {
ZN_FastNoiseLite::FractalType ZN_FastNoiseLite::get_fractal_type() const {
return _fractal_type;
}
void FastNoiseLite::set_fractal_octaves(int octaves) {
void ZN_FastNoiseLite::set_fractal_octaves(int octaves) {
ERR_FAIL_COND(octaves <= 0);
if (octaves > MAX_OCTAVES) {
octaves = MAX_OCTAVES;
@ -115,11 +115,11 @@ void FastNoiseLite::set_fractal_octaves(int octaves) {
emit_changed();
}
int FastNoiseLite::get_fractal_octaves() const {
int ZN_FastNoiseLite::get_fractal_octaves() const {
return _fractal_octaves;
}
void FastNoiseLite::set_fractal_lacunarity(float lacunarity) {
void ZN_FastNoiseLite::set_fractal_lacunarity(float lacunarity) {
if (_fractal_lacunarity == lacunarity) {
return;
}
@ -128,11 +128,11 @@ void FastNoiseLite::set_fractal_lacunarity(float lacunarity) {
emit_changed();
}
float FastNoiseLite::get_fractal_lacunarity() const {
float ZN_FastNoiseLite::get_fractal_lacunarity() const {
return _fractal_lacunarity;
}
void FastNoiseLite::set_fractal_gain(float gain) {
void ZN_FastNoiseLite::set_fractal_gain(float gain) {
if (_fractal_gain == gain) {
return;
}
@ -141,11 +141,11 @@ void FastNoiseLite::set_fractal_gain(float gain) {
emit_changed();
}
float FastNoiseLite::get_fractal_gain() const {
float ZN_FastNoiseLite::get_fractal_gain() const {
return _fractal_gain;
}
void FastNoiseLite::set_fractal_ping_pong_strength(float s) {
void ZN_FastNoiseLite::set_fractal_ping_pong_strength(float s) {
if (_fractal_ping_pong_strength == s) {
return;
}
@ -154,11 +154,11 @@ void FastNoiseLite::set_fractal_ping_pong_strength(float s) {
emit_changed();
}
float FastNoiseLite::get_fractal_ping_pong_strength() const {
float ZN_FastNoiseLite::get_fractal_ping_pong_strength() const {
return _fractal_ping_pong_strength;
}
void FastNoiseLite::set_fractal_weighted_strength(float s) {
void ZN_FastNoiseLite::set_fractal_weighted_strength(float s) {
if (_fractal_weighted_strength == s) {
return;
}
@ -167,11 +167,11 @@ void FastNoiseLite::set_fractal_weighted_strength(float s) {
emit_changed();
}
float FastNoiseLite::get_fractal_weighted_strength() const {
float ZN_FastNoiseLite::get_fractal_weighted_strength() const {
return _fractal_weighted_strength;
}
void FastNoiseLite::set_cellular_distance_function(CellularDistanceFunction cdf) {
void ZN_FastNoiseLite::set_cellular_distance_function(CellularDistanceFunction cdf) {
if (cdf == _cellular_distance_function) {
return;
}
@ -180,11 +180,11 @@ void FastNoiseLite::set_cellular_distance_function(CellularDistanceFunction cdf)
emit_changed();
}
FastNoiseLite::CellularDistanceFunction FastNoiseLite::get_cellular_distance_function() const {
ZN_FastNoiseLite::CellularDistanceFunction ZN_FastNoiseLite::get_cellular_distance_function() const {
return _cellular_distance_function;
}
void FastNoiseLite::set_cellular_return_type(CellularReturnType rt) {
void ZN_FastNoiseLite::set_cellular_return_type(CellularReturnType rt) {
if (_cellular_return_type == rt) {
return;
}
@ -193,11 +193,11 @@ void FastNoiseLite::set_cellular_return_type(CellularReturnType rt) {
emit_changed();
}
FastNoiseLite::CellularReturnType FastNoiseLite::get_cellular_return_type() const {
ZN_FastNoiseLite::CellularReturnType ZN_FastNoiseLite::get_cellular_return_type() const {
return _cellular_return_type;
}
void FastNoiseLite::set_cellular_jitter(float jitter) {
void ZN_FastNoiseLite::set_cellular_jitter(float jitter) {
jitter = math::clamp(jitter, 0.f, 1.f);
if (_cellular_jitter == jitter) {
return;
@ -207,11 +207,11 @@ void FastNoiseLite::set_cellular_jitter(float jitter) {
emit_changed();
}
float FastNoiseLite::get_cellular_jitter() const {
float ZN_FastNoiseLite::get_cellular_jitter() const {
return _cellular_jitter;
}
void FastNoiseLite::set_rotation_type_3d(RotationType3D type) {
void ZN_FastNoiseLite::set_rotation_type_3d(RotationType3D type) {
if (_rotation_type_3d == type) {
return;
}
@ -220,67 +220,68 @@ void FastNoiseLite::set_rotation_type_3d(RotationType3D type) {
emit_changed();
}
FastNoiseLite::RotationType3D FastNoiseLite::get_rotation_type_3d() const {
ZN_FastNoiseLite::RotationType3D ZN_FastNoiseLite::get_rotation_type_3d() const {
return _rotation_type_3d;
}
void FastNoiseLite::_on_warp_noise_changed() {
void ZN_FastNoiseLite::_on_warp_noise_changed() {
emit_changed();
}
void FastNoiseLite::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_noise_type", "type"), &FastNoiseLite::set_noise_type);
ClassDB::bind_method(D_METHOD("get_noise_type"), &FastNoiseLite::get_noise_type);
void ZN_FastNoiseLite::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_noise_type", "type"), &ZN_FastNoiseLite::set_noise_type);
ClassDB::bind_method(D_METHOD("get_noise_type"), &ZN_FastNoiseLite::get_noise_type);
ClassDB::bind_method(D_METHOD("set_seed", "seed"), &FastNoiseLite::set_seed);
ClassDB::bind_method(D_METHOD("get_seed"), &FastNoiseLite::get_seed);
ClassDB::bind_method(D_METHOD("set_seed", "seed"), &ZN_FastNoiseLite::set_seed);
ClassDB::bind_method(D_METHOD("get_seed"), &ZN_FastNoiseLite::get_seed);
ClassDB::bind_method(D_METHOD("set_period", "period"), &FastNoiseLite::set_period);
ClassDB::bind_method(D_METHOD("get_period"), &FastNoiseLite::get_period);
ClassDB::bind_method(D_METHOD("set_period", "period"), &ZN_FastNoiseLite::set_period);
ClassDB::bind_method(D_METHOD("get_period"), &ZN_FastNoiseLite::get_period);
ClassDB::bind_method(D_METHOD("set_warp_noise", "gradient_noise"), &FastNoiseLite::set_warp_noise);
ClassDB::bind_method(D_METHOD("get_warp_noise"), &FastNoiseLite::get_warp_noise);
ClassDB::bind_method(D_METHOD("set_warp_noise", "gradient_noise"), &ZN_FastNoiseLite::set_warp_noise);
ClassDB::bind_method(D_METHOD("get_warp_noise"), &ZN_FastNoiseLite::get_warp_noise);
ClassDB::bind_method(D_METHOD("set_fractal_type", "type"), &FastNoiseLite::set_fractal_type);
ClassDB::bind_method(D_METHOD("get_fractal_type"), &FastNoiseLite::get_fractal_type);
ClassDB::bind_method(D_METHOD("set_fractal_type", "type"), &ZN_FastNoiseLite::set_fractal_type);
ClassDB::bind_method(D_METHOD("get_fractal_type"), &ZN_FastNoiseLite::get_fractal_type);
ClassDB::bind_method(D_METHOD("set_fractal_octaves", "octaves"), &FastNoiseLite::set_fractal_octaves);
ClassDB::bind_method(D_METHOD("get_fractal_octaves"), &FastNoiseLite::get_fractal_octaves);
ClassDB::bind_method(D_METHOD("set_fractal_octaves", "octaves"), &ZN_FastNoiseLite::set_fractal_octaves);
ClassDB::bind_method(D_METHOD("get_fractal_octaves"), &ZN_FastNoiseLite::get_fractal_octaves);
ClassDB::bind_method(D_METHOD("set_fractal_lacunarity", "lacunarity"), &FastNoiseLite::set_fractal_lacunarity);
ClassDB::bind_method(D_METHOD("get_fractal_lacunarity"), &FastNoiseLite::get_fractal_lacunarity);
ClassDB::bind_method(D_METHOD("set_fractal_lacunarity", "lacunarity"), &ZN_FastNoiseLite::set_fractal_lacunarity);
ClassDB::bind_method(D_METHOD("get_fractal_lacunarity"), &ZN_FastNoiseLite::get_fractal_lacunarity);
ClassDB::bind_method(D_METHOD("set_fractal_gain", "gain"), &FastNoiseLite::set_fractal_gain);
ClassDB::bind_method(D_METHOD("get_fractal_gain"), &FastNoiseLite::get_fractal_gain);
ClassDB::bind_method(D_METHOD("set_fractal_gain", "gain"), &ZN_FastNoiseLite::set_fractal_gain);
ClassDB::bind_method(D_METHOD("get_fractal_gain"), &ZN_FastNoiseLite::get_fractal_gain);
ClassDB::bind_method(
D_METHOD("set_fractal_ping_pong_strength", "strength"), &FastNoiseLite::set_fractal_ping_pong_strength);
ClassDB::bind_method(D_METHOD("get_fractal_ping_pong_strength"), &FastNoiseLite::get_fractal_ping_pong_strength);
D_METHOD("set_fractal_ping_pong_strength", "strength"), &ZN_FastNoiseLite::set_fractal_ping_pong_strength);
ClassDB::bind_method(D_METHOD("get_fractal_ping_pong_strength"), &ZN_FastNoiseLite::get_fractal_ping_pong_strength);
ClassDB::bind_method(
D_METHOD("set_fractal_weighted_strength", "strength"), &FastNoiseLite::set_fractal_weighted_strength);
ClassDB::bind_method(D_METHOD("get_fractal_weighted_strength"), &FastNoiseLite::get_fractal_weighted_strength);
D_METHOD("set_fractal_weighted_strength", "strength"), &ZN_FastNoiseLite::set_fractal_weighted_strength);
ClassDB::bind_method(D_METHOD("get_fractal_weighted_strength"), &ZN_FastNoiseLite::get_fractal_weighted_strength);
ClassDB::bind_method(D_METHOD("set_cellular_distance_function", "cell_distance_func"),
&FastNoiseLite::set_cellular_distance_function);
ClassDB::bind_method(D_METHOD("get_cellular_distance_function"), &FastNoiseLite::get_cellular_distance_function);
&ZN_FastNoiseLite::set_cellular_distance_function);
ClassDB::bind_method(D_METHOD("get_cellular_distance_function"), &ZN_FastNoiseLite::get_cellular_distance_function);
ClassDB::bind_method(D_METHOD("set_cellular_return_type", "return_type"), &FastNoiseLite::set_cellular_return_type);
ClassDB::bind_method(D_METHOD("get_cellular_return_type"), &FastNoiseLite::get_cellular_return_type);
ClassDB::bind_method(
D_METHOD("set_cellular_return_type", "return_type"), &ZN_FastNoiseLite::set_cellular_return_type);
ClassDB::bind_method(D_METHOD("get_cellular_return_type"), &ZN_FastNoiseLite::get_cellular_return_type);
ClassDB::bind_method(D_METHOD("set_cellular_jitter", "return_type"), &FastNoiseLite::set_cellular_jitter);
ClassDB::bind_method(D_METHOD("get_cellular_jitter"), &FastNoiseLite::get_cellular_jitter);
ClassDB::bind_method(D_METHOD("set_cellular_jitter", "return_type"), &ZN_FastNoiseLite::set_cellular_jitter);
ClassDB::bind_method(D_METHOD("get_cellular_jitter"), &ZN_FastNoiseLite::get_cellular_jitter);
ClassDB::bind_method(D_METHOD("set_rotation_type_3d", "type"), &FastNoiseLite::set_rotation_type_3d);
ClassDB::bind_method(D_METHOD("get_rotation_type_3d"), &FastNoiseLite::get_rotation_type_3d);
ClassDB::bind_method(D_METHOD("set_rotation_type_3d", "type"), &ZN_FastNoiseLite::set_rotation_type_3d);
ClassDB::bind_method(D_METHOD("get_rotation_type_3d"), &ZN_FastNoiseLite::get_rotation_type_3d);
ClassDB::bind_method(D_METHOD("get_noise_2d", "x", "y"), &FastNoiseLite::_b_get_noise_2d);
ClassDB::bind_method(D_METHOD("get_noise_3d", "x", "y", "z"), &FastNoiseLite::_b_get_noise_3d);
ClassDB::bind_method(D_METHOD("get_noise_2d", "x", "y"), &ZN_FastNoiseLite::_b_get_noise_2d);
ClassDB::bind_method(D_METHOD("get_noise_3d", "x", "y", "z"), &ZN_FastNoiseLite::_b_get_noise_3d);
ClassDB::bind_method(D_METHOD("get_noise_2dv", "position"), &FastNoiseLite::_b_get_noise_2dv);
ClassDB::bind_method(D_METHOD("get_noise_3dv", "position"), &FastNoiseLite::_b_get_noise_3dv);
ClassDB::bind_method(D_METHOD("get_noise_2dv", "position"), &ZN_FastNoiseLite::_b_get_noise_2dv);
ClassDB::bind_method(D_METHOD("get_noise_3dv", "position"), &ZN_FastNoiseLite::_b_get_noise_3dv);
// ClassDB::bind_method(D_METHOD("_on_warp_noise_changed"), &FastNoiseLite::_on_warp_noise_changed);
// ClassDB::bind_method(D_METHOD("_on_warp_noise_changed"), &ZN_FastNoiseLite::_on_warp_noise_changed);
ADD_PROPERTY(PropertyInfo(Variant::INT, "noise_type", PROPERTY_HINT_ENUM,
"OpenSimplex2,OpenSimplex2S,Cellular,Perlin,ValueCubic,Value"),
@ -292,7 +293,7 @@ void FastNoiseLite::_bind_methods() {
"get_period");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "warp_noise", PROPERTY_HINT_RESOURCE_TYPE,
FastNoiseLiteGradient::get_class_static()),
ZN_FastNoiseLiteGradient::get_class_static()),
"set_warp_noise", "get_warp_noise");
ADD_GROUP("Fractal", "");

View File

@ -1,5 +1,5 @@
#ifndef FAST_NOISE_LITE_H
#define FAST_NOISE_LITE_H
#ifndef ZYLANN_FAST_NOISE_LITE_H
#define ZYLANN_FAST_NOISE_LITE_H
#include <core/io/resource.h>
@ -7,8 +7,30 @@
namespace zylann {
class FastNoiseLite : public Resource {
GDCLASS(FastNoiseLite, Resource)
// My own implementation of FastNoiseLite for Godot Engine.
// Godot 4 comes with its own FastNoiseLite, but mine predated it. So it needs to be prefixed to avoid conflict.
// Each has pros and cons. Godot's implementation has a few practical differences:
//
// - get_noise* methods are not inline. That means there is a potential performance loss when calling it many times
// (basically all the time in this module).
//
// - get_noise* methods are not `const`. Means any person creating a Noise implementation can mutate internal state,
// which is bad for multithreaded usage. IMO noise should not have state, and if it does, it must be explicit and not
// change "lazily". Devs aren't sure yet if they should change that.
//
// - `real_t` is used everywhere, instead of just coordinates. That means builds with `float=64` might be slower,
// especially in cases where such precision isn't necessary *for the use case of noise generation*.
//
// - Using it from a GDExtension has a lot more indirection and so will be much slower than a local implementation that
// can benefit from inlining. That could be solved with `get_noise_series(Vector3 *positions, float *noises)`, but no
// conventional Godot API allow to implement such a pattern without performance impact.
//
// - Domain warp is not exposed as its own thing, so can't generate from (x,y,z) coordinates in a single call
//
// - Does not have direct editor preview, requires to use a NoiseTexture even if the use case doesn't need it
class ZN_FastNoiseLite : public Resource {
GDCLASS(ZN_FastNoiseLite, Resource)
typedef fast_noise_lite::FastNoiseLite _FastNoise;
@ -54,7 +76,7 @@ public:
CELLULAR_RETURN_DISTANCE_2_DIV = _FastNoise::CellularReturnType_Distance2Div
};
FastNoiseLite();
ZN_FastNoiseLite();
void set_noise_type(NoiseType type);
NoiseType get_noise_type() const;
@ -65,8 +87,8 @@ public:
void set_period(float p);
float get_period() const;
void set_warp_noise(Ref<FastNoiseLiteGradient> warp_noise);
Ref<FastNoiseLiteGradient> get_warp_noise() const;
void set_warp_noise(Ref<ZN_FastNoiseLiteGradient> warp_noise);
Ref<ZN_FastNoiseLiteGradient> get_warp_noise() const;
void set_fractal_type(FractalType type);
FractalType get_fractal_type() const;
@ -161,15 +183,15 @@ private:
RotationType3D _rotation_type_3d = ROTATION_3D_NONE;
Ref<FastNoiseLiteGradient> _warp_noise;
Ref<ZN_FastNoiseLiteGradient> _warp_noise;
};
} // namespace zylann
VARIANT_ENUM_CAST(zylann::FastNoiseLite::NoiseType);
VARIANT_ENUM_CAST(zylann::FastNoiseLite::FractalType);
VARIANT_ENUM_CAST(zylann::FastNoiseLite::RotationType3D);
VARIANT_ENUM_CAST(zylann::FastNoiseLite::CellularDistanceFunction);
VARIANT_ENUM_CAST(zylann::FastNoiseLite::CellularReturnType);
VARIANT_ENUM_CAST(zylann::ZN_FastNoiseLite::NoiseType);
VARIANT_ENUM_CAST(zylann::ZN_FastNoiseLite::FractalType);
VARIANT_ENUM_CAST(zylann::ZN_FastNoiseLite::RotationType3D);
VARIANT_ENUM_CAST(zylann::ZN_FastNoiseLite::CellularDistanceFunction);
VARIANT_ENUM_CAST(zylann::ZN_FastNoiseLite::CellularReturnType);
#endif // FAST_NOISE_LITE_H
#endif // ZYLANN_FAST_NOISE_LITE_H

View File

@ -2,15 +2,15 @@
namespace zylann {
static fast_noise_lite::FastNoiseLite::FractalType to_fnl_fractal_type(FastNoiseLiteGradient::FractalType type) {
static fast_noise_lite::FastNoiseLite::FractalType to_fnl_fractal_type(ZN_FastNoiseLiteGradient::FractalType type) {
switch (type) {
case FastNoiseLiteGradient::FRACTAL_NONE:
case ZN_FastNoiseLiteGradient::FRACTAL_NONE:
return fast_noise_lite::FastNoiseLite::FractalType_None;
case FastNoiseLiteGradient::FRACTAL_DOMAIN_WARP_PROGRESSIVE:
case ZN_FastNoiseLiteGradient::FRACTAL_DOMAIN_WARP_PROGRESSIVE:
return fast_noise_lite::FastNoiseLite::FractalType_DomainWarpProgressive;
case FastNoiseLiteGradient::FRACTAL_DOMAIN_WARP_INDEPENDENT:
case ZN_FastNoiseLiteGradient::FRACTAL_DOMAIN_WARP_INDEPENDENT:
return fast_noise_lite::FastNoiseLite::FractalType_DomainWarpIndependent;
default:
@ -20,7 +20,7 @@ static fast_noise_lite::FastNoiseLite::FractalType to_fnl_fractal_type(FastNoise
return fast_noise_lite::FastNoiseLite::FractalType_None;
}
FastNoiseLiteGradient::FastNoiseLiteGradient() {
ZN_FastNoiseLiteGradient::ZN_FastNoiseLiteGradient() {
_fn.SetDomainWarpType(static_cast<_FastNoise::DomainWarpType>(_noise_type));
_fn.SetSeed(_seed);
_fn.SetFrequency(1.f / _period);
@ -34,7 +34,7 @@ FastNoiseLiteGradient::FastNoiseLiteGradient() {
_fn.SetRotationType3D(static_cast<_FastNoise::RotationType3D>(_rotation_type_3d));
}
void FastNoiseLiteGradient::set_noise_type(NoiseType type) {
void ZN_FastNoiseLiteGradient::set_noise_type(NoiseType type) {
if (_noise_type == type) {
return;
}
@ -43,11 +43,11 @@ void FastNoiseLiteGradient::set_noise_type(NoiseType type) {
emit_changed();
}
FastNoiseLiteGradient::NoiseType FastNoiseLiteGradient::get_noise_type() const {
ZN_FastNoiseLiteGradient::NoiseType ZN_FastNoiseLiteGradient::get_noise_type() const {
return _noise_type;
}
void FastNoiseLiteGradient::set_seed(int seed) {
void ZN_FastNoiseLiteGradient::set_seed(int seed) {
if (_seed == seed) {
return;
}
@ -56,11 +56,11 @@ void FastNoiseLiteGradient::set_seed(int seed) {
emit_changed();
}
int FastNoiseLiteGradient::get_seed() const {
int ZN_FastNoiseLiteGradient::get_seed() const {
return _seed;
}
void FastNoiseLiteGradient::set_period(float p) {
void ZN_FastNoiseLiteGradient::set_period(float p) {
if (p < 0.0001f) {
p = 0.0001f;
}
@ -72,11 +72,11 @@ void FastNoiseLiteGradient::set_period(float p) {
emit_changed();
}
float FastNoiseLiteGradient::get_period() const {
float ZN_FastNoiseLiteGradient::get_period() const {
return _period;
}
void FastNoiseLiteGradient::set_amplitude(float amp) {
void ZN_FastNoiseLiteGradient::set_amplitude(float amp) {
if (amp == _amplitude) {
return;
}
@ -85,11 +85,11 @@ void FastNoiseLiteGradient::set_amplitude(float amp) {
emit_changed();
}
float FastNoiseLiteGradient::get_amplitude() const {
float ZN_FastNoiseLiteGradient::get_amplitude() const {
return _amplitude;
}
void FastNoiseLiteGradient::set_fractal_type(FractalType type) {
void ZN_FastNoiseLiteGradient::set_fractal_type(FractalType type) {
if (type == _fractal_type) {
return;
}
@ -98,11 +98,11 @@ void FastNoiseLiteGradient::set_fractal_type(FractalType type) {
emit_changed();
}
FastNoiseLiteGradient::FractalType FastNoiseLiteGradient::get_fractal_type() const {
ZN_FastNoiseLiteGradient::FractalType ZN_FastNoiseLiteGradient::get_fractal_type() const {
return _fractal_type;
}
void FastNoiseLiteGradient::set_fractal_octaves(int octaves) {
void ZN_FastNoiseLiteGradient::set_fractal_octaves(int octaves) {
if (_fractal_octaves == octaves) {
return;
}
@ -111,11 +111,11 @@ void FastNoiseLiteGradient::set_fractal_octaves(int octaves) {
emit_changed();
}
int FastNoiseLiteGradient::get_fractal_octaves() const {
int ZN_FastNoiseLiteGradient::get_fractal_octaves() const {
return _fractal_octaves;
}
void FastNoiseLiteGradient::set_fractal_lacunarity(float lacunarity) {
void ZN_FastNoiseLiteGradient::set_fractal_lacunarity(float lacunarity) {
if (_fractal_lacunarity == lacunarity) {
return;
}
@ -124,11 +124,11 @@ void FastNoiseLiteGradient::set_fractal_lacunarity(float lacunarity) {
emit_changed();
}
float FastNoiseLiteGradient::get_fractal_lacunarity() const {
float ZN_FastNoiseLiteGradient::get_fractal_lacunarity() const {
return _fractal_lacunarity;
}
void FastNoiseLiteGradient::set_fractal_gain(float gain) {
void ZN_FastNoiseLiteGradient::set_fractal_gain(float gain) {
if (_fractal_gain == gain) {
return;
}
@ -137,11 +137,11 @@ void FastNoiseLiteGradient::set_fractal_gain(float gain) {
emit_changed();
}
float FastNoiseLiteGradient::get_fractal_gain() const {
float ZN_FastNoiseLiteGradient::get_fractal_gain() const {
return _fractal_gain;
}
void FastNoiseLiteGradient::set_rotation_type_3d(RotationType3D type) {
void ZN_FastNoiseLiteGradient::set_rotation_type_3d(RotationType3D type) {
if (_rotation_type_3d == type) {
return;
}
@ -150,41 +150,41 @@ void FastNoiseLiteGradient::set_rotation_type_3d(RotationType3D type) {
emit_changed();
}
FastNoiseLiteGradient::RotationType3D FastNoiseLiteGradient::get_rotation_type_3d() const {
ZN_FastNoiseLiteGradient::RotationType3D ZN_FastNoiseLiteGradient::get_rotation_type_3d() const {
return _rotation_type_3d;
}
void FastNoiseLiteGradient::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_noise_type", "type"), &FastNoiseLiteGradient::set_noise_type);
ClassDB::bind_method(D_METHOD("get_noise_type"), &FastNoiseLiteGradient::get_noise_type);
void ZN_FastNoiseLiteGradient::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_noise_type", "type"), &ZN_FastNoiseLiteGradient::set_noise_type);
ClassDB::bind_method(D_METHOD("get_noise_type"), &ZN_FastNoiseLiteGradient::get_noise_type);
ClassDB::bind_method(D_METHOD("set_seed", "seed"), &FastNoiseLiteGradient::set_seed);
ClassDB::bind_method(D_METHOD("get_seed"), &FastNoiseLiteGradient::get_seed);
ClassDB::bind_method(D_METHOD("set_seed", "seed"), &ZN_FastNoiseLiteGradient::set_seed);
ClassDB::bind_method(D_METHOD("get_seed"), &ZN_FastNoiseLiteGradient::get_seed);
ClassDB::bind_method(D_METHOD("set_period", "period"), &FastNoiseLiteGradient::set_period);
ClassDB::bind_method(D_METHOD("get_period"), &FastNoiseLiteGradient::get_period);
ClassDB::bind_method(D_METHOD("set_period", "period"), &ZN_FastNoiseLiteGradient::set_period);
ClassDB::bind_method(D_METHOD("get_period"), &ZN_FastNoiseLiteGradient::get_period);
ClassDB::bind_method(D_METHOD("set_amplitude", "amplitude"), &FastNoiseLiteGradient::set_amplitude);
ClassDB::bind_method(D_METHOD("get_amplitude"), &FastNoiseLiteGradient::get_amplitude);
ClassDB::bind_method(D_METHOD("set_amplitude", "amplitude"), &ZN_FastNoiseLiteGradient::set_amplitude);
ClassDB::bind_method(D_METHOD("get_amplitude"), &ZN_FastNoiseLiteGradient::get_amplitude);
ClassDB::bind_method(D_METHOD("set_fractal_type", "type"), &FastNoiseLiteGradient::set_fractal_type);
ClassDB::bind_method(D_METHOD("get_fractal_type"), &FastNoiseLiteGradient::get_fractal_type);
ClassDB::bind_method(D_METHOD("set_fractal_type", "type"), &ZN_FastNoiseLiteGradient::set_fractal_type);
ClassDB::bind_method(D_METHOD("get_fractal_type"), &ZN_FastNoiseLiteGradient::get_fractal_type);
ClassDB::bind_method(D_METHOD("set_fractal_octaves", "octaves"), &FastNoiseLiteGradient::set_fractal_octaves);
ClassDB::bind_method(D_METHOD("get_fractal_octaves"), &FastNoiseLiteGradient::get_fractal_octaves);
ClassDB::bind_method(D_METHOD("set_fractal_octaves", "octaves"), &ZN_FastNoiseLiteGradient::set_fractal_octaves);
ClassDB::bind_method(D_METHOD("get_fractal_octaves"), &ZN_FastNoiseLiteGradient::get_fractal_octaves);
ClassDB::bind_method(
D_METHOD("set_fractal_lacunarity", "lacunarity"), &FastNoiseLiteGradient::set_fractal_lacunarity);
ClassDB::bind_method(D_METHOD("get_fractal_lacunarity"), &FastNoiseLiteGradient::get_fractal_lacunarity);
D_METHOD("set_fractal_lacunarity", "lacunarity"), &ZN_FastNoiseLiteGradient::set_fractal_lacunarity);
ClassDB::bind_method(D_METHOD("get_fractal_lacunarity"), &ZN_FastNoiseLiteGradient::get_fractal_lacunarity);
ClassDB::bind_method(D_METHOD("set_fractal_gain", "gain"), &FastNoiseLiteGradient::set_fractal_gain);
ClassDB::bind_method(D_METHOD("get_fractal_gain"), &FastNoiseLiteGradient::get_fractal_gain);
ClassDB::bind_method(D_METHOD("set_fractal_gain", "gain"), &ZN_FastNoiseLiteGradient::set_fractal_gain);
ClassDB::bind_method(D_METHOD("get_fractal_gain"), &ZN_FastNoiseLiteGradient::get_fractal_gain);
ClassDB::bind_method(D_METHOD("set_rotation_type_3d", "type"), &FastNoiseLiteGradient::set_rotation_type_3d);
ClassDB::bind_method(D_METHOD("get_rotation_type_3d"), &FastNoiseLiteGradient::get_rotation_type_3d);
ClassDB::bind_method(D_METHOD("set_rotation_type_3d", "type"), &ZN_FastNoiseLiteGradient::set_rotation_type_3d);
ClassDB::bind_method(D_METHOD("get_rotation_type_3d"), &ZN_FastNoiseLiteGradient::get_rotation_type_3d);
ClassDB::bind_method(D_METHOD("warp_2d", "position"), &FastNoiseLiteGradient::_b_warp_2d);
ClassDB::bind_method(D_METHOD("warp_3d", "position"), &FastNoiseLiteGradient::_b_warp_3d);
ClassDB::bind_method(D_METHOD("warp_2d", "position"), &ZN_FastNoiseLiteGradient::_b_warp_2d);
ClassDB::bind_method(D_METHOD("warp_3d", "position"), &ZN_FastNoiseLiteGradient::_b_warp_3d);
ADD_PROPERTY(PropertyInfo(Variant::INT, "noise_type", PROPERTY_HINT_ENUM, "OpenSimplex2,OpenSimplex2Reduced,Value"),
"set_noise_type", "get_noise_type");

View File

@ -1,9 +1,9 @@
#ifndef FAST_NOISE_LITE_GRADIENT_H
#define FAST_NOISE_LITE_GRADIENT_H
#ifndef ZYLANN_FAST_NOISE_LITE_GRADIENT_H
#define ZYLANN_FAST_NOISE_LITE_GRADIENT_H
#include <core/io/resource.h>
#include "../../thirdparty/fast_noise/FastNoiseLite.h"
#include "../../../thirdparty/fast_noise/FastNoiseLite.h"
namespace zylann {
@ -15,8 +15,8 @@ namespace zylann {
// Note: FastNoiseLite provides this with the same class, but then its unclear which applies to what,
// so I made two classes, each with a specific purpose.
//
class FastNoiseLiteGradient : public Resource {
GDCLASS(FastNoiseLiteGradient, Resource)
class ZN_FastNoiseLiteGradient : public Resource {
GDCLASS(ZN_FastNoiseLiteGradient, Resource)
typedef fast_noise_lite::FastNoiseLite _FastNoise;
@ -44,7 +44,7 @@ public:
ROTATION_3D_IMPROVE_XZ_PLANES = _FastNoise::RotationType3D_ImproveXZPlanes
};
FastNoiseLiteGradient();
ZN_FastNoiseLiteGradient();
void set_noise_type(NoiseType type);
NoiseType get_noise_type() const;
@ -121,8 +121,8 @@ private:
} // namespace zylann
VARIANT_ENUM_CAST(zylann::FastNoiseLiteGradient::NoiseType);
VARIANT_ENUM_CAST(zylann::FastNoiseLiteGradient::FractalType);
VARIANT_ENUM_CAST(zylann::FastNoiseLiteGradient::RotationType3D);
VARIANT_ENUM_CAST(zylann::ZN_FastNoiseLiteGradient::NoiseType);
VARIANT_ENUM_CAST(zylann::ZN_FastNoiseLiteGradient::FractalType);
VARIANT_ENUM_CAST(zylann::ZN_FastNoiseLiteGradient::RotationType3D);
#endif // FAST_NOISE_LITE_GRADIENT_H
#endif // ZYLANN_FAST_NOISE_LITE_GRADIENT_H

View File

@ -1,12 +1,12 @@
#include "fast_noise_lite_range.h"
#include "../noise_range_utility.h"
#include "fast_noise_lite.h"
#include "noise_range_utility.h"
#include "fast_noise_lite_gradient.h"
namespace zylann {
using namespace math;
static Interval get_fnl_cellular_value_range_2d(const FastNoiseLite &noise, Interval x, Interval y) {
static Interval get_fnl_cellular_value_range_2d(const ZN_FastNoiseLite &noise, Interval x, Interval y) {
const float c0 = noise.get_noise_2d(x.min, y.min);
const float c1 = noise.get_noise_2d(x.max, y.min);
const float c2 = noise.get_noise_2d(x.min, y.max);
@ -33,81 +33,81 @@ static Interval get_fnl_cellular_value_range_3d(
return Interval{ -1, 1 };
}
static Interval get_fnl_cellular_range(const FastNoiseLite &noise) {
static Interval get_fnl_cellular_range(const ZN_FastNoiseLite &noise) {
// There are many combinations with Cellular noise so instead of implementing them with intervals,
// I used empiric tests to figure out some bounds.
// Value mode must be handled separately.
switch (noise.get_cellular_distance_function()) {
case FastNoiseLite::CELLULAR_DISTANCE_EUCLIDEAN:
case ZN_FastNoiseLite::CELLULAR_DISTANCE_EUCLIDEAN:
switch (noise.get_cellular_return_type()) {
case FastNoiseLite::CELLULAR_RETURN_DISTANCE:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE:
return Interval{ -1.f, 0.08f };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2:
return Interval{ -0.92f, 0.35 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_ADD:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_ADD:
return Interval{ -0.92f, 0.1 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_SUB:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_SUB:
return Interval{ -1, 0.15 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_MUL:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_MUL:
return Interval{ -1, 0 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_DIV:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_DIV:
return Interval{ -1, 0 };
default:
ERR_FAIL_V(Interval(-1, 1));
}
break;
case FastNoiseLite::CELLULAR_DISTANCE_EUCLIDEAN_SQ:
case ZN_FastNoiseLite::CELLULAR_DISTANCE_EUCLIDEAN_SQ:
switch (noise.get_cellular_return_type()) {
case FastNoiseLite::CELLULAR_RETURN_DISTANCE:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE:
return Interval{ -1, 0.2 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2:
return Interval{ -1, 0.8 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_ADD:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_ADD:
return Interval{ -1, 0.2 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_SUB:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_SUB:
return Interval{ -1, 0.7 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_MUL:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_MUL:
return Interval{ -1, 0 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_DIV:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_DIV:
return Interval{ -1, 0 };
default:
ERR_FAIL_V(Interval(-1, 1));
}
case FastNoiseLite::CELLULAR_DISTANCE_MANHATTAN:
case ZN_FastNoiseLite::CELLULAR_DISTANCE_MANHATTAN:
switch (noise.get_cellular_return_type()) {
case FastNoiseLite::CELLULAR_RETURN_DISTANCE:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE:
return Interval{ -1, 0.75 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2:
return Interval{ -0.9, 0.8 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_ADD:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_ADD:
return Interval{ -0.8, 0.8 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_SUB:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_SUB:
return Interval{ -1.0, 0.5 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_MUL:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_MUL:
return Interval{ -1.0, 0.7 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_DIV:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_DIV:
return Interval{ -1.0, 0.0 };
default:
ERR_FAIL_V(Interval(-1, 1));
}
case FastNoiseLite::CELLULAR_DISTANCE_HYBRID:
case ZN_FastNoiseLite::CELLULAR_DISTANCE_HYBRID:
switch (noise.get_cellular_return_type()) {
case FastNoiseLite::CELLULAR_RETURN_DISTANCE:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE:
return Interval{ -1, 1.75 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2:
return Interval{ -0.9, 2.3 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_ADD:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_ADD:
return Interval{ -0.9, 1.9 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_SUB:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_SUB:
return Interval{ -1.0, 1.85 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_MUL:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_MUL:
return Interval{ -1.0, 3.4 };
case FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_DIV:
case ZN_FastNoiseLite::CELLULAR_RETURN_DISTANCE_2_DIV:
return Interval{ -1.0, 0.0 };
default:
ERR_FAIL_V(Interval(-1, 1));
@ -175,7 +175,7 @@ Interval fnl_single_opensimplex2s(
p_x, p_y, p_z, 2.5f);
}
Interval fnl_single_cellular(const FastNoiseLite &noise, Interval x, Interval y, Interval z) {
Interval fnl_single_cellular(const ZN_FastNoiseLite &noise, Interval x, Interval y, Interval z) {
const fast_noise_lite::FastNoiseLite &fn = noise.get_noise_internal();
if (fn.mCellularReturnType == fast_noise_lite::FastNoiseLite::CellularReturnType_CellValue) {
return get_fnl_cellular_value_range_3d(fn, x, y, z);
@ -213,7 +213,7 @@ Interval fnl_single_value(
p_x, p_y, p_z, 3.0f);
}
Interval fnl_gen_noise_single(const FastNoiseLite &noise, int seed, Interval x, Interval y, Interval z) {
Interval fnl_gen_noise_single(const ZN_FastNoiseLite &noise, int seed, Interval x, Interval y, Interval z) {
// Same logic as in the FastNoiseLite internal function
const fast_noise_lite::FastNoiseLite &fn = noise.get_noise_internal();
@ -235,7 +235,7 @@ Interval fnl_gen_noise_single(const FastNoiseLite &noise, int seed, Interval x,
}
}
Interval fnl_gen_fractal_fbm(const FastNoiseLite &p_noise, Interval x, Interval y, Interval z) {
Interval fnl_gen_fractal_fbm(const ZN_FastNoiseLite &p_noise, Interval x, Interval y, Interval z) {
// Same logic as in the FastNoiseLite internal function
const fast_noise_lite::FastNoiseLite &fn = p_noise.get_noise_internal();
@ -258,7 +258,7 @@ Interval fnl_gen_fractal_fbm(const FastNoiseLite &p_noise, Interval x, Interval
return sum;
}
Interval fnl_gen_fractal_ridged(const FastNoiseLite &p_noise, Interval x, Interval y, Interval z) {
Interval fnl_gen_fractal_ridged(const ZN_FastNoiseLite &p_noise, Interval x, Interval y, Interval z) {
// Same logic as in the FastNoiseLite internal function
const fast_noise_lite::FastNoiseLite &fn = p_noise.get_noise_internal();
@ -281,7 +281,7 @@ Interval fnl_gen_fractal_ridged(const FastNoiseLite &p_noise, Interval x, Interv
return sum;
}
Interval fnl_get_noise(const FastNoiseLite &noise, Interval x, Interval y, Interval z) {
Interval fnl_get_noise(const ZN_FastNoiseLite &noise, Interval x, Interval y, Interval z) {
// Same logic as in the FastNoiseLite internal function
const fast_noise_lite::FastNoiseLite &fn = noise.get_noise_internal();
@ -290,22 +290,22 @@ Interval fnl_get_noise(const FastNoiseLite &noise, Interval x, Interval y, Inter
switch (noise.get_fractal_type()) {
default:
return fnl_gen_noise_single(noise, noise.get_seed(), x, y, z);
case FastNoiseLite::FRACTAL_FBM:
case ZN_FastNoiseLite::FRACTAL_FBM:
return fnl_gen_fractal_fbm(noise, x, y, z);
case FastNoiseLite::FRACTAL_RIDGED:
case ZN_FastNoiseLite::FRACTAL_RIDGED:
return fnl_gen_fractal_ridged(noise, x, y, z);
case FastNoiseLite::FRACTAL_PING_PONG:
case ZN_FastNoiseLite::FRACTAL_PING_PONG:
// TODO Ping pong
return Interval(-1.f, 1.f);
}
}
Interval get_fnl_range_2d(const FastNoiseLite &noise, Interval x, Interval y) {
Interval get_fnl_range_2d(const ZN_FastNoiseLite &noise, Interval x, Interval y) {
// TODO More precise analysis using derivatives
// TODO Take warp noise into account
switch (noise.get_noise_type()) {
case FastNoiseLite::TYPE_CELLULAR:
if (noise.get_cellular_return_type() == FastNoiseLite::CELLULAR_RETURN_CELL_VALUE) {
case ZN_FastNoiseLite::TYPE_CELLULAR:
if (noise.get_cellular_return_type() == ZN_FastNoiseLite::CELLULAR_RETURN_CELL_VALUE) {
return get_fnl_cellular_value_range_2d(noise, x, y);
}
return get_fnl_cellular_range(noise);
@ -314,14 +314,14 @@ Interval get_fnl_range_2d(const FastNoiseLite &noise, Interval x, Interval y) {
}
}
Interval get_fnl_range_3d(const FastNoiseLite &noise, Interval x, Interval y, Interval z) {
Interval get_fnl_range_3d(const ZN_FastNoiseLite &noise, Interval x, Interval y, Interval z) {
if (noise.get_warp_noise().is_null()) {
return fnl_get_noise(noise, x, y, z);
}
// TODO Take warp noise into account
switch (noise.get_noise_type()) {
case FastNoiseLite::TYPE_CELLULAR:
if (noise.get_cellular_return_type() == FastNoiseLite::CELLULAR_RETURN_CELL_VALUE) {
case ZN_FastNoiseLite::TYPE_CELLULAR:
if (noise.get_cellular_return_type() == ZN_FastNoiseLite::CELLULAR_RETURN_CELL_VALUE) {
return get_fnl_cellular_value_range_3d(noise.get_noise_internal(), x, y, z);
}
return get_fnl_cellular_range(noise);
@ -330,7 +330,7 @@ Interval get_fnl_range_3d(const FastNoiseLite &noise, Interval x, Interval y, In
}
}
math::Interval2 get_fnl_gradient_range_2d(const FastNoiseLiteGradient &noise, Interval x, Interval y) {
math::Interval2 get_fnl_gradient_range_2d(const ZN_FastNoiseLiteGradient &noise, Interval x, Interval y) {
// TODO More precise analysis
const float amp = Math::abs(noise.get_amplitude());
return math::Interval2{ //
@ -339,7 +339,7 @@ math::Interval2 get_fnl_gradient_range_2d(const FastNoiseLiteGradient &noise, In
};
}
math::Interval3 get_fnl_gradient_range_3d(const FastNoiseLiteGradient &noise, Interval x, Interval y, Interval z) {
math::Interval3 get_fnl_gradient_range_3d(const ZN_FastNoiseLiteGradient &noise, Interval x, Interval y, Interval z) {
// TODO More precise analysis
const float amp = Math::abs(noise.get_amplitude());
return math::Interval3{

View File

@ -0,0 +1,21 @@
#ifndef FAST_NOISE_LITE_RANGE_H
#define FAST_NOISE_LITE_RANGE_H
#include "../../math/interval.h"
// Interval estimation for ZN_FastNoiseLite
namespace zylann {
class ZN_FastNoiseLite;
class ZN_FastNoiseLiteGradient;
math::Interval get_fnl_range_2d(const ZN_FastNoiseLite &noise, math::Interval x, math::Interval y);
math::Interval get_fnl_range_3d(const ZN_FastNoiseLite &noise, math::Interval x, math::Interval y, math::Interval z);
math::Interval2 get_fnl_gradient_range_2d(const ZN_FastNoiseLiteGradient &noise, math::Interval x, math::Interval y);
math::Interval3 get_fnl_gradient_range_3d(
const ZN_FastNoiseLiteGradient &noise, math::Interval x, math::Interval y, math::Interval z);
} // namespace zylann
#endif // FAST_NOISE_LITE_RANGE_H

View File

@ -1,21 +0,0 @@
#ifndef FAST_NOISE_LITE_RANGE_H
#define FAST_NOISE_LITE_RANGE_H
#include "../math/interval.h"
// Interval estimation for FastNoiseLite
namespace zylann {
class FastNoiseLite;
class FastNoiseLiteGradient;
math::Interval get_fnl_range_2d(const FastNoiseLite &noise, math::Interval x, math::Interval y);
math::Interval get_fnl_range_3d(const FastNoiseLite &noise, math::Interval x, math::Interval y, math::Interval z);
math::Interval2 get_fnl_gradient_range_2d(const FastNoiseLiteGradient &noise, math::Interval x, math::Interval y);
math::Interval3 get_fnl_gradient_range_3d(
const FastNoiseLiteGradient &noise, math::Interval x, math::Interval y, math::Interval z);
} // namespace zylann
#endif // FAST_NOISE_LITE_RANGE_H

View File

@ -0,0 +1,15 @@
#include "gd_noise_range.h"
namespace zylann {
math::Interval get_range_2d(const Noise &noise, math::Interval x, math::Interval y) {
// TODO Implement Godot's Noise range analysis
return { -1.f, 1.f };
}
math::Interval get_range_3d(const Noise &noise, math::Interval x, math::Interval y, math::Interval z) {
// TODO Implement Godot's Noise range analysis
return { -1.f, 1.f };
}
} // namespace zylann

View File

@ -0,0 +1,15 @@
#ifndef VOXEL_GD_NOISE_RANGE_H
#define VOXEL_GD_NOISE_RANGE_H
#include "../math/interval.h"
class Noise;
namespace zylann {
math::Interval get_range_2d(const Noise &noise, math::Interval x, math::Interval y);
math::Interval get_range_3d(const Noise &noise, math::Interval x, math::Interval y, math::Interval z);
} // namespace zylann
#endif // VOXEL_GD_NOISE_RANGE_H

View File

@ -1,80 +0,0 @@
#include "osn_noise_range.h"
#include "noise_range_utility.h"
#include <modules/opensimplex/open_simplex_noise.h>
namespace zylann {
using namespace math;
Interval get_osn_octave_range_2d(const OpenSimplexNoise &noise, const Interval &p_x, const Interval &p_y, int octave) {
return get_noise_range_2d(
[octave, &noise](real_t x, real_t y) { //
return noise._get_octave_noise_2d(octave, x, y);
},
p_x, p_y, 2.35f);
}
Interval get_osn_octave_range_3d(
const OpenSimplexNoise &noise, const Interval &p_x, const Interval &p_y, const Interval &p_z, int octave) {
return get_noise_range_3d(
[octave, &noise](real_t x, real_t y, real_t z) { //
return noise._get_octave_noise_3d(octave, x, y, z);
},
p_x, p_y, p_z, 2.5f);
}
Interval get_osn_range_2d(const OpenSimplexNoise &noise, Interval x, Interval y) {
// Same implementation as `get_noise_2d`
if (x.is_single_value() && y.is_single_value()) {
return Interval::from_single_value(noise.get_noise_2d(x.min, y.min));
}
x /= noise.get_period();
y /= noise.get_period();
float amp = 1.0;
float max = 1.0;
Interval sum = get_osn_octave_range_2d(noise, x, y, 0);
int i = 0;
while (++i < noise.get_octaves()) {
x *= noise.get_lacunarity();
y *= noise.get_lacunarity();
amp *= noise.get_persistence();
max += amp;
sum += get_osn_octave_range_2d(noise, x, y, i) * amp;
}
return sum / max;
}
Interval get_osn_range_3d(const OpenSimplexNoise &noise, Interval x, Interval y, Interval z) {
// Same implementation as `get_noise_3d`
if (x.is_single_value() && y.is_single_value()) {
return Interval::from_single_value(noise.get_noise_2d(x.min, y.min));
}
x /= noise.get_period();
y /= noise.get_period();
z /= noise.get_period();
float amp = 1.0;
float max = 1.0;
Interval sum = get_osn_octave_range_3d(noise, x, y, z, 0);
int i = 0;
while (++i < noise.get_octaves()) {
x *= noise.get_lacunarity();
y *= noise.get_lacunarity();
z *= noise.get_lacunarity();
amp *= noise.get_persistence();
max += amp;
sum += get_osn_octave_range_3d(noise, x, y, z, i) * amp;
}
return sum / max;
}
} // namespace zylann

View File

@ -1,17 +0,0 @@
#ifndef OSN_NOISE_RANGE_H
#define OSN_NOISE_RANGE_H
#include "../math/interval.h"
// Interval estimation for Godot's OpenSimplexNoise
class OpenSimplexNoise;
namespace zylann {
math::Interval get_osn_range_2d(const OpenSimplexNoise &noise, math::Interval x, math::Interval y);
math::Interval get_osn_range_3d(const OpenSimplexNoise &noise, math::Interval x, math::Interval y, math::Interval z);
} // namespace zylann
#endif // OSN_NOISE_RANGE_H