Debian Codegraph @

shaders/std.frag

raw
1 #version 330
2 in vec3 Normal;
3 in vec3 nor;
4
5 uniform vec4 Color=vec4(1,1,0,1);
6 uniform vec3 lightPos;
7 uniform int inFocus = -1;
8
9 out vec4 fragColor;
10
11 const float a = 4.0 / sqrt(10.0 + 2.0 * sqrt(5.0));
12 const float re = 0.25 * (1.0 + sqrt(5.0)) * a;
13 const float ri = sqrt(3.0) / 12.0 * (3.0 + sqrt(5.0)) * a;
14 const float r1 =(re+ri+ri)/3;
15 const float r2 =(re+re+1)/3;
16
17 vec3 blinnPhongDirectional( vec3 n , vec3 kd) {
18 vec3 ambient = kd * 0.5;//Light.La * Material.Ka;
19 vec3 intensity = vec3(0.8, 0.8, 0.8);
20 vec3 s = normalize(lightPos);// directional light
21 float sDotN = abs(dot(s, n));
22 vec3 diffuse = kd * sDotN;
23 vec3 spec = vec3(0.0);
24 float Shininess = 48.0;
25 if (sDotN > 0.0) {
26 spec = vec3(1,1,1) * pow(max(dot(s,n), 0.0), Shininess);
27 }
28 return ambient + intensity * (diffuse + spec);
29 }
30
31 void main( void ){
32 float v = length(nor);
33 // edge raius of icosahedron re = 0.25 * (1 + sqrt(5)) = 0.809016994 * a
34 // inner radius of icosahedron ri = sqrt(3)/12 * (3 + sqrt(5) = 0.755761314 * a
35 // {\displaystyle r_{i}={\frac {\sqrt {3}}{12}}(3+{\sqrt {5}})\cdot a} ≈ 0,756 ⋅ a {\displaystyle \approx 0{,}756\cdot a}
36 if (inFocus>-1){
37 if (v<re) discard;
38 }else {
39 if (v<r1) discard;// round hole
40 if ((v>re)&&(v<r2)) discard;// pentagon hole
41 }
42 if (gl_FrontFacing) {
43 /*if (inFocus==-2) fragColor = vec4(blinnPhongDirectional( Normal, vec3(0.8,0.2,1.0)), 1.0);
44 else if (inFocus>-1) fragColor = vec4(blinnPhongDirectional( Normal, vec3(0.4,0.8,1.0)), 1.0);
45 else */
46 fragColor = vec4(blinnPhongDirectional( Normal, Color.rgb), 0.5);
47 //vec4(blinnPhongDirectional( Normal, abs(nor), 0.5);//
48 }
49 else discard;
50 }