#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Aug 5 15:35:04 2019 @author: pavel """ #shaders for drawing supernodes vert_s = """ #version 120 // Uniforms // ------------------------------------ uniform mat4 u_model; uniform mat4 u_view; uniform mat4 u_projection; uniform vec3 u_graph_size; uniform bool u_picking; // Attributes // ------------------------------------ attribute vec3 a_position; attribute vec4 a_bg_color; attribute vec4 a_cluster_color; attribute vec2 a_value; attribute float a_arc_length; attribute vec4 a_outer_arc_length; attribute vec4 a_unique_id; // Varyings // ------------------------------------ varying vec4 v_bg_color; varying vec4 v_cluster_color; varying vec2 v_value; varying float v_zoom_level; varying float v_arc_length; varying vec4 v_outer_arc_length; varying vec4 v_unique_id; void main (void) { v_value = a_value; v_bg_color = a_bg_color; v_cluster_color = a_cluster_color; gl_Position = u_projection * u_view * u_model * vec4(a_position, 1.0); v_zoom_level = u_view[0][0]; v_arc_length = a_arc_length; v_outer_arc_length = a_outer_arc_length; v_unique_id = a_unique_id; } """ frag_s = """ #version 120 const float pi = 3.1415926535897932384626433832795; // Varyings // ------------------------------------ varying vec4 v_bg_color; varying vec2 v_value; varying float v_zoom_level; varying vec4 v_cluster_color; varying float v_arc_length; varying vec4 v_outer_arc_length; varying vec4 v_unique_id; uniform bool u_picking; // Attributes // ------------------------------------ // Functions // ------------------------------------ float new_alpha(float zoom_level); float atan2(float y, float x); // Main // ------------------------------------ void main() { if(!u_picking) { //This is the color of the outer arc lengths float R = 0.55; float R2 = 0.3; float dist = sqrt(dot(v_value, v_value)); float sm = smoothstep(R, R-0.0010, dist); float sm2 = smoothstep(R2, R2+0.0010, dist); float alpha = sm*sm2; float n_alpha = 1.0; if(v_zoom_level < 0.0010) { n_alpha = new_alpha(v_zoom_level); } else { discard; } float angle = atan(v_value[1], v_value[0]); if(dist < 0.25) { //gl_FragColor = v_cluster_color; gl_FragColor = vec4(v_cluster_color.rgb, n_alpha); } if(dist > 0.3 && 0.55 > dist) { float angle2 = angle+pi; if(angle2 > v_arc_length) { discard; } else { gl_FragColor = vec4(v_bg_color.rgb, n_alpha*alpha); } } angle = atan(v_value[1]/dist, v_value[0]/dist); //Need to add antialiasing to all other circles in the form of smoothstep. //THIS NEED TO BE FIXED if(dist > 0.61 && 0.9 > dist) { if(angle < v_outer_arc_length[1]) { gl_FragColor = vec4(0.32, 0.61, 0.93, n_alpha); //gl_FragColor = vec4(1.0, 0.0, 0.0, n_alpha); } else if(angle > v_outer_arc_length[1] && angle < v_outer_arc_length[2]) { gl_FragColor = vec4(0.337, 0.866, 0.415, n_alpha); //gl_FragColor = vec4(0.0, 1.0, 0.0, n_alpha); } else if(angle > v_outer_arc_length[2] && angle < v_outer_arc_length[3]) { gl_FragColor = vec4(0.988, 0.631, 0.058, n_alpha); //gl_FragColor = vec4(0.0, 0.0, 1.0, n_alpha); } else //if(angle > v_outer_arc_length[3] && angle < pi) { gl_FragColor = vec4(0.93, 0.949, 0.329, n_alpha); //gl_FragColor = vec4(1.0, 1.0, 0.0, n_alpha); } //else //{ // discard; //} // if(angle > -pi && angle < -pi/4.0) // { // //gl_FragColor = vec4(0.32, 0.61, 0.93, n_alpha); // gl_FragColor = vec4(1.0, 0.0, 0.0, n_alpha); // } // else if(angle > -pi/4.0 && angle < 0.0) // { // gl_FragColor = vec4(0.0, 1.0, 0.0, n_alpha); // } // else if(angle > 0.0 && angle < pi/2.0) // { // gl_FragColor = vec4(0.0, 0.0, 1.0, n_alpha); // } // else if(angle > pi/2.0 && angle < pi) // { // gl_FragColor = vec4(1.0, 1.0, 0.0, n_alpha); // } } } else { float dist = sqrt(dot(v_value, v_value)); if (dist > 0.9) discard; else gl_FragColor = v_unique_id; } } float atan2(float y, float x) { float s; if(abs(x) > abs(y)) s = 1.0; else s = 0.0; return (mix(pi/2.0 - atan(x,y), atan(y,x), s)); } //float atan2(in float y, in float x) //{ // return x == 0.0 ? sign(y)*pi/2 : atan(y, x); //} float new_alpha(float zoom_level) { float val = 1 - (zoom_level - 0.00075)/(0.0010-0.00075); if(val > 1.0) { val = 1.0; } return val; } """ vs_s = """ #version 120 // Uniforms // ------------------------------------ uniform mat4 u_model; uniform mat4 u_view; uniform mat4 u_projection; // Attributes // ------------------------------------ attribute vec3 a_position; attribute vec2 a_normal; attribute vec4 a_fg_color; attribute float a_linewidth; //attribute vec4 a_unique_id; //attribute vec4 l_color; // Varyings // ------------------------------------ varying vec4 v_fg_color; varying float v_zoom_level; varying vec2 v_normal; varying float v_linewidth; void main() { vec3 delta = vec3(a_normal*a_linewidth/((1-u_view[0][0])*0.1), 0); //vec3 delta = vec3(a_normal*a_linewidth/(1-u_view[0][0]), 0); gl_Position = u_model * u_view * u_projection * vec4(a_position+delta, 1.0); //gl_Position = u_projection * u_view * u_model * // vec4(a_position, 1.0); v_zoom_level = u_view[0][0]; v_fg_color = a_fg_color; v_normal = a_normal; v_linewidth = a_linewidth; } """ fs_s = """ #version 120 // Varying // ------------------------------------ varying vec4 v_fg_color; varying float v_zoom_level; varying vec2 v_normal; varying float v_linewidth; float new_alpha(float zoom_level); void main() { float l = length(v_normal); float feather = 0.5; float alpha = 1.0; if(l > v_linewidth/2.0+feather) discard; else alpha = 0.0; if(v_zoom_level < 0.0010) alpha = new_alpha(v_zoom_level); gl_FragColor = vec4(v_fg_color.rgb, alpha); } float new_alpha(float zoom_level) { float val = 1 - (zoom_level - 0.00075)/(0.0010-0.00075); if(val > 1.0) { val = 1.0; } return val; } """