Created
December 2, 2012 22:08
-
-
Save agrif/4191273 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 400 core | |
#extension GL_ARB_gup_shader_fp64 : enable | |
in vec2 txcoords; | |
uniform double zoom; | |
uniform dvec2 offset; | |
out vec4 fragColor; | |
uniform int iter; | |
uniform sampler1D palette; | |
void main() { | |
double c_real = double(txcoords.x) * zoom + offset.x; | |
double c_imag = double(txcoords.y) * zoom + offset.y; | |
double z_real_0 = c_real; | |
double z_imag_0 = c_imag; | |
double z_real_1 = z_real_0 * z_real_0 - z_imag_0 * z_imag_0 + c_real; | |
double z_imag_1 = 2.0 * z_real_0 * z_imag_0 + c_imag; | |
int i; | |
for (i = 0; i < iter; i += 2) { | |
double z_r_q = z_real_1 * z_real_1; | |
double z_i_q = z_imag_1 * z_imag_1; | |
if (z_i_q + z_r_q > 4.0) { | |
break; | |
} | |
z_real_0 = z_r_q - z_i_q + c_real; | |
z_imag_0 = 2.0 * z_real_1 * z_imag_1 + c_imag; | |
z_real_1 = z_real_0 * z_real_0 - z_imag_0 * z_imag_0 + c_real; | |
z_imag_1 = 2.0 * z_real_0 * z_imag_0 + c_imag; | |
} | |
if (z_imag_0 * z_imag_0 + z_real_0 * z_real_0 > 4.0) { | |
i -= 1; | |
z_real_1 = z_real_0; | |
z_imag_1 = z_imag_0; | |
} | |
if (i == iter) { | |
fragColor = vec4(0.0, 0.0, 0.0, 1.0); | |
} else { | |
float ni = float(i) + 1.0 - log(log(float(sqrt(z_imag_1 * z_imag_1 + z_real_1 * z_real_1)))) / log(2.0); | |
fragColor = texture(palette, abs(ni / float(iter))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment