41#define GLSL(src) "#version 150\n" #src
53 vert_color = vertColor;
55 gl_Position = mvp * vec4(vert + offset, 1.0);
61 out vec4 fragment_color;
70 fragment_color = vert_color;
88 vert_color = vertColor;
89 gl_Position = mvp * vec4(vert, 1.0);
95 uniform vec4 vertColor;
101 vert_color = vertColor;
102 gl_Position = mvp * vec4(vert, 1.0);
108 out vec4 fragment_color;
111 fragment_color = vert_color;
117 layout(line_strip, max_vertices=2) out;
118 in vec4 vert_color[];
125 vec2 win_pos_0 = gl_in[0].gl_Position.xy;
126 vec2 win_pos_1 = gl_in[1].gl_Position.xy;
127 gl_Position = gl_in[0].gl_Position;
129 v_color = vert_color[0];
131 gl_Position = gl_in[1].gl_Position;
133 line_pos = psize * length(win_pos_1 - win_pos_0);
135 v_color = vert_color[1];
149 vert_color = vertColor;
150 gl_Position = vec4(vert, 1.0);
156 layout(line_strip, max_vertices=20) out;
157 in vec4 vert_color[];
161 uniform mat4 un_view;
162 uniform mat4 text_proj;
168 const
float PI = 3.14159265359;
170 mat4 translate_this (in vec3 coord)
185 mat4 n_mvp = (mvp * translate_this (coord));
186 vec4
res = n_mvp * vec4(vec3(0.0), 1.0);
193 return vec3 (
res.x*viewp.z+viewp.x,
res.y*viewp.w+viewp.y,
res.z);
197 return vec3 (0.0, 0.0, -1.0);
201 float angle2d (in vec2 at, in vec2 bt, in vec2 ct)
205 float theta = dot(ab,bc) / (length(ab) * length(bc));
208 return acos (-2.0 - theta);
210 else if (theta > 1.0)
212 return acos (2.0 - theta);
222 vec3 pa =
project (gl_in[0].gl_Position.xyz);
223 vec3 pb =
project (gl_in[1].gl_Position.xyz);
224 vec3 pc =
project (gl_in[2].gl_Position.xyz);
228 float alpha = angle2d (pa.xy, pb.xy, pd);
229 float beta = angle2d (pc.xy, pb.xy, pd);
230 float theta = angle2d (pa.xy, pb.xy, pc.xy);
231 if (pa.y > pb.y && pc.y > pb.y)
233 beta =
min (alpha, beta);
235 else if (pa.y < pb.y && pc.y < pb.y)
237 beta =
min (-alpha, -beta);
244 pe.y =
max(pa.y, pc.y);
257 beta = angle2d (pe, pb.xy, pd);
258 alpha = angle2d (pf, pb.xy, pd);
259 if (beta + alpha < PI)
266 float tan_factor = tan(theta/10.0);
267 float radial_factor = cos(theta/10.0);
268 float dist =
min(length(pb-pa), length(pb-pc)) / 3.0;
269 float x =
dist * cos(beta);
270 float y =
dist * sin(beta);
276 v_color = vert_color[0];
278 vec4 pos_s = mvp * gl_in[0].gl_Position;
279 vec4 pos_e = mvp * gl_in[1].gl_Position;
283 float line_save = psize * length(pos_e.xy - pos_s.xy);
284 line_pos = line_save;
291 for (i = 0;
i < 11;
i++)
294 gl_Position = text_proj * (vec4(pb, 1.0) + vec4(apos.x, apos.y, 0.0, 1.0));
298 line_pos = line_save;
303 x += tx * tan_factor;
304 y += ty * tan_factor;
308 line_pos += psize * length(bpos - apos) / 20.0;
311 line_save = line_pos;
316 line_pos = line_save;
319 pos_s = mvp * gl_in[2].gl_Position;
320 line_pos += depth * psize * length(pos_s.xy - pos_e.xy);
329 uniform uint pattern;
333 out vec4 fragment_color;
336 fragment_color = v_color;
337 if (line_pos == -1.0) discard;
338 uint bit = uint(round(line_pos/factor)) % 16U;
339 if ((pattern & (1U<<bit)) == 0U) discard;
345 uniform uint pattern;
349 out vec4 fragment_color;
352 fragment_color = v_color;
353 if (line_pos == -1.0) discard;
366 out vec4 surfaceColor;
367 out vec3 surfacePosition;
368 out vec3 surfaceNormal;
369 out vec3 surfaceToCamera;
372 surfaceColor = vertColor;
374 surfacePosition = vec3(m_view * vec4(vert, 1.0f));
375 surfaceNormal = mat3(m_view) * vertNormal;
376 surfaceToCamera = normalize (- surfacePosition);
377 gl_Position = mvp * vec4(vert, 1.0f);
386 int COOK_BECKMANN = 4;
419 uniform
Light AllLights[10];
422 uniform
int lights_on;
423 uniform
int numLights;
425 in vec4 surfaceColor;
426 in vec3 surfacePosition;
427 in vec3 surfaceNormal;
428 in vec3 surfaceToCamera;
430 out vec4 fragment_color;
432 const float PI = 3.14159265359;
435 float saturate (in
float value)
437 return clamp(value, 0.0, 1.0);
441 float phong_diffuse()
448 vec3 fresnel_factor (in vec3 f0, in
float product)
450 return mix(f0, vec3(1.0), pow(1.01 - product, 5.0));
456 float D_blinn(in
float roughness, in
float NdH)
458 float m = roughness * roughness;
460 float n = 2.0 / m2 - 2.0;
461 return (n + 2.0) / (2.0 * PI) * pow(NdH, n);
464 float D_beckmann(in
float roughness, in
float NdH)
466 float m = roughness * roughness;
468 float NdH2 = NdH * NdH;
469 return exp((NdH2 - 1.0) / (m2 * NdH2)) / (PI * m2 * NdH2 * NdH2);
472 float D_GGX(in
float roughness, in
float NdH)
474 float m = roughness * roughness;
476 float d = (NdH * m2 - NdH) * NdH + 1.0;
477 return m2 / (PI *
d *
d);
480 float G_schlick(in
float roughness, in
float NdV, in
float NdL)
482 float k = roughness * roughness * 0.5;
483 float V = NdV * (1.0 -
k) + k;
484 float L = NdL * (1.0 -
k) + k;
485 return 0.25 / (V * L);
489 vec3 phong_specular(in vec3 V, in vec3 L, in vec3 N, in vec3 specular, in
float roughness)
491 vec3 R = reflect(-L, N);
492 float spec =
max(0.0, dot(V, R));
494 float k = 1.999 / (roughness * roughness);
496 return min(1.0, 3.0 * 0.0398 * k) * pow(spec,
min(10000.0, k)) * specular;
500 vec3 blinn_specular(in
float NdH, in vec3 specular, in
float roughness)
502 float k = 1.999 / (roughness * roughness);
504 return min(1.0, 3.0 * 0.0398 * k) * pow(NdH,
min(10000.0, k)) * specular;
508 vec3 cooktorrance_specular (in
int cook, in
float NdL, in
float NdV, in
float NdH, in vec3 specular, in
float roughness)
511 if (cook == COOK_BLINN)
513 D = D_blinn(roughness, NdH);
515 else if (cook == COOK_BECKMANN)
517 D = D_beckmann(roughness, NdH);
519 else if (cook == COOK_GGX)
521 D = D_GGX(roughness, NdH);
524 float G = G_schlick(roughness, NdV, NdL);
526 float rim = mix(1.0 - roughness * mat.back_light * 0.9, 1.0, NdV);
528 return (1.0 / rim) * specular * G * D;
531 vec3 Apply_lighting_model (in
int model, in
Light light, in vec3 specular)
533 vec3 v_pos = surfacePosition;
541 L = normalize (-light.direction);
546 vec3 L = light.position - v_pos;
547 float dist = length (L);
549 A = 1.0 / (light.constant + light.linear*
dist + light.quadratic*
dist*
dist);
552 float theta = dot(L, normalize(light.position-light.direction));
553 if(theta > light.cone_angle)
555 float epsilon = light.spot_inner - light.spot_outer;
556 I = saturate((theta - light.spot_outer) / epsilon);
564 vec3 V = normalize(-v_pos);
565 vec3 H = normalize(L + V);
566 vec3 N = surfaceNormal;
569 float NdL =
max(0.0, dot(N, L));
570 float NdV =
max(0.001, dot(N, V));
571 float NdH =
max(0.001, dot(N, H));
572 float HdV =
max(0.001, dot(H, V));
573 float LdV =
max(0.001, dot(L, V));
582 specfresnel = fresnel_factor (specular, NdV);
583 specref = phong_specular (V, L, N, specfresnel, mat.roughness);
585 else if (
model == BLINN)
588 specfresnel = fresnel_factor (specular, HdV);
589 specref = blinn_specular (NdH, specfresnel, mat.roughness);
594 specfresnel = fresnel_factor(specular, HdV);
595 specref = cooktorrance_specular(
model, NdL, NdV, NdH, specfresnel, mat.roughness);
598 specref *= vec3(NdL);
601 vec3 diffref = (vec3(1.0) - specfresnel) * phong_diffuse() * NdL;
604 vec3 reflected_light = vec3(0);
605 vec3 diffuse_light = vec3(0);
608 vec3 light_color = light.intensity * A * I;
609 reflected_light += specref * light_color;
610 diffuse_light += diffref * light_color;
613 return diffuse_light * mix(mat.albedo, vec3(0.0), mat.metallic) + reflected_light;
616 vec3 Apply_fog (in vec3 lightColor)
620 float fogFactor = 0.0;
626 dist = abs (surfacePosition.z);
631 dist = length (surfacePosition);
636 fogFactor = (fog.depth.x -
dist)/(fog.depth.y - fog.depth.x);
638 else if (fog.mode == 2)
640 fogFactor = 1.0 / exp (
dist * fog.density);
644 fogFactor = 1.0 / exp((
dist * fog.density)* (
dist * fog.density));
646 fogFactor = saturate (fogFactor);
647 return mix (fog.color, lightColor, fogFactor);
658 alpha = surfaceColor.w;
664 vec3 specular = mix(vec3(0.04), mat.albedo, mat.metallic);
666 for(
int i = 0;
i < numLights;
i++)
668 color += Apply_lighting_model (lights_on, AllLights[i], specular);
671 alpha = surfaceColor.w * mat.alpha;
675 fragment_color = vec4 (Apply_fog(surfaceColor.xyz*
color), alpha);
679 fragment_color = vec4 (surfaceColor.xyz*
color, alpha);
695 out vec4 surfaceColor;
696 out vec3 surfacePosition;
697 out vec3 surfaceNormal;
698 out vec3 surfaceToCamera;
701 surfaceColor = vertColor;
702 vec4 pos = vec4 (radius*vert + offset, 1.0);
703 surfacePosition = vec3(m_view * pos);
704 surfaceNormal = mat3(m_view) * vert;
705 surfaceToCamera = normalize (- surfacePosition);
707 gl_Position = mvp * pos;
714 uniform vec4 vertColor;
719 out vec4 surfaceColor;
720 out vec3 surfacePosition;
721 out vec3 surfaceNormal;
722 out vec3 surfaceToCamera;
725 surfaceColor = vertColor;
726 vec4 pos = vec4(vert, 1.0);
727 surfacePosition = vec3(m_view * pos);
728 surfaceNormal = mat3(m_view) * vertNormal;
729 surfaceToCamera = normalize (- surfacePosition);
731 gl_Position = mvp * pos;
744 gl_Position = vec4(vert, 1.0);
758 out vec4 surfaceColor;
759 out vec3 surfacePosition;
760 out vec3 surfaceNormal;
761 out vec3 surfaceToCamera;
763 vec3 rotate_this (in vec3 v, in vec4 quat)
765 vec3 u = vec3(quat.x, quat.y, quat.z);
767 return 2.0 * dot(u,v) * u + (s*s - dot(u,u)) * v + 2.0 * s *
cross (u,v);
772 surfaceColor = vertColor;
773 vec3 pos = vec3(radius*vert.x, radius*vert.y, height*vert.z);
774 vec3 norm = normalize (vec3(vert.x, vert.y, 0.0));
777 pos = rotate_this (pos, quat);
778 norm = rotate_this (norm, quat);
781 surfacePosition = vec3(m_view * vec4(pos,1.0));
782 surfaceNormal = mat3(m_view) * norm;
783 surfaceToCamera = normalize (- surfacePosition);
784 gl_Position = mvp * vec4(pos,1.0);
798 out vec4 surfaceColor;
799 out vec3 surfacePosition;
800 out vec3 surfaceNormal;
801 out vec3 surfaceToCamera;
803 vec3 rotate_this (in vec3 v, in vec4 quat)
805 vec3 u = vec3(quat.x, quat.y, quat.z);
807 return 2.0 * dot(u,v) * u + (s*s - dot(u,u)) * v + 2.0 * s *
cross (u,v);
812 surfaceColor = vertColor;
813 vec3 pos = vec3(radius*vert.x, radius*vert.y, height*vert.z);
815 float B = sqrt(radius*radius + height*height);
816 vec3 norm = vec3(height*vert.x/B, height*vert.y/B, radius/B);
819 pos = rotate_this (pos, quat);
820 norm = rotate_this (norm, quat);
823 surfacePosition = vec3(m_view * vec4(pos,1.0));
824 surfaceNormal = mat3(m_view) * norm;
825 surfaceToCamera = normalize (- surfacePosition);
826 gl_Position = mvp * vec4(pos,1.0);
839 out vec4 surfaceColor;
840 out vec3 surfacePosition;
841 out vec3 surfaceNormal;
842 out vec3 surfaceToCamera;
844 vec3 rotate_this (in vec3 v, in vec4 quat)
846 vec3 u = vec3(quat.x, quat.y, quat.z);
848 return 2.0 * dot(u,v) * u + (s*s - dot(u,u)) * v + 2.0 * s *
cross (u,v);
853 surfaceColor = vertColor;
854 vec3 pos = vec3(radius*vert.x, radius*vert.y, vert.z);
855 vec3 norm = vec3(0.0, 0.0, -1.0);
858 pos = rotate_this (pos, quat);
859 norm = rotate_this (norm, quat);
862 surfacePosition = vec3(m_view * vec4(pos,1.0));
863 surfaceNormal = mat3(m_view) * norm;
864 surfaceToCamera = normalize (- surfacePosition);
865 gl_Position = mvp * vec4(pos,1.0);
872 layout (triangle_strip, max_vertices=64) out;
877 uniform
float radius;
881 out vec4 surfaceColor;
882 out vec3 surfacePosition;
883 out vec3 surfaceNormal;
884 out vec3 surfaceToCamera;
886 float pi = 3.141592653;
888 vec3 create_perp (in vec3
axis)
890 vec3 u = vec3(0.0, 0.0, 1.0);
891 vec3 v = vec3(0.0, 1.0, 0.0);
893 if (length(
res) == 0.0)
903 vec3 v1 = gl_in[0].gl_Position.xyz;
904 vec3 v2 = gl_in[1].gl_Position.xyz;
905 vec3
axis = normalize(v2 - v1);
906 vec3 perp_x = create_perp (
axis);
908 float step = 2.0 *
pi / float(quality - 1);
909 for(
int i=0;
i<quality;
i++)
915 vec3 normal = normalize(ca*perp_x + sa*perp_y);
916 vec3
p1 = v1 + radius * normal;
917 vec3
p2 = v2 + radius * normal;
919 surfaceNormal = mat3(m_view) * normal;
920 gl_Position = mvp * vec4(p1, 1.0);
922 surfacePosition = vec3(m_view * vec4(p1, 1.0));
923 surfaceToCamera = normalize (- surfacePosition);
924 surfaceColor = vertCol[0];
927 gl_Position = mvp * vec4 (p2, 1.0);
928 surfacePosition = vec3(m_view * vec4(p2, 1.0));
929 surfaceToCamera = normalize (- surfacePosition);
930 surfaceColor = vertCol[1];
942 layout (triangle_strip, max_vertices=64) out;
946 uniform
float radius;
948 out vec3 surfacePosition;
949 out vec3 surfaceNormal;
950 out vec3 surfaceToCamera;
952 float pi = 3.141592653;
954 vec3 create_perp (in vec3
axis)
956 vec3 u = vec3(0.0, 0.0, 1.0);
957 vec3 v = vec3(0.0, 1.0, 0.0);
959 if (length(
res) == 0.0)
969 vec3 v1 = gl_in[0].gl_Position.xyz;
970 vec3 v2 = gl_in[1].gl_Position.xyz;
971 float r1 = gl_in[0].gl_Position.w;
972 float r2 = gl_in[1].gl_Position.w;
973 vec3
axis = normalize(v2 - v1);
974 vec3 perp_x = create_perp (
axis);
976 float step = 2.0 *
pi / float(32 - 1);
977 for(
int i=0;
i<32;
i++)
983 vec3 normal = normalize(ca*perp_x + sa*perp_y);
984 vec3
p1 = v1 + r1 * normal;
985 vec3
p2 = v2 + r2 * normal;
987 surfaceNormal = mat3(m_view) * normal;
988 gl_Position = mvp * vec4(p1, 1.0);
990 surfacePosition = vec3(m_view * vec4(p1, 1.0));
991 surfaceToCamera = normalize (- surfacePosition);
994 gl_Position = mvp * vec4 (p2, 1.0);
995 surfacePosition = vec3(m_view * vec4(p2, 1.0));
996 surfaceToCamera = normalize (- surfacePosition);
1009 out vec4 surfaceColor;
1012 surfaceColor = vertColor;
1020 layout (triangle_strip, max_vertices=3) out;
1023 uniform mat4 m_view;
1025 out vec3 surfacePosition;
1026 out vec3 surfaceNormal;
1027 out vec3 surfaceToCamera;
1029 float pi = 3.141592653;
1033 vec3 edge_a = v3 - v1;
1034 vec3 edge_b = v2 - v1;
1035 return normalize(
cross(edge_a, edge_b));
1044 v[
i] = gl_in[
i].gl_Position.xyz;
1046 float sign = gl_in[0].gl_Position.w;
1048 surfaceNormal = mat3(m_view) * normal;
1051 gl_Position = mvp * vec4(v[i], 1.0);
1052 surfacePosition = vec3(m_view * vec4(v[i], 1.0));
1053 surfaceToCamera = normalize (- surfacePosition);
1064 int COOK_TORRANCE = 3;
1066 int COOK_BECKMANN = 4;
1099 uniform
Light AllLights[10];
1102 uniform
int lights_on;
1103 uniform
int numLights;
1104 uniform vec4 vertColor;
1106 in vec3 surfacePosition;
1107 in vec3 surfaceNormal;
1108 in vec3 surfaceToCamera;
1110 out vec4 fragment_color;
1112 const float PI = 3.14159265359;
1115 float saturate (in
float value)
1117 return clamp(value, 0.0, 1.0);
1121 float phong_diffuse()
1128 vec3 fresnel_factor (in vec3 f0, in
float product)
1130 return mix(f0, vec3(1.0), pow(1.01 - product, 5.0));
1136 float D_blinn(in
float roughness, in
float NdH)
1138 float m = roughness * roughness;
1140 float n = 2.0 / m2 - 2.0;
1141 return (n + 2.0) / (2.0 * PI) * pow(NdH, n);
1144 float D_beckmann(in
float roughness, in
float NdH)
1146 float m = roughness * roughness;
1148 float NdH2 = NdH * NdH;
1149 return exp((NdH2 - 1.0) / (m2 * NdH2)) / (PI * m2 * NdH2 * NdH2);
1152 float D_GGX(in
float roughness, in
float NdH)
1154 float m = roughness * roughness;
1156 float d = (NdH * m2 - NdH) * NdH + 1.0;
1157 return m2 / (PI *
d *
d);
1160 float G_schlick(in
float roughness, in
float NdV, in
float NdL)
1162 float k = roughness * roughness * 0.5;
1163 float V = NdV * (1.0 -
k) + k;
1164 float L = NdL * (1.0 -
k) + k;
1165 return 0.25 / (V * L);
1169 vec3 phong_specular(in vec3 V, in vec3 L, in vec3 N, in vec3 specular, in
float roughness)
1171 vec3 R = reflect(-L, N);
1172 float spec =
max(0.0, dot(V, R));
1174 float k = 1.999 / (roughness * roughness);
1176 return min(1.0, 3.0 * 0.0398 * k) * pow(spec,
min(10000.0, k)) * specular;
1180 vec3 blinn_specular(in
float NdH, in vec3 specular, in
float roughness)
1182 float k = 1.999 / (roughness * roughness);
1184 return min(1.0, 3.0 * 0.0398 * k) * pow(NdH,
min(10000.0, k)) * specular;
1188 vec3 cooktorrance_specular (in
int cook, in
float NdL, in
float NdV, in
float NdH, in vec3 specular, in
float roughness)
1191 if (cook == COOK_BLINN)
1193 D = D_blinn(roughness, NdH);
1195 else if (cook == COOK_BECKMANN)
1197 D = D_beckmann(roughness, NdH);
1199 else if (cook == COOK_GGX)
1201 D = D_GGX(roughness, NdH);
1204 float G = G_schlick(roughness, NdV, NdL);
1206 float rim = mix(1.0 - roughness * mat.back_light * 0.9, 1.0, NdV);
1208 return (1.0 / rim) * specular * G * D;
1211 vec3 Apply_lighting_model (in
int model, in
Light light, in vec3 specular)
1213 vec3 v_pos = surfacePosition;
1218 if (light.type == 0)
1221 L = normalize (-light.direction);
1226 vec3 L = light.position - v_pos;
1227 float dist = length (L);
1229 A = 1.0 / (light.constant + light.linear*
dist + light.quadratic*
dist*
dist);
1230 if (light.type == 2)
1232 float theta = dot(L, normalize(light.position-light.direction));
1233 if(theta > light.cone_angle)
1235 float epsilon = light.spot_inner - light.spot_outer;
1236 I = saturate((theta - light.spot_outer) / epsilon);
1240 return vec3(0.0001);
1244 vec3 V = normalize(-v_pos);
1245 vec3 H = normalize(L + V);
1246 vec3 N = surfaceNormal;
1249 float NdL =
max(0.0, dot(N, L));
1250 float NdV =
max(0.001, dot(N, V));
1251 float NdH =
max(0.001, dot(N, H));
1252 float HdV =
max(0.001, dot(H, V));
1253 float LdV =
max(0.001, dot(L, V));
1262 specfresnel = fresnel_factor (specular, NdV);
1263 specref = phong_specular (V, L, N, specfresnel, mat.roughness);
1265 else if (
model == BLINN)
1268 specfresnel = fresnel_factor (specular, HdV);
1269 specref = blinn_specular (NdH, specfresnel, mat.roughness);
1274 specfresnel = fresnel_factor(specular, HdV);
1275 specref = cooktorrance_specular(
model, NdL, NdV, NdH, specfresnel, mat.roughness);
1278 specref *= vec3(NdL);
1281 vec3 diffref = (vec3(1.0) - specfresnel) * phong_diffuse() * NdL;
1284 vec3 reflected_light = vec3(0);
1285 vec3 diffuse_light = vec3(0);
1288 vec3 light_color = light.intensity * A * I;
1289 reflected_light += specref * light_color;
1290 diffuse_light += diffref * light_color;
1293 return diffuse_light * mix(mat.albedo, vec3(0.0), mat.metallic) + reflected_light;
1296 vec3 Apply_fog (in vec3 lightColor)
1300 float fogFactor = 0.0;
1306 dist = abs (surfacePosition.z);
1311 dist = length (surfacePosition);
1316 fogFactor = (fog.depth.x -
dist)/(fog.depth.y - fog.depth.x);
1318 else if (fog.mode == 2)
1320 fogFactor = 1.0 / exp (
dist * fog.density);
1324 fogFactor = 1.0 / exp((
dist * fog.density)* (
dist * fog.density));
1326 fogFactor = saturate (fogFactor);
1327 return mix (fog.color, lightColor, fogFactor);
1338 alpha = vertColor.w;
1344 vec3 specular = mix(vec3(0.04), mat.albedo, mat.metallic);
1346 for(
int i = 0;
i < numLights;
i++)
1348 color += Apply_lighting_model (lights_on, AllLights[i], specular);
1351 alpha = vertColor.w * mat.alpha;
1355 fragment_color = vec4 (Apply_fog(vertColor.xyz*
color), alpha);
1359 fragment_color = vec4 (vertColor.xyz*
color, alpha);
1367 out uvec4 fragment_color;
1370 fragment_color = uvec4(vert_color);
1376 uniform mat4 un_view;
1377 uniform mat4 text_proj;
1379 uniform vec4 pos_shift;
1385 out vec2 text_coords;
1386 mat4 translate_this (in vec3 coord)
1389 translate[0] = vec4(1.0, 0.0, 0.0, 0.0);
1390 translate[1] = vec4(0.0, 1.0, 0.0, 0.0);
1391 translate[2] = vec4(0.0, 0.0, 1.0, 0.0);
1402 mat4 n_mvp = ((mvp * translate_this (coord)) * un_view) * translate_this (pos_shift.xyz);
1403 vec4
res = n_mvp * vec4(vec3(0.0), 1.0);
1410 return vec4 (
res.x*viewp.z+viewp.x,
res.y*viewp.w+viewp.y, pos_shift.w*
res.z, 1.0);
1414 return vec4 (0.0, 0.0, -1.0, 0.0);
1420 text_coords = tcoord;
1421 vec4 pos =
project (offset) + vec4(vert, 0.0, 1.0);
1422 gl_Position = text_proj * pos;
1428 uniform mat4 un_view;
1429 uniform mat4 text_proj;
1431 uniform vec4 pos_shift;
1440 out vec2 text_coords;
1442 float angle2d (in vec2 at, in vec2 bt, in vec2 ct)
1446 float theta = dot(ab,bc) / (length(ab) * length(bc));
1449 return acos (-2.0 - theta);
1451 else if (theta > 1.0)
1453 return acos (2.0 - theta);
1457 return acos (theta);
1461 mat4 rotate_this_z (in
float theta)
1463 return mat4 ( vec4( cos(theta), sin(theta), 0.0, 0.0),
1464 vec4(-sin(theta), cos(theta), 0.0, 0.0),
1465 vec4( 0.0, 0.0, 1.0, 0.0),
1466 vec4( 0.0, 0.0, 0.0, 1.0));
1469 mat4 translate_this (in vec3 coord)
1472 translate[0] = vec4(1.0, 0.0, 0.0, 0.0);
1473 translate[1] = vec4(0.0, 1.0, 0.0, 0.0);
1474 translate[2] = vec4(0.0, 0.0, 1.0, 0.0);
1485 mat4 n_mvp = mvp * translate_this (coord) * un_view;
1486 vec4
res = n_mvp * vec4(vec3(0.0), 1.0);
1494 return vec4 (
res.x*viewp.z+viewp.x,
res.y*viewp.w+viewp.y,
shift.w*
res.z, 1.0);
1498 return vec4 (0.0, 0.0, -1.0, 0.0);
1504 text_coords = tcoord;
1505 float rot_angle = 0.0;
1506 vec4
shift = pos_shift;
1509 vec3 pos_a =
project (at_a, vec4(0.0)).xyz;
1510 vec3 pos_b =
project (at_b, vec4(0.0)).xyz;
1514 pa.y =
max(pos_a.y, pos_b.y);
1515 if (pa.y == pos_a.y)
1529 rot_angle = - angle2d (pa, pb, pc);
1532 rot_angle = -rot_angle;
1537 if (rot_angle != 0.0)
1539 pos =
project(offset,
shift) + vec4(vert, 0.0, 1.0) * rotate_this_z(rot_angle);
1545 gl_Position = text_proj * pos;
1551 uniform mat4 un_view;
1552 uniform mat4 text_proj;
1554 uniform vec4 pos_shift;
1564 const float PI = 3.14159265359;
1566 out vec2 text_coords;
1568 float angle2d (in vec2 at, in vec2 bt, in vec2 ct)
1572 float theta = dot(ab,bc) / (length(ab) * length(bc));
1575 return acos (-2.0 - theta);
1577 else if (theta > 1.0)
1579 return acos (2.0 - theta);
1583 return acos (theta);
1587 mat4 rotate_this_z (in
float theta)
1589 return mat4 ( vec4( cos(theta), sin(theta), 0.0, 0.0),
1590 vec4(-sin(theta), cos(theta), 0.0, 0.0),
1591 vec4( 0.0, 0.0, 1.0, 0.0),
1592 vec4( 0.0, 0.0, 0.0, 1.0));
1595 mat4 translate_this (in vec3 coord)
1598 translate[0] = vec4(1.0, 0.0, 0.0, 0.0);
1599 translate[1] = vec4(0.0, 1.0, 0.0, 0.0);
1600 translate[2] = vec4(0.0, 0.0, 1.0, 0.0);
1611 mat4 n_mvp = mvp * translate_this (coord) * un_view;
1612 vec4
res = n_mvp * vec4(vec3(0.0), 1.0);
1620 return vec4 (
res.x*viewp.z+viewp.x,
res.y*viewp.w+viewp.y,
shift.w*
res.z, 1.0);
1624 return vec4 (0.0, 0.0, -1.0, 0.0);
1630 text_coords = tcoord;
1631 float rot_angle = 0.0;
1632 vec4
shift = pos_shift;
1633 vec3 pos_a =
project (at_a, vec4(0.0)).xyz;
1634 vec3 pos_b =
project (at_b, vec4(0.0)).xyz;
1635 vec3 pos_c =
project (at_c, vec4(0.0)).xyz;
1640 float theta = angle2d (pa, pb, pc);
1641 pd.x = pb.x + 100.0;
1650 beta = angle2d (pa, pb, pd);
1651 alpha = angle2d (pc, pb, pd);
1652 if (pa.y > pb.y && pc.y > pb.y)
1654 gamma =
min (alpha, beta);
1656 else if (pa.y < pb.y && pc.y < pb.y)
1658 gamma =
min (-alpha, -beta);
1664 pe.y =
max(pa.y, pc.y);
1677 beta = angle2d (pe, pb, pd);
1679 alpha = angle2d (pf, pb, pd);
1680 if (beta + alpha < PI)
1685 rot_angle = PI/2.0 - gamma - theta/2.0;
1686 vec3
a = at_b + ((at_a - at_b)/3.0 + (at_c - at_b)/3.0)/2.0;
1688 float dist =
min(length(pb-pa), length(pb-pc)) / 3.0;
1689 float x = pb.x + (
shift.x+
dist) * sin(rot_angle);
1690 float y = pb.y + (
shift.y+
dist) * cos(rot_angle);
1691 if (pa.y < pb.y && pc.y < pb.y)
1693 gamma = -
max (alpha, beta);
1695 else if (pa.y > pb.y || pc.y > pb.y)
1699 rot_angle = PI/2.0 - gamma - theta/2.0;
1700 vec3
c = vec3(
x,
y,
b.z);
1701 vec4 pos = vec4(
c, 1.0);
1705 pos += vec4(vert, 0.0, 1.0) * rotate_this_z(rot_angle);
1709 pos += vec4(vert, 0.0, 1.0);
1711 gl_Position = text_proj * pos;
1716 uniform sampler2DRect tex;
1717 uniform vec4 vert_color;
1720 in vec2 text_coords;
1722 out vec4 fragment_color;
1725 vec2 coords = text_coords;
1726 fragment_color = vert_color * vec4(1.0, 1.0, 1.0, texture (tex, text_coords).r);
1731 uniform sampler2DRect tex;
1732 uniform vec4 vert_color;
1733 in vec2 text_coords;
1735 out vec4 fragment_color;
1738 vec4 sampled = vec4(1.0, 1.0, 1.0, texture (tex, text_coords).r);
1739 fragment_color = vert_color * sampled;
void translate(project *this_proj, int status, int axis, vec3_t trans)
translate
vec3_t get_triangle_normal(vec3_t v1, vec3_t v2, vec3_t v3)
compute triangle normal vector
Global variable declarations Global convenience function declarations Global data structure defin...
struct project project
data structure for the 'atomes' project
int main(int argc, char *argv[])
initialization of the atomes program
double precision, dimension(3) rim
const GLchar * full_color
const GLchar * gs_cylinder_vertex
const GLchar * string_color_2d
const GLchar * string_vertex
const GLchar * line_stipple_color
const GLchar * axis_sphere_vertex
const GLchar * angle_stipple
const GLchar * angle_vertex
const GLchar * polyedron_vertex
const GLchar * gs_cylinder_geom
const GLchar * pick_color
const GLchar * polyedron_geom
const GLchar * polyedron_color
const GLchar * cylinder_vertex
const GLchar * string_color
const GLchar * full_vertex
const GLchar * line_color
const GLchar * line_stipple
const GLchar * cap_vertex
const GLchar * axis_cylinder_geom
const GLchar * angle_color
const GLchar * line_vertex
const GLchar * sphere_vertex
const GLchar * point_vertex
const GLchar * axis_line_vertex
const GLchar * cone_vertex
const GLchar * degree_vertex
const GLchar * point_color
const GLchar * angstrom_vertex