diff --git a/README.md b/README.md index 7f0d0dd..91b1cea 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,6 @@ A program and codebase for rapid iteration of GLSL programs. * Hot Reload * This Dick -* Public Domain \ No newline at end of file +* Public Domain + +![](mandelbrot.png) \ No newline at end of file diff --git a/main.cpp b/main.cpp index 7ca8f1b..2ab6e53 100644 --- a/main.cpp +++ b/main.cpp @@ -49,8 +49,10 @@ public: Shader::OnCompilationErrorMessage += [this](std::string type, std::string infoLog) { auto log_lines = string_expand(infoLog, '\n'); console->Log(type, Colors::Red); + std::cerr << type << std::endl; for (auto line: log_lines) { console->Log(line, Colors::Red); + std::cerr << line << std::endl; } }; @@ -171,7 +173,7 @@ public: console->Log(std::format("OpenGL Vendor: {}", GetGLVendor())); console->Log(std::format("OpenGL Version: {}", GetGLVersion())); console->Log(std::format("GLSL Version: {}", GetGLSLVersion())); - auto ext_list = GetGLExtensionList(); + /*auto ext_list = GetGLExtensionList(); // TODO: output 3 at a time. console->Log("GL-Extensions: "); @@ -187,7 +189,7 @@ public: console->Log(formatted_output); formatted_output = ""; } - } + }*/ return true; } diff --git a/mandelbrot.png b/mandelbrot.png new file mode 100644 index 0000000..26ec4a0 Binary files /dev/null and b/mandelbrot.png differ diff --git a/shaders/fastmandelbrot.frag.glsl b/shaders/fastmandelbrot.frag.glsl index 62da3df..449ad8e 100644 --- a/shaders/fastmandelbrot.frag.glsl +++ b/shaders/fastmandelbrot.frag.glsl @@ -4,20 +4,71 @@ precision mediump float; #endif +#define PI 3.14159265359 + uniform vec2 u_resolution; uniform vec2 u_mouse; uniform float u_time; -void main() -{ +uniform vec2 u_translation; +uniform float u_zoom; - vec2 I = gl_FragCoord.xy; +#define N 48. +#define B 4. - //vec2 uv = gl_FragCoord.xy / u_resolution.xy; - //vec3 col = 0.5 + 0.5*cos(u_time+uv.xyx+vec3(0,2,4)); - //gl_FragColor = vec4(col, 1.0); +vec3 pal(in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d) { + return a + b*cos(6.28318*(c*t+d)); +} - vec2 c = ( 2.*I - R) / R.y, z = 0./R; +float iterate(vec2 p) { + vec2 z = vec2(0), c = p; + float i; + for (i=0.; i < N; i++ ) { + z = mat2(z, -z.y, z.x) * z + c; + if (dot(z, z) > B*B) break; + } -} \ No newline at end of file + //return i; + // Compute the iteration smoothly, instead of in integers. + + if (p.y < 0.f) return i; + return i - log(log(dot(z, z)) / log(B)) / log(2.);; +} + +void main() { + vec2 R = u_resolution.xy; + vec2 uv = 1.2 * (2. * gl_FragCoord.xy - R - 1.) / R.y - vec2(.4, 0.); + //vec2 z = vec2(0), c = uv; + //float i; + + //for (i = 0.; i < N; i++) { + // z = mat2(z, -z.y, z.x) * z + c; + // if (dot(z, z) > B*B) break; + //} + + float n = iterate(uv) / N; + + vec3 col = pal(fract(n + 0.5), vec3(.5), vec3(.5), vec3(1), vec3(.0, .1, .2)); + + //if (n == 1.) {n = 0; } + gl_FragColor = vec4(n == 1. ? vec3(0) : col, 1.); + + //vec2 st = gl_FragCoord.xy/u_resolution.xy; + //vec3 color = vec3(0.0); + + //vec3 pct = vec3(st.x); + + // pct.r = smoothstep(0.0,1.0, st.x); + // pct.g = sin(st.x*PI); + // pct.b = pow(st.x,0.5); + + //color = mix(colorA, colorB, pct); + + // Plot transition lines for each channel + // color = mix(color,vec3(1.0,0.0,0.0),plot(st,pct.r)); + // color = mix(color,vec3(0.0,1.0,0.0),plot(st,pct.g)); + // color = mix(color,vec3(0.0,0.0,1.0),plot(st,pct.b)); + + // gl_FragColor = vec4(color,1.0); +} diff --git a/shaders/random.glsl b/shaders/random.glsl new file mode 100644 index 0000000..3b84a4d --- /dev/null +++ b/shaders/random.glsl @@ -0,0 +1,11 @@ +/// Generates and returns a pseudorandom number. (sic) +float random(in vec2 st) { + return fract(sin(dot(st.xy, vec2(12.989, 78.233))) * 43758.543); +} + +float rseed = 0.; + +vec2 random2() { + vec2 seed = vec2(rseed++, rseed++); + return vec2(random(seed + 0.342), random(seed + 0.756)); +} \ No newline at end of file