diff --git a/Fragment.glsl b/Fragment.glsl index 980cd28..bebfb85 100644 --- a/Fragment.glsl +++ b/Fragment.glsl @@ -3,6 +3,7 @@ out vec4 pixColor; uniform int maxIterationsCount; uniform float hueAdd; +uniform bool normalize; in vec2 complexPos; @@ -53,9 +54,11 @@ float mandelbrot(in vec2 c){ } if (steps == maxIterationsCount) return 0.; - float log_zn = log(z.x * z.x + z.y * z.y) / 2; - float nu = log(log_zn / log(2.)) / log(2.); - steps += 1 - nu; + if (normalize){ + float log_zn = log(z.x * z.x + z.y * z.y) / 2; + float nu = log(log_zn / log(2.)) / log(2.); + steps += 1 - nu; + } float t = steps / maxIterationsCount; return sqrt(t); } diff --git a/headers/Mandelbrot.h b/headers/Mandelbrot.h index b96ca38..31832d2 100644 --- a/headers/Mandelbrot.h +++ b/headers/Mandelbrot.h @@ -17,12 +17,14 @@ public: bool initShader(); public slots: void toggleAnimation(); + void toggleNormalize(); private: int maxIterations = 0; float hueAdd = 0; QVector2D origin {-2, -1}; QVector2D size {2, 2}; float zoomModifier = 1.05; + bool normalize = true; bool animating = true; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index f7fd882..d0ee066 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -53,6 +53,12 @@ void MainWindow::buildUI() { &outputWidget.getMandelbrot(), &Mandelbrot::toggleAnimation); + auto normButton = new QPushButton("Toggle normalization"); + connect(normButton, + &QPushButton::clicked, + &outputWidget.getMandelbrot(), + &Mandelbrot::toggleNormalize); + auto controls = new QGridLayout; controls->addWidget(maxIterationsCaption, 1, 1); controls->addWidget(maxIterationsLabel, 1, 2); @@ -60,6 +66,7 @@ void MainWindow::buildUI() { controls->addWidget(saveInfo, 2, 1, 1, 2); controls->addWidget(saveButton, 2, 3, 1, 1); controls->addWidget(animButton, 3, 1, 1, 3); + controls->addWidget(normButton, 4, 1, 1, 3); auto lyt = new QVBoxLayout(this); lyt->addWidget(&outputWidget); diff --git a/src/Mandelbrot.cpp b/src/Mandelbrot.cpp index 8b5418a..b212a98 100644 --- a/src/Mandelbrot.cpp +++ b/src/Mandelbrot.cpp @@ -41,6 +41,7 @@ void Mandelbrot::setShaderValues() { shader.setUniformValue("size", size); shader.setUniformValue("maxIterationsCount", maxIterations); shader.setUniformValue("hueAdd", hueAdd); + shader.setUniformValue("normalize", normalize); } void Mandelbrot::zoomRelative(int direction, QVector2D posRelative) { @@ -65,6 +66,10 @@ void Mandelbrot::resizeRelative(QVector2D relative) { size *= relative; } +void Mandelbrot::toggleNormalize() { + normalize = !normalize; +} +