/**************************************************************************/1/* noise_texture_2d.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "noise.h"3334#include "core/object/ref_counted.h"35#include "scene/resources/texture.h"3637class NoiseTexture2D : public Texture2D {38GDCLASS(NoiseTexture2D, Texture2D);3940private:41Ref<Image> image;4243Thread noise_thread;4445bool first_time = true;46bool update_queued = false;47bool regen_queued = false;4849mutable RID texture;50uint32_t flags = 0;5152Size2i size = Size2i(512, 512);53bool invert = false;54bool in_3d_space = false;55bool generate_mipmaps = true;56bool seamless = false;57real_t seamless_blend_skirt = 0.1;58bool as_normal_map = false;59float bump_strength = 8.0;60bool normalize = true;6162Ref<Gradient> color_ramp;63Ref<Noise> noise;6465void _thread_done(const Ref<Image> &p_image);66static void _thread_function(void *p_ud);6768void _queue_update();69Ref<Image> _generate_texture();70void _update_texture();71void _set_texture_image(const Ref<Image> &p_image);7273Ref<Image> _modulate_with_gradient(Ref<Image> p_image, Ref<Gradient> p_gradient);7475protected:76static void _bind_methods();77void _validate_property(PropertyInfo &p_property) const;7879public:80void set_noise(Ref<Noise> p_noise);81Ref<Noise> get_noise();8283void set_width(int p_width);84void set_height(int p_height);8586void set_invert(bool p_invert);87bool get_invert() const;8889void set_in_3d_space(bool p_enable);90bool is_in_3d_space() const;9192void set_generate_mipmaps(bool p_enable);93bool is_generating_mipmaps() const;9495void set_seamless(bool p_seamless);96bool get_seamless();9798void set_seamless_blend_skirt(real_t p_blend_skirt);99real_t get_seamless_blend_skirt();100101void set_as_normal_map(bool p_as_normal_map);102bool is_normal_map();103104void set_bump_strength(float p_bump_strength);105float get_bump_strength();106107void set_normalize(bool p_normalize);108bool is_normalized() const;109110void set_color_ramp(const Ref<Gradient> &p_gradient);111Ref<Gradient> get_color_ramp() const;112113int get_width() const override;114int get_height() const override;115116virtual RID get_rid() const override;117virtual bool has_alpha() const override { return false; }118119virtual Ref<Image> get_image() const override;120121NoiseTexture2D();122virtual ~NoiseTexture2D();123};124125126