# HG changeset patch # User John Tsiombikas # Date 1511700574 -7200 # Node ID f440ecffc45add55759cfa180562e7151be12dac # Parent 03e8b9a5031d210f88c3884f6483dfcf90b47b13 trying to draw the orbit in the shader diff -r 03e8b9a5031d -r f440ecffc45a mbrot.glsl --- a/mbrot.glsl Mon Nov 20 03:53:02 2017 +0200 +++ b/mbrot.glsl Sun Nov 26 14:49:34 2017 +0200 @@ -1,5 +1,5 @@ // vi:ft=glsl: -#define ITER 96 +#define ITER 128 uniform float view_scale; uniform vec2 view_center; @@ -7,6 +7,7 @@ float mbrot_dist_point(in vec2 c, in vec2 p) { + vec2 pixpos = c; vec2 z = c; float mindist_sq = 8192.0; @@ -15,18 +16,59 @@ float y = (z.x * z.y + z.x * z.y) + c.y; z = vec2(x, y); - vec2 dir = z - seed; + vec2 dir = z - p; mindist_sq = min(mindist_sq, dot(dir, dir)); } - return sqrt(mindist_sq); + return mindist_sq; +} + +float line_dist_sq(in vec2 a, in vec2 b, in vec2 p) +{ + vec2 dir = b - a; + vec2 pvec = p - a; + float t = dot(dir, pvec); + + if(t < 0.0) return dot(pvec, pvec); + if(t > 1.0) return dot(p - b, p - b); + + vec2 ppt = a + dir * t; + vec2 lpvec = p - ppt; + return dot(lpvec, lpvec); +} + +float mbrot_orbit_dist(in vec2 c, in vec2 p) +{ + vec2 pixpos = c; + vec2 z = c; + float mindist_sq = 8192.0; + + for(int i=0; i #include "sdr.h" +enum { + SDR_LINE_DIST_BIT = 1, + SDR_PLOT_ORBIT_BIT = 2 +}; +const char *sdrdef[] = { + "#define LINE_DIST\n", + "#define PLOT_ORBIT\n" +}; +#define NUM_SDR_BITS (sizeof sdrdef / sizeof *sdrdef) +#define NUM_SHADERS (1 << NUM_SDR_BITS) + int init(void); void cleanup(void); void disp(void); @@ -21,11 +32,12 @@ static int win_width = 1280, win_height = 800; static float win_aspect; static int mouse_x = 640, mouse_y = 400; -static unsigned int prog_mbrot; +static unsigned int prog_mbrot[NUM_SHADERS]; static float view_center[2] = {0.7, 0.0}; static float view_scale = 1.2; +static unsigned int sdrflags; int main(int argc, char **argv) { @@ -53,17 +65,57 @@ int init(void) { + int i, j; + unsigned int vs = 0, ps[NUM_SHADERS] = {0}; + glewInit(); - if(!(prog_mbrot = create_program_load("vertex.glsl", "mbrot.glsl"))) { + if(!(vs = load_vertex_shader("vertex.glsl"))) { return -1; } + + for(i=0; i