From 83d15fe102d14181deb2dac49defb109f4386790 Mon Sep 17 00:00:00 2001 From: shun-iwasawa Date: Mon, 13 Sep 2021 16:50:24 +0900 Subject: [PATCH] fix pn clouds ino fx --- toonz/sources/stdfx/igs_perlin_noise.cpp | 38 ++++++++++++------------ toonz/sources/stdfx/igs_perlin_noise.h | 6 ++-- toonz/sources/stdfx/ino_pn_clouds.cpp | 15 +++++----- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/toonz/sources/stdfx/igs_perlin_noise.cpp b/toonz/sources/stdfx/igs_perlin_noise.cpp index 4db0b6ee..772893a9 100644 --- a/toonz/sources/stdfx/igs_perlin_noise.cpp +++ b/toonz/sources/stdfx/igs_perlin_noise.cpp @@ -9,7 +9,7 @@ double perlin_noise_3d_(const double x, const double y, const double z, , const double persistence // Not 0 // 1/4 or 1/2 or 1/sqrt(3) or 1/sqrt(2) or 1 or ... - ) { +) { double total = 0; Noise1234 pn; for (int ii = octaves_start; ii <= octaves_end; ++ii) { @@ -25,14 +25,14 @@ double perlin_noise_minmax_(const int octaves_start // 0<= , const double persistence // Not 0 // 1/4 or 1/2 or 1/sqrt(3) or 1/sqrt(2) or 1 or ... - ) { +) { double total = 0; for (int ii = octaves_start; ii <= octaves_end; ++ii) { total += pow(persistence, ii); } return total; } -} +} // namespace //-------------------------------------------------------------------- #include // std::domain_error(-) #include // std::numeric_limits @@ -40,10 +40,8 @@ double perlin_noise_minmax_(const int octaves_start // 0<= #include "igs_perlin_noise.h" namespace { template -void change_(T *image_array, const int height // pixel - , - const int width // pixel - , +void change_(T *image_array, const int height, const int width, + const int wrap, // pixel const int channels, const bool alpha_rendering_sw, const double a11 // geometry of 2D affine transformation , @@ -54,7 +52,7 @@ void change_(T *image_array, const int height // pixel const int octaves_end // 0<= , const double persistence // Not 0 - ) { +) { const int max_div = std::numeric_limits::max(); const int max_div_2 = max_div / 2; // 255 / 2 --> 127 @@ -80,8 +78,10 @@ void change_(T *image_array, const int height // pixel perlin_noise_minmax_(octaves_start, octaves_end, persistence); using namespace igs::image::rgba; - T *image_crnt = image_array; + T *image_crnt; + T *image_scanline = image_array; for (int yy = 0; yy < height; ++yy) { + image_crnt = image_scanline; for (int xx = 0; xx < width; ++xx, image_crnt += channels) { const T val = static_cast( perlin_noise_3d_(xx * a11 + yy * a12 + a13, xx * a21 + yy * a22 + a23, @@ -96,15 +96,14 @@ void change_(T *image_array, const int height // pixel } } } + image_scanline += channels * wrap; } } -} +} // namespace // #include "igs_geometry2d.h" void igs::perlin_noise::change( - unsigned char *image_array, const int height // pixel - , - const int width // pixel - , + unsigned char *image_array, const int height, const int width, + const int wrap, // pixel const int channels, const int bits, const bool alpha_rendering_sw, const double a11 // geometry of 2D affine transformation , @@ -114,17 +113,18 @@ void igs::perlin_noise::change( const int octaves_end // 0... , const double persistence // not 0 - ) { +) { // igs::geometry2d::affine af(a11 , a12 , a13 , a21 , a22 , a23); // igs::geometry2d::translate(); if (std::numeric_limits::digits == bits) { - change_(image_array, height, width, channels, alpha_rendering_sw, a11, a12, - a13, a21, a22, a23, zz, octaves_start, octaves_end, persistence); + change_(image_array, height, width, wrap, channels, alpha_rendering_sw, a11, + a12, a13, a21, a22, a23, zz, octaves_start, octaves_end, + persistence); } else if (std::numeric_limits::digits == bits) { change_(reinterpret_cast(image_array), height, width, - channels, alpha_rendering_sw, a11, a12, a13, a21, a22, a23, zz, - octaves_start, octaves_end, persistence); + wrap, channels, alpha_rendering_sw, a11, a12, a13, a21, a22, a23, + zz, octaves_start, octaves_end, persistence); } else { throw std::domain_error("Bad bits,Not uchar/ushort"); } diff --git a/toonz/sources/stdfx/igs_perlin_noise.h b/toonz/sources/stdfx/igs_perlin_noise.h index 974c79ae..032f6ab2 100644 --- a/toonz/sources/stdfx/igs_perlin_noise.h +++ b/toonz/sources/stdfx/igs_perlin_noise.h @@ -12,7 +12,7 @@ namespace perlin_noise { IGS_PERLIN_NOISE_EXPORT void change( unsigned char *image_array, const int height // pixel , - const int width // pixel + const int width, const int wrap // pixel , const int channels, const int bits, const bool alpha_rendering_sw = true @@ -28,8 +28,8 @@ IGS_PERLIN_NOISE_EXPORT void change( const int octaves_end = 9 // 0... , const double persistence = 1. / 1.7320508 // not 0 - ); -} +); } +} // namespace igs #endif /* !igs_perlin_noise_h */ diff --git a/toonz/sources/stdfx/ino_pn_clouds.cpp b/toonz/sources/stdfx/ino_pn_clouds.cpp index 61f12a70..b67b447a 100644 --- a/toonz/sources/stdfx/ino_pn_clouds.cpp +++ b/toonz/sources/stdfx/ino_pn_clouds.cpp @@ -67,15 +67,14 @@ void fx_(TRasterP in_ras, const double zz, const int octaves, const double persistance, const bool alpha_rendering_sw, const double a11, const double a12, const double a13, const double a21, const double a22, const double a23) { - igs::perlin_noise::change( - in_ras->getRawData() // BGRA - , - in_ras->getLy(), in_ras->getLx() // =in_ras->getWrap()??? - , - ino::channels(), ino::bits(in_ras), alpha_rendering_sw, a11, a12, a13, - a21, a22, a23, zz, 0, octaves, persistance); -} + igs::perlin_noise::change(in_ras->getRawData() // BGRA + , + in_ras->getLy(), in_ras->getLx(), in_ras->getWrap(), + ino::channels(), ino::bits(in_ras), + alpha_rendering_sw, a11, a12, a13, a21, a22, a23, + zz, 0, octaves, persistance); } +} // namespace //------------------------------------------------------------ void ino_pn_clouds::doCompute(TTile &tile, double frame, const TRenderSettings &rend_sets) {