Blame view

subgraph_shaders.py 6.89 KB
9f9f1788   Pavel Govyadinov   clead up version ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  #!/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;
25fa0bfe   Pavel Govyadinov   Stable, pre-vispy...
17
  //uniform vec3 u_graph_size;
9f9f1788   Pavel Govyadinov   clead up version ...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
  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;
9f9f1788   Pavel Govyadinov   clead up version ...
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
  
  // 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;
  }
25fa0bfe   Pavel Govyadinov   Stable, pre-vispy...
274
  """