diff options
Diffstat (limited to 'modules/opensimplex/open_simplex_noise.cpp')
-rw-r--r-- | modules/opensimplex/open_simplex_noise.cpp | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/modules/opensimplex/open_simplex_noise.cpp b/modules/opensimplex/open_simplex_noise.cpp index aded4d2a07..3773946112 100644 --- a/modules/opensimplex/open_simplex_noise.cpp +++ b/modules/opensimplex/open_simplex_noise.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ @@ -33,12 +33,6 @@ #include "core/core_string_names.h" OpenSimplexNoise::OpenSimplexNoise() { - seed = 0; - persistence = 0.5; - octaves = 3; - period = 64; - lacunarity = 2.0; - _init_seeds(); } @@ -104,7 +98,7 @@ void OpenSimplexNoise::set_lacunarity(float p_lacunarity) { Ref<Image> OpenSimplexNoise::get_image(int p_width, int p_height) const { Vector<uint8_t> data; - data.resize(p_width * p_height * 4); + data.resize(p_width * p_height); uint8_t *wd8 = data.ptrw(); @@ -112,21 +106,17 @@ Ref<Image> OpenSimplexNoise::get_image(int p_width, int p_height) const { for (int j = 0; j < p_width; j++) { float v = get_noise_2d(j, i); v = v * 0.5 + 0.5; // Normalize [0..1] - uint8_t value = uint8_t(CLAMP(v * 255.0, 0, 255)); - wd8[(i * p_width + j) * 4 + 0] = value; - wd8[(i * p_width + j) * 4 + 1] = value; - wd8[(i * p_width + j) * 4 + 2] = value; - wd8[(i * p_width + j) * 4 + 3] = 255; + 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_RGBA8, data)); + 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 * 4); + data.resize(p_size * p_size); uint8_t *wd8 = data.ptrw(); @@ -135,10 +125,10 @@ Ref<Image> OpenSimplexNoise::get_seamless_image(int p_size) const { float ii = (float)i / (float)p_size; float jj = (float)j / (float)p_size; - ii *= 2.0 * Math_PI; - jj *= 2.0 * Math_PI; + ii *= Math_TAU; + jj *= Math_TAU; - float radius = p_size / (2.0 * Math_PI); + float radius = p_size / Math_TAU; float x = radius * Math::sin(jj); float y = radius * Math::cos(jj); @@ -147,15 +137,11 @@ Ref<Image> OpenSimplexNoise::get_seamless_image(int p_size) const { float v = get_noise_4d(x, y, z, w); v = v * 0.5 + 0.5; // Normalize [0..1] - uint8_t value = uint8_t(CLAMP(v * 255.0, 0, 255)); - wd8[(i * p_size + j) * 4 + 0] = value; - wd8[(i * p_size + j) * 4 + 1] = value; - wd8[(i * p_size + j) * 4 + 2] = value; - wd8[(i * p_size + j) * 4 + 3] = 255; + 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_RGBA8, data)); + Ref<Image> image = memnew(Image(p_size, p_size, false, Image::FORMAT_L8, data)); return image; } |