2018-08-25 00:25:06 +02:00
|
|
|
/**************************************************************************/
|
2022-08-25 01:08:09 +02:00
|
|
|
/* noise_texture_2d.cpp */
|
2018-08-25 00:25:06 +02:00
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
#include "noise_texture_2d.h"
|
2018-08-25 00:25:06 +02:00
|
|
|
|
2022-03-20 14:53:45 +01:00
|
|
|
#include "noise.h"
|
2018-08-25 00:25:06 +02:00
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
NoiseTexture2D::NoiseTexture2D() {
|
2022-03-20 14:53:45 +01:00
|
|
|
noise = Ref<Noise>();
|
2018-08-25 00:25:06 +02:00
|
|
|
|
|
|
|
_queue_update();
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
NoiseTexture2D::~NoiseTexture2D() {
|
2022-12-12 18:42:37 +01:00
|
|
|
ERR_FAIL_NULL(RenderingServer::get_singleton());
|
2019-06-11 20:43:37 +02:00
|
|
|
if (texture.is_valid()) {
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->free(texture);
|
2019-06-11 20:43:37 +02:00
|
|
|
}
|
2023-04-27 18:34:30 +02:00
|
|
|
if (noise_thread.is_started()) {
|
|
|
|
noise_thread.wait_to_finish();
|
|
|
|
}
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_width", "width"), &NoiseTexture2D::set_width);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_height", "height"), &NoiseTexture2D::set_height);
|
2018-08-25 00:25:06 +02:00
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_invert", "invert"), &NoiseTexture2D::set_invert);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_invert"), &NoiseTexture2D::get_invert);
|
2021-05-18 06:51:05 +02:00
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_in_3d_space", "enable"), &NoiseTexture2D::set_in_3d_space);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_in_3d_space"), &NoiseTexture2D::is_in_3d_space);
|
2022-04-19 19:48:25 +02:00
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_generate_mipmaps", "invert"), &NoiseTexture2D::set_generate_mipmaps);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_generating_mipmaps"), &NoiseTexture2D::is_generating_mipmaps);
|
2022-04-19 19:48:25 +02:00
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_seamless", "seamless"), &NoiseTexture2D::set_seamless);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_seamless"), &NoiseTexture2D::get_seamless);
|
2018-08-25 00:25:06 +02:00
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_seamless_blend_skirt", "seamless_blend_skirt"), &NoiseTexture2D::set_seamless_blend_skirt);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_seamless_blend_skirt"), &NoiseTexture2D::get_seamless_blend_skirt);
|
2022-03-20 14:53:45 +01:00
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_as_normal_map", "as_normal_map"), &NoiseTexture2D::set_as_normal_map);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_normal_map"), &NoiseTexture2D::is_normal_map);
|
2018-08-25 00:25:06 +02:00
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bump_strength", "bump_strength"), &NoiseTexture2D::set_bump_strength);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bump_strength"), &NoiseTexture2D::get_bump_strength);
|
2019-03-03 19:50:55 +01:00
|
|
|
|
2023-01-29 14:56:10 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_normalize", "normalize"), &NoiseTexture2D::set_normalize);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_normalized"), &NoiseTexture2D::is_normalized);
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_color_ramp", "gradient"), &NoiseTexture2D::set_color_ramp);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_color_ramp"), &NoiseTexture2D::get_color_ramp);
|
2022-04-19 19:48:25 +02:00
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_noise", "noise"), &NoiseTexture2D::set_noise);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_noise"), &NoiseTexture2D::get_noise);
|
2018-08-25 00:25:06 +02:00
|
|
|
|
2022-05-20 07:24:41 +02:00
|
|
|
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");
|
2022-03-20 14:53:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "invert"), "set_invert", "get_invert");
|
2022-04-19 19:48:25 +02:00
|
|
|
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");
|
2018-08-25 00:25:06 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "seamless"), "set_seamless", "get_seamless");
|
2023-01-06 02:46:08 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "seamless_blend_skirt", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_seamless_blend_skirt", "get_seamless_blend_skirt");
|
2020-12-23 10:34:26 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "as_normal_map"), "set_as_normal_map", "is_normal_map");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bump_strength", PROPERTY_HINT_RANGE, "0,32,0.1,or_greater"), "set_bump_strength", "get_bump_strength");
|
2023-01-29 14:56:10 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "normalize"), "set_normalize", "is_normalized");
|
2022-04-19 19:48:25 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "color_ramp", PROPERTY_HINT_RESOURCE_TYPE, "Gradient"), "set_color_ramp", "get_color_ramp");
|
2022-03-20 14:53:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "noise", PROPERTY_HINT_RESOURCE_TYPE, "Noise"), "set_noise", "get_noise");
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::_validate_property(PropertyInfo &p_property) const {
|
2022-08-12 22:57:11 +02:00
|
|
|
if (p_property.name == "bump_strength") {
|
2020-12-23 10:34:26 +01:00
|
|
|
if (!as_normal_map) {
|
2022-08-12 22:57:11 +02:00
|
|
|
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
|
2019-03-03 19:50:55 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-20 14:53:45 +01:00
|
|
|
|
2022-08-12 22:57:11 +02:00
|
|
|
if (p_property.name == "seamless_blend_skirt") {
|
2022-03-20 14:53:45 +01:00
|
|
|
if (!seamless) {
|
2022-08-12 22:57:11 +02:00
|
|
|
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
|
2022-03-20 14:53:45 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-03 19:50:55 +01:00
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::_set_texture_image(const Ref<Image> &p_image) {
|
2021-03-28 13:32:17 +02:00
|
|
|
image = p_image;
|
|
|
|
if (image.is_valid()) {
|
2019-06-11 20:43:37 +02:00
|
|
|
if (texture.is_valid()) {
|
2020-03-27 19:21:27 +01:00
|
|
|
RID new_texture = RS::get_singleton()->texture_2d_create(p_image);
|
|
|
|
RS::get_singleton()->texture_replace(texture, new_texture);
|
2019-06-11 20:43:37 +02:00
|
|
|
} else {
|
2020-03-27 19:21:27 +01:00
|
|
|
texture = RS::get_singleton()->texture_2d_create(p_image);
|
2019-06-11 20:43:37 +02:00
|
|
|
}
|
2024-05-16 01:30:19 +02:00
|
|
|
RS::get_singleton()->texture_set_path(texture, get_path());
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
|
|
|
emit_changed();
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::_thread_done(const Ref<Image> &p_image) {
|
2021-03-28 13:32:17 +02:00
|
|
|
_set_texture_image(p_image);
|
2021-01-19 13:29:41 +01:00
|
|
|
noise_thread.wait_to_finish();
|
2018-08-25 00:25:06 +02:00
|
|
|
if (regen_queued) {
|
2021-01-19 13:29:41 +01:00
|
|
|
noise_thread.start(_thread_function, this);
|
2018-08-25 00:25:06 +02:00
|
|
|
regen_queued = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::_thread_function(void *p_ud) {
|
|
|
|
NoiseTexture2D *tex = static_cast<NoiseTexture2D *>(p_ud);
|
2023-12-18 15:46:56 +01:00
|
|
|
callable_mp(tex, &NoiseTexture2D::_thread_done).call_deferred(tex->_generate_texture());
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::_queue_update() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (update_queued) {
|
2018-08-25 00:25:06 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-08-25 00:25:06 +02:00
|
|
|
|
|
|
|
update_queued = true;
|
2023-12-18 15:46:56 +01:00
|
|
|
callable_mp(this, &NoiseTexture2D::_update_texture).call_deferred();
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
Ref<Image> NoiseTexture2D::_generate_texture() {
|
2020-04-06 13:22:31 +02:00
|
|
|
// Prevent memdelete due to unref() on other thread.
|
2022-03-20 14:53:45 +01:00
|
|
|
Ref<Noise> ref_noise = noise;
|
2020-04-06 13:22:31 +02:00
|
|
|
|
|
|
|
if (ref_noise.is_null()) {
|
|
|
|
return Ref<Image>();
|
|
|
|
}
|
2018-08-25 00:25:06 +02:00
|
|
|
|
2022-09-29 11:53:28 +02:00
|
|
|
Ref<Image> new_image;
|
2018-08-25 00:25:06 +02:00
|
|
|
|
|
|
|
if (seamless) {
|
2023-04-28 22:19:42 +02:00
|
|
|
new_image = ref_noise->get_seamless_image(size.x, size.y, invert, in_3d_space, seamless_blend_skirt, normalize);
|
2018-08-25 00:25:06 +02:00
|
|
|
} else {
|
2023-04-28 22:19:42 +02:00
|
|
|
new_image = ref_noise->get_image(size.x, size.y, invert, in_3d_space, normalize);
|
2022-04-19 19:48:25 +02:00
|
|
|
}
|
|
|
|
if (color_ramp.is_valid()) {
|
2022-09-29 11:53:28 +02:00
|
|
|
new_image = _modulate_with_gradient(new_image, color_ramp);
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
2020-12-23 10:34:26 +01:00
|
|
|
if (as_normal_map) {
|
2022-09-29 11:53:28 +02:00
|
|
|
new_image->bump_map_to_normal_map(bump_strength);
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
2022-04-19 19:48:25 +02:00
|
|
|
if (generate_mipmaps) {
|
2022-09-29 11:53:28 +02:00
|
|
|
new_image->generate_mipmaps();
|
2022-04-19 19:48:25 +02:00
|
|
|
}
|
2018-08-25 00:25:06 +02:00
|
|
|
|
2022-09-29 11:53:28 +02:00
|
|
|
return new_image;
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
Ref<Image> NoiseTexture2D::_modulate_with_gradient(Ref<Image> p_image, Ref<Gradient> p_gradient) {
|
2022-04-19 19:48:25 +02:00
|
|
|
int width = p_image->get_width();
|
|
|
|
int height = p_image->get_height();
|
|
|
|
|
2022-07-22 20:06:19 +02:00
|
|
|
Ref<Image> new_image = Image::create_empty(width, height, false, Image::FORMAT_RGBA8);
|
2022-04-19 19:48:25 +02:00
|
|
|
|
|
|
|
for (int row = 0; row < height; row++) {
|
|
|
|
for (int col = 0; col < width; col++) {
|
|
|
|
Color pixel_color = p_image->get_pixel(col, row);
|
2023-01-06 02:46:08 +01:00
|
|
|
Color ramp_color = p_gradient->get_color_at_offset(pixel_color.get_luminance());
|
2022-04-19 19:48:25 +02:00
|
|
|
new_image->set_pixel(col, row, ramp_color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_image;
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::_update_texture() {
|
2018-08-25 00:25:06 +02:00
|
|
|
bool use_thread = true;
|
|
|
|
if (first_time) {
|
|
|
|
use_thread = false;
|
|
|
|
first_time = false;
|
|
|
|
}
|
|
|
|
if (use_thread) {
|
2021-01-19 13:29:41 +01:00
|
|
|
if (!noise_thread.is_started()) {
|
|
|
|
noise_thread.start(_thread_function, this);
|
2018-08-25 00:25:06 +02:00
|
|
|
regen_queued = false;
|
|
|
|
} else {
|
|
|
|
regen_queued = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2022-09-29 11:53:28 +02:00
|
|
|
Ref<Image> new_image = _generate_texture();
|
|
|
|
_set_texture_image(new_image);
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
2020-01-07 11:35:34 +01:00
|
|
|
update_queued = false;
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::set_noise(Ref<Noise> p_noise) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_noise == noise) {
|
2018-08-25 00:25:06 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-08-25 00:25:06 +02:00
|
|
|
if (noise.is_valid()) {
|
2023-07-03 21:29:37 +02:00
|
|
|
noise->disconnect_changed(callable_mp(this, &NoiseTexture2D::_queue_update));
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
|
|
|
noise = p_noise;
|
|
|
|
if (noise.is_valid()) {
|
2023-07-03 21:29:37 +02:00
|
|
|
noise->connect_changed(callable_mp(this, &NoiseTexture2D::_queue_update));
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
|
|
|
_queue_update();
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
Ref<Noise> NoiseTexture2D::get_noise() {
|
2018-08-25 00:25:06 +02:00
|
|
|
return noise;
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::set_width(int p_width) {
|
2021-06-14 06:29:41 +02:00
|
|
|
ERR_FAIL_COND(p_width <= 0);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_width == size.x) {
|
2018-08-25 00:25:06 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-08-25 00:25:06 +02:00
|
|
|
size.x = p_width;
|
|
|
|
_queue_update();
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::set_height(int p_height) {
|
2021-06-14 06:29:41 +02:00
|
|
|
ERR_FAIL_COND(p_height <= 0);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_height == size.y) {
|
2018-08-25 00:25:06 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-08-25 00:25:06 +02:00
|
|
|
size.y = p_height;
|
|
|
|
_queue_update();
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::set_invert(bool p_invert) {
|
2022-03-20 14:53:45 +01:00
|
|
|
if (p_invert == invert) {
|
2021-05-18 06:51:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-03-20 14:53:45 +01:00
|
|
|
invert = p_invert;
|
2021-05-18 06:51:05 +02:00
|
|
|
_queue_update();
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
bool NoiseTexture2D::get_invert() const {
|
2022-03-20 14:53:45 +01:00
|
|
|
return invert;
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::set_in_3d_space(bool p_enable) {
|
2022-04-19 19:48:25 +02:00
|
|
|
if (p_enable == in_3d_space) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
in_3d_space = p_enable;
|
|
|
|
_queue_update();
|
|
|
|
}
|
2022-08-25 01:08:09 +02:00
|
|
|
bool NoiseTexture2D::is_in_3d_space() const {
|
2022-04-19 19:48:25 +02:00
|
|
|
return in_3d_space;
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::set_generate_mipmaps(bool p_enable) {
|
2022-04-19 19:48:25 +02:00
|
|
|
if (p_enable == generate_mipmaps) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
generate_mipmaps = p_enable;
|
|
|
|
_queue_update();
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
bool NoiseTexture2D::is_generating_mipmaps() const {
|
2022-04-19 19:48:25 +02:00
|
|
|
return generate_mipmaps;
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::set_seamless(bool p_seamless) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_seamless == seamless) {
|
2018-08-25 00:25:06 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-08-25 00:25:06 +02:00
|
|
|
seamless = p_seamless;
|
|
|
|
_queue_update();
|
2022-03-20 14:53:45 +01:00
|
|
|
notify_property_list_changed();
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
bool NoiseTexture2D::get_seamless() {
|
2018-08-25 00:25:06 +02:00
|
|
|
return seamless;
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::set_seamless_blend_skirt(real_t p_blend_skirt) {
|
2023-01-06 02:46:08 +01:00
|
|
|
ERR_FAIL_COND(p_blend_skirt < 0 || p_blend_skirt > 1);
|
2022-04-20 04:44:00 +02:00
|
|
|
|
2022-03-20 14:53:45 +01:00
|
|
|
if (p_blend_skirt == seamless_blend_skirt) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
seamless_blend_skirt = p_blend_skirt;
|
|
|
|
_queue_update();
|
|
|
|
}
|
2022-08-25 01:08:09 +02:00
|
|
|
real_t NoiseTexture2D::get_seamless_blend_skirt() {
|
2022-03-20 14:53:45 +01:00
|
|
|
return seamless_blend_skirt;
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::set_as_normal_map(bool p_as_normal_map) {
|
2020-12-23 10:34:26 +01:00
|
|
|
if (p_as_normal_map == as_normal_map) {
|
2018-08-25 00:25:06 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-12-23 10:34:26 +01:00
|
|
|
as_normal_map = p_as_normal_map;
|
2018-08-25 00:25:06 +02:00
|
|
|
_queue_update();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
bool NoiseTexture2D::is_normal_map() {
|
2020-12-23 10:34:26 +01:00
|
|
|
return as_normal_map;
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::set_bump_strength(float p_bump_strength) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_bump_strength == bump_strength) {
|
2019-03-03 19:50:55 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-03-03 19:50:55 +01:00
|
|
|
bump_strength = p_bump_strength;
|
2020-12-23 10:34:26 +01:00
|
|
|
if (as_normal_map) {
|
2019-03-03 19:50:55 +01:00
|
|
|
_queue_update();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-03-03 19:50:55 +01:00
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
float NoiseTexture2D::get_bump_strength() {
|
2019-03-03 19:50:55 +01:00
|
|
|
return bump_strength;
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
void NoiseTexture2D::set_color_ramp(const Ref<Gradient> &p_gradient) {
|
2022-04-19 19:48:25 +02:00
|
|
|
if (p_gradient == color_ramp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (color_ramp.is_valid()) {
|
2023-07-03 21:29:37 +02:00
|
|
|
color_ramp->disconnect_changed(callable_mp(this, &NoiseTexture2D::_queue_update));
|
2022-04-19 19:48:25 +02:00
|
|
|
}
|
|
|
|
color_ramp = p_gradient;
|
|
|
|
if (color_ramp.is_valid()) {
|
2023-07-03 21:29:37 +02:00
|
|
|
color_ramp->connect_changed(callable_mp(this, &NoiseTexture2D::_queue_update));
|
2022-04-19 19:48:25 +02:00
|
|
|
}
|
|
|
|
_queue_update();
|
|
|
|
}
|
|
|
|
|
2023-01-29 14:56:10 +01:00
|
|
|
void NoiseTexture2D::set_normalize(bool p_normalize) {
|
|
|
|
if (normalize == p_normalize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
normalize = p_normalize;
|
|
|
|
_queue_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NoiseTexture2D::is_normalized() const {
|
|
|
|
return normalize;
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
Ref<Gradient> NoiseTexture2D::get_color_ramp() const {
|
2022-04-19 19:48:25 +02:00
|
|
|
return color_ramp;
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
int NoiseTexture2D::get_width() const {
|
2018-08-25 00:25:06 +02:00
|
|
|
return size.x;
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
int NoiseTexture2D::get_height() const {
|
2018-08-25 00:25:06 +02:00
|
|
|
return size.y;
|
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
RID NoiseTexture2D::get_rid() const {
|
2019-06-11 20:43:37 +02:00
|
|
|
if (!texture.is_valid()) {
|
2020-03-27 19:21:27 +01:00
|
|
|
texture = RS::get_singleton()->texture_2d_placeholder_create();
|
2019-06-11 20:43:37 +02:00
|
|
|
}
|
2018-08-25 00:25:06 +02:00
|
|
|
|
2019-06-11 20:43:37 +02:00
|
|
|
return texture;
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|
|
|
|
|
2022-08-25 01:08:09 +02:00
|
|
|
Ref<Image> NoiseTexture2D::get_image() const {
|
2021-03-28 13:32:17 +02:00
|
|
|
return image;
|
2018-08-25 00:25:06 +02:00
|
|
|
}
|