OpenToonz - An open-source full-featured 2D animation creation software
C
Merge pull request #4209 from shun-iwasawa/g/conical_fractal_noise
Rodney88c0ebc520a9
diff --cc toonz/sources/stdfx/iwa_fractalnoisefx.cppindex 7a4764e38,63cdb7970..c694f241a--- a/toonz/sources/stdfx/iwa_fractalnoisefx.cpp+++ b/toonz/sources/stdfx/iwa_fractalnoisefx.cpp@@@ -171,81 -189,243 +189,243 @@@ void Iwa_FractalNoiseFx::doCompute(TTilint genCount = (int)std::ceil(param.complexity);- // accumulate base noise pattern for each generation- for (int gen = 0; gen < genCount; gen++) {- // affine transformation for the current generation- TAffine currentAff =+ if (!param.doConical) {+ TAffine parentOffsetAff = TTranslation(param.offsetTurbulence);+ // accumulate base noise pattern for each generation+ for (int gen = 0; gen < genCount; gen++) {+ // affine transformation for the current generation+ TAffine currentAff =(globalAff * parentOffsetAff * parentAff * genAff).inv();- // scale of the current pattern ( used for the Dynamic / Dynamic Twist- // offset )- double scale = sqrt(std::abs(currentAff.det()));-- // for each pixel- double *buf_p = work_buf;- for (int y = 0; y < outDim.ly; y++) {- for (int x = 0; x < outDim.lx; x++, buf_p++) {- // obtain sampling position- // For Dynamic and Dynamic Twist patterns, the position offsets using- // gradient / rotation of the parent pattern- TPointD samplePos =+ // scale of the current pattern ( used for the Dynamic / Dynamic Twist+ // offset )+ double scale = sqrt(std::abs(currentAff.det()));+ // for each pixel+ double* buf_p = work_buf;+ for (int y = 0; y < outDim.ly; y++) {+ for (int x = 0; x < outDim.lx; x++, buf_p++) {+ // obtain sampling position+ // For Dynamic and Dynamic Twist patterns, the position offsets using+ // gradient / rotation of the parent pattern+ TPointD samplePos =getSamplePos(x, y, outDim, out_buf, gen, scale, param);- // multiply affine transformation- samplePos = currentAff * samplePos;- // adjust position for the block pattern- if (param.noiseType == Block)- samplePos = TPointD(std::floor(samplePos.x) + 0.5,- std::floor(samplePos.y) + 0.5);- // calculate the base noise- if (param.cycleEvolution)- *buf_p = (pn.noise(samplePos.x, samplePos.y, evolution_zw.x,- evolution_zw.y) +- 1.0) *- 0.5;- else- *buf_p =- (pn.noise(samplePos.x, samplePos.y, evolution_z) + 1.0) * 0.5;-- // convert the noise- convert(buf_p, param);+ // multiply affine transformation+ samplePos = currentAff * samplePos;+ // adjust position for the block pattern+ if (param.noiseType == Block)+ samplePos = TPointD(std::floor(samplePos.x) + 0.5,+ std::floor(samplePos.y) + 0.5);+ // calculate the base noise+ if (param.cycleEvolution)+ *buf_p = (pn.noise(samplePos.x, samplePos.y, evolution_zw.x,+ evolution_zw.y) ++ 1.0) *+ 0.5;+ else+ *buf_p =+ (pn.noise(samplePos.x, samplePos.y, evolution_z) + 1.0) * 0.5;++ // convert the noise+ convert(buf_p, param);+ }}- }- // just copy the values for the first generation- if (gen == 0) {- memcpy(out_buf, work_buf, outDim.lx * outDim.ly * sizeof(double));- } else {- // intensity of the last generation will take the fraction part of- // complexity- double genIntensity = std::min(1.0, param.complexity - (double)gen);- // influence of the current generation- double influence =+ // just copy the values for the first generation+ if (gen == 0) {+ memcpy(out_buf, work_buf, outDim.lx * outDim.ly * sizeof(double));+ }+ else {+ // intensity of the last generation will take the fraction part of+ // complexity+ double genIntensity = std::min(1.0, param.complexity - (double)gen);+ // influence of the current generation+ double influence =genIntensity * std::pow(param.subInfluence, (double)gen);- // composite the base noise pattern- buf_p = work_buf;- double *out_p = out_buf;- for (int i = 0; i < outDim.lx * outDim.ly; i++, buf_p++, out_p++)- composite(out_p, buf_p, influence, param);+ // composite the base noise pattern+ buf_p = work_buf;+ double* out_p = out_buf;+ for (int i = 0; i < outDim.lx * outDim.ly; i++, buf_p++, out_p++)+ composite(out_p, buf_p, influence, param);+ }++ // update affine transformations (for the next generation loop)+ genAff *= subAff;+ // When the "Perspective Offset" option is ON, reduce the offset amount+ // according to the sub scale+ if (param.perspectiveOffset)+ parentOffsetAff = TScale(param.subScaling) *+ TRotation(-param.subRotation) * parentOffsetAff *+ TRotation(param.subRotation) *+ TScale(1 / param.subScaling);++ if (param.cycleEvolution)+ evolution_zw.x += evolutionOffsetStep;+ else+ evolution_z += evolutionOffsetStep;}+ }++ // conical noise+ else {+ // angle of slope of the cone+ double theta_n = param.conicalAngle * M_PI_180;+ // half of the vertical fov+ double phi_2 = param.cameraFov * 0.5 * M_PI_180;+ double z_scale = std::pow(10.0, param.zScale);+ double evolution_w = param.conicalEvolution;++ // pixel distance between camera and the screen+ double D = ri.m_cameraBox.getLy() * 0.5 / std::tan(phi_2);+ // the line on the slope : d = U * z + V+ double U = -1.0 / std::tan(theta_n);+ double V = ri.m_cameraBox.getLy() * 0.5;++ TPointD center = ri.m_affine * param.offsetTurbulence;++ // accumulate base noise pattern for each generation+ for (int gen = 0; gen < genCount; gen++) {+ // affine transformation for the current generation+ TAffine currentAff =+ (globalAff * parentAff * genAff).inv();+ // scale of the current pattern ( used for the Dynamic / Dynamic Twist+ // offset )+ double scale = sqrt(std::abs(currentAff.det()));++ // for each pixel+ double* buf_p = work_buf;+ for (int y = 0; y < outDim.ly; y++) {+ for (int x = 0; x < outDim.lx; x++, buf_p++) {++ double dx, dy, dz;+ if (theta_n == 0.0) {+ dx = x;+ dy = y;+ dz = 0.0;+ }+ else {+ // conical, without offset+ if (center == TPointD()) {+ TPointD p = TTranslation(tile.m_pos) * TPointD(x, y);+ // pixel distance from the screen center+ double d = tdistance(p, TPointD());+ // line of sight : d = S * z + T+ double S = d / D;+ double T = d;+ dz = (V - T) / (S - U);+ double dp = S * dz + T;+ if (d != 0.0) {+ p.x *= dp / d;+ p.y *= dp / d;+ }+ p += center * (dp / V);+ p = TTranslation(tile.m_pos).inv() * p;+ dx = p.x;+ dy = p.y;+ dz /= z_scale;+ }+ // conical, with offset+ else {+ // compute the intersecting point between the "noise cone" and the line of sight+ TPointD _p = TTranslation(tile.m_pos) * TPointD(x, y);+ QVector3D p(_p.x, _p.y, 0.0);+ QVector3D eye_O(center.x, center.y, -D);+ QVector3D eye_d = (p - eye_O).normalized();+ QVector3D cone_C(0.0, 0.0, V * std::tan(theta_n));+ QVector3D cone_a(0, 0, -1);+ double cos_ConeT = std::sin(theta_n);++ float d_a = QVector3D::dotProduct(eye_d, cone_a);+ float Ca_Oa = QVector3D::dotProduct(cone_C, cone_a) - QVector3D::dotProduct(eye_O, cone_a);++ // A * t^2 + B * t + C = 0+ float A = d_a * d_a - eye_d.lengthSquared() * cos_ConeT;+ float B = 2.0 * (QVector3D::dotProduct(eye_d, cone_C) - QVector3D::dotProduct(eye_d, eye_O)) * cos_ConeT * cos_ConeT+ - 2.0 * Ca_Oa * d_a;+ float C = Ca_Oa * Ca_Oa+ - cos_ConeT * cos_ConeT * (cone_C.lengthSquared() - 2.0 * QVector3D::dotProduct(eye_O, cone_C) + eye_O.lengthSquared());++ // obtain t+ double t1 = (-B + std::sqrt(B * B - 4.0 * A * C)) / (2.0 * A);+ double t2 = (-B - std::sqrt(B * B - 4.0 * A * C)) / (2.0 * A);+ if (t1 < 0) t1 = t2;+ else if (t2 < 0) t2 = t1;+ double t = std::min(t1, t2);++ // intersecting point+ QVector3D sampleP = eye_O + eye_d * t;+ _p.x = sampleP.x();+ _p.y = sampleP.y();+ _p = TTranslation(tile.m_pos).inv() * _p;+ dx = _p.x;+ dy = _p.y;+ dz = sampleP.z() / z_scale;+ }+ if (param.cycleEvolution) {+ double cycle_theta = 2.0 * M_PI * (param.evolution + param.conicalEvolution + dz) / param.cycleEvolutionRange;+ double cycle_d = param.cycleEvolutionRange / (2.0 * M_PI);+ evolution_zw.x = cycle_d * cos(cycle_theta);+ evolution_zw.y = cycle_d * sin(cycle_theta);+ }+ }+ // obtain sampling position+ // For Dynamic and Dynamic Twist patterns, the position offsets using+ // gradient / rotation of the parent pattern+ TPointD samplePos =+ getSamplePos(dx, dy, outDim, out_buf, gen, scale, param);+ // multiply affine transformation+ samplePos = currentAff * samplePos;+ // adjust position for the block pattern+ if (param.noiseType == Block)+ samplePos = TPointD(std::floor(samplePos.x) + 0.5,+ std::floor(samplePos.y) + 0.5);+ // calculate the base noise+ if (param.cycleEvolution)+ *buf_p = (pn.noise(samplePos.x, samplePos.y, evolution_zw.x,+ evolution_zw.y) ++ 1.0) *+ 0.5;+ else+ *buf_p =+ (pn.noise(samplePos.x, samplePos.y, evolution_z, evolution_w + dz) + 1.0) * 0.5;++ // convert the noise+ convert(buf_p, param);+ }+ }- // update affine transformations (for the next generation loop)- genAff *= subAff;- // When the "Perspective Offset" option is ON, reduce the offset amount- // according to the sub scale- if (param.perspectiveOffset)- parentOffsetAff = TScale(param.subScaling) *- TRotation(-param.subRotation) * parentOffsetAff *- TRotation(param.subRotation) *- TScale(1 / param.subScaling);-- if (param.cycleEvolution)- evolution_zw.x += evolutionOffsetStep;- else- evolution_z += evolutionOffsetStep;+ // just copy the values for the first generation+ if (gen == 0) {+ memcpy(out_buf, work_buf, outDim.lx * outDim.ly * sizeof(double));+ }+ else {+ // intensity of the last generation will take the fraction part of+ // complexity+ double genIntensity = std::min(1.0, param.complexity - (double)gen);+ // influence of the current generation+ double influence =+ genIntensity * std::pow(param.subInfluence, (double)gen);+ // composite the base noise pattern+ buf_p = work_buf;+ double* out_p = out_buf;+ for (int i = 0; i < outDim.lx * outDim.ly; i++, buf_p++, out_p++)+ composite(out_p, buf_p, influence, param);+ }++ // update affine transformations (for the next generation loop)+ genAff *= subAff;++ if (param.cycleEvolution)+ evolution_zw.x += evolutionOffsetStep;+ else {+ evolution_z += evolutionOffsetStep;+ evolution_w += evolutionOffsetStepW;+ }+ }}+work_buf_ras->unlock();- // finalize pattern (coverting the color space)+ // finalize pattern (converting the color space)if (param.fractalType == TurbulentSmooth ||param.fractalType == TurbulentBasic ||param.fractalType == TurbulentSharp) {diff --cc toonz/sources/stdfx/iwa_fractalnoisefx.hindex 80a173cd3,652fa18ed..e58d61b47--- a/toonz/sources/stdfx/iwa_fractalnoisefx.h+++ b/toonz/sources/stdfx/iwa_fractalnoisefx.h@@@ -50,62 -57,69 +57,69 @@@ class Iwa_FractalNoiseFx final : publi};protected:- // Fractal Type �t���N�^���̎��+ // Fractal Type フラクタルの種類TIntEnumParamP m_fractalType;- // Noise Type �m�C�Y�̎��+ // Noise Type ノイズの種類TIntEnumParamP m_noiseType;- // Invert ���]+ // Invert 反転TBoolParamP m_invert;- /// Contrast �R���g���X�g- /// Brightness ���邳- /// Overflow �I�[�o�[�t���[+ /// Contrast コントラスト+ /// Brightness 明るさ+ /// Overflow オーバーフロー- //- - - Transform �g�����X�t�H�[�� - - -- // Rotation ��]+ //- - - Transform トランスフォーム - - -+ // Rotation 回転TDoubleParamP m_rotation;- // Uniform Scaling�@�c������Œ�+ // Uniform Scaling 縦横比を固定TBoolParamP m_uniformScaling;- // Scale �X�P�[��+ // Scale スケールTDoubleParamP m_scale;- // Scale Width �X�P�[���̕�+ // Scale Width スケールの幅TDoubleParamP m_scaleW;- // Scale Height �X�P�[���̍���+ // Scale Height スケールの高さTDoubleParamP m_scaleH;- // Offset Turbulence ���C���̃I�t�Z�b�g+ // Offset Turbulence 乱気流のオフセットTPointParamP m_offsetTurbulence;- // Perspective Offset ���߃I�t�Z�b�g+ // Perspective Offset 遠近オフセットTBoolParamP m_perspectiveOffset;- // Complexity ���G�x+ // Complexity 複雑度TDoubleParamP m_complexity;- //- - - Sub Settings �T�u�ݒ� - - -- // Sub Influence �T�u�e���i���j+ //- - - Sub Settings サブ設定 - - -+ // Sub Influence サブ影響(%)TDoubleParamP m_subInfluence;- // Sub Scaling�@�T�u�X�P�[��+ // Sub Scaling サブスケールTDoubleParamP m_subScaling;- // Sub Rotation �T�u��]+ // Sub Rotation サブ回転TDoubleParamP m_subRotation;- // Sub Offset �T�u�̃I�t�Z�b�g+ // Sub Offset サブのオフセットTPointParamP m_subOffset;- // Center Subscale �T�u�X�P�[���𒆐S+ // Center Subscale サブスケールを中心/// TBoolParamP m_centerSubscale;- // Evolution �W�J+ // Evolution 展開TDoubleParamP m_evolution;- //- - - Evolution Options �W�J�̃I�v�V���� - - -- // Cycle Evolution �T�C�N���W�J+ //- - - Evolution Options 展開のオプション - - -+ // Cycle Evolution サイクル展開TBoolParamP m_cycleEvolution;- // Cycle (in Evolution) �T�C�N���i�����j+ // Cycle (in Evolution) サイクル(周期)TDoubleParamP m_cycleEvolutionRange;- /// Random Seed �����_���V�[�h- /// Opacity �s�����x- /// Blending Mode �`�惂�[�h+ /// Random Seed ランダムシード+ /// Opacity 不透明度+ /// Blending Mode 描画モード- // �_�C�i�~�b�N�̓x����+ // ダイナミックの度合いTDoubleParamP m_dynamicIntensity;+ //- - - Conical Noise - - -+ TBoolParamP m_doConical;+ TDoubleParamP m_conicalEvolution;+ TDoubleParamP m_conicalAngle;+ TDoubleParamP m_cameraFov;+ TDoubleParamP m_zScale;+// - - - additional parameters - - -TBoolParamP m_alphaRendering;