added option for normalization

master
Benjamin Kraft 3 years ago
parent b41ce0b649
commit 788171e862
  1. 9
      Fragment.glsl
  2. 2
      headers/Mandelbrot.h
  3. 7
      src/MainWindow.cpp
  4. 5
      src/Mandelbrot.cpp

@ -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);
}

@ -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;

@ -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);

@ -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;
}

Loading…
Cancel
Save