Debian Codegraph @

shaders/bond.geom

raw
1 #version 330
2
3 layout(lines) in;
4 layout(triangle_strip, max_vertices = 60) out;
5 //layout(line_strip, max_vertices = 113) out;
6
7 const float PI = 3.14159265359f;
8
9 uniform mat3 normalMatrix;
10 uniform mat4 pmv;
11 uniform int segments = 2;
12 uniform float radius = 0.09f;
13 uniform float qradius = 0.02f;
14 uniform float qcutoff = -10.0;
15 uniform bool h_bonds = true;
16 uniform bool qPeakBonds = true;
17 uniform bool hideHydrogen = false;
18
19 in vec3 vPos[];
20 in float styleI[];
21 in float an[];
22 in float ph[];
23 in float sg[];
24
25 out vec3 Normal;
26 vec3 vert=vec3(0,0,0);
27 out float distance_from_start;
28 flat out int _style;
29 flat out int _an;
30 flat out int _sg;
31 flat out float ph_or_part;
32 flat out float bondlength;
33 out gl_PerVertex{
34 vec4 gl_Position;
35 };
36
37
38 void main(void){
39 if (((int(styleI[0])|(int(styleI[1])))&512)>0) return;
40 if ((hideHydrogen)&&((an[0] == 0) || ( an[1] == 0))) return;
41 vec4 start = gl_in[0].gl_Position;
42 vec4 end = gl_in[1].gl_Position;
43 start.w = 1.0;
44 end.w = 1.0;
45 vec3 direction = normalize(end.xyz - start.xyz);
46 float l = length(end.xyz - start.xyz);
47 vec3 lot = (abs(dot(direction, vec3(1, 0, 0))) > 0.8)?
48 (abs(dot(direction, vec3(0, 1, 0))) > 0.8)?
49 normalize(cross(direction, vec3(0, 0, 1))):
50 normalize(cross(direction, vec3(0, 1, 0))):
51 normalize(cross(direction, vec3(1, 0, 0)));
52 vec3 lot2 = normalize(cross(direction,lot));
53 vec3 r = vec3(0,0,0);
54 int toan = int(((an[0]<0)||(an[1]<0)) ? min(an[0], an[1]) : an[0] + 1000*an[1]);
55 int tostyle = int(styleI[0]) + (int(styleI[1])<<14);
56 float rad = (toan<0) ? qradius/20.0 : radius;
57 //if (!h_bonds) return;
58 if ((!h_bonds) && ((an[0] == 0) || ( an[1] == 0)) && (l > 1.3)) return; //h_bonds
59 if ((toan==-1) && (!qPeakBonds)) return;
60 if ((((an[0] == -1) || ( an[1] == -1))) && ((ph[0]<qcutoff) || (ph[1]<qcutoff))) return;
61 for (int i = 0; i <= 2*segments; i++){
62 r = sin(PI * i / segments) * lot + cos(PI * i / segments) * lot2;
63 vert = start.xyz + rad * r;
64 gl_Position = pmv* vec4(vert, 1);
65 Normal = normalMatrix * r;
66 bondlength = l;
67 _an = toan;
68 _sg = int(sg[0]);
69 ph_or_part = ph[0];
70 _style = tostyle;//abs(styleI[0]-styleI[1]);
71 distance_from_start = 0.0;
72 EmitVertex();
73 vert = end.xyz + rad * r;
74 gl_Position = pmv* vec4(vert , 1);
75 Normal = normalMatrix * r;
76 distance_from_start = 1.0;
77 bondlength = l;
78 _an = toan;
79 _sg = int(sg[1]);
80 ph_or_part = ph[1];
81 _style = tostyle;//abs(styleI[0]-styleI[1]);
82 EmitVertex();
83 }
84 EndPrimitive();
85 }