From b7a1dad6bb9da01121734a5c03a376f3b8c55a6a Mon Sep 17 00:00:00 2001 From: Eduard Mandy Date: Sun, 1 Dec 2024 19:23:45 +0100 Subject: [PATCH] #5 31.4 Basic Noise Textures Add FBmTexture. --- CMakeLists.txt | 2 ++ src/Textures/FBmTexture.cpp | 1 + src/Textures/FBmTexture.h | 1 + 3 files changed, 4 insertions(+) create mode 100644 src/Textures/FBmTexture.cpp create mode 100644 src/Textures/FBmTexture.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f62aa93..f822680 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,6 +212,8 @@ set (SOURCE_TEXTURES src/Textures/CylinderChecker.h src/Textures/DiskChecker.h src/Textures/DiskChecker.cpp + src/Textures/FBmTexture.cpp + src/Textures/FBmTexture.h src/Textures/ImageTexture.cpp src/Textures/ImageTexture.h src/Textures/PlaneChecker.cpp diff --git a/src/Textures/FBmTexture.cpp b/src/Textures/FBmTexture.cpp new file mode 100644 index 0000000..619a4e1 --- /dev/null +++ b/src/Textures/FBmTexture.cpp @@ -0,0 +1 @@ +// Copyright (C) Kevin Suffern 2000-2007. // This C++ code is for non-commercial purposes only. // This C++ code is licensed under the GNU General Public License Version 2. // See the file COPYING.txt for the full license. // Copyright notice for changes since the originally published version: // Copyright (C) Eduárd Mándy 2019-2021 // Though this C++ code was change in a large measure it still has the original copyright notice. // This C++ code is for non-commercial purposes only. // This C++ code is licensed under the GNU General Public License Version 2. // See the file COPYING.txt for the full license. #include "FBmTexture.h" #include "../Noises/LatticeNoise.h" FBmTexture::FBmTexture(LatticeNoise *ln_ptr) { noise_ptr = ln_ptr; } RGBColor FBmTexture::get_color(const ShadeRec& sr) const { float value = noise_ptr->value_fbm(sr.local_hit_point); // in the range (0, 1) value = min_value + (max_value - min_value) * value; // in the range (min_value, max_value) if (value < 0.0 || value > 1.0) { return RGBColor(1, 0, 0); } else { return (value * color); } } \ No newline at end of file diff --git a/src/Textures/FBmTexture.h b/src/Textures/FBmTexture.h new file mode 100644 index 0000000..6b4b6d3 --- /dev/null +++ b/src/Textures/FBmTexture.h @@ -0,0 +1 @@ +// Copyright (C) Kevin Suffern 2000-2007. // This C++ code is for non-commercial purposes only. // This C++ code is licensed under the GNU General Public License Version 2. // See the file COPYING.txt for the full license. // Copyright notice for changes since the originally published version: // Copyright (C) Eduárd Mándy 2019-2021 // Though this C++ code was change in a large measure it still has the original copyright notice. // This C++ code is for non-commercial purposes only. // This C++ code is licensed under the GNU General Public License Version 2. // See the file COPYING.txt for the full license. #include "Texture.h" #include "../Utilities/RGBColor.h" class ShadeRec; class LatticeNoise; class FBmTexture: public Texture { public: FBmTexture() = default; FBmTexture(LatticeNoise *ln_ptr); void set_color(const float r, const float g, const float b); void set_min_value(const float min); void set_max_value(const float max); virtual RGBColor get_color(const ShadeRec& sr) const; private: LatticeNoise* noise_ptr = nullptr; RGBColor color = RGBColor::black; float min_value = 0.0f; float max_value = 1.0f; }; inline void FBmTexture::set_color(const float r, const float g, const float b) { color.r = r; color.g = g; color.b = b; } inline void FBmTexture::set_min_value(const float min) { min_value = min; } inline void FBmTexture::set_max_value(const float max) { max_value = max; } \ No newline at end of file