Debian Codegraph @

shaders/splitrot.frag

raw
1 #version 330
2
3 in vec3 Normal;
4 in float distance_from_start;
5 in float rl;
6 in float bondlength;
7 uniform vec3 lightPos;
8 layout( location = 0 ) out vec4 fragColor;
9
10 /*
11 uniform struct LightInfo {
12 vec4_an%1000; // Position; // Light position in eye coords.
13 vec3 La; // Ambient light intesity
14 vec3 L; // Diffuse and specular light intensity
15 } Light;
16
17 uniform struct MaterialInfo {
18 vec3 Ka; // Ambient reflectivity
19 vec3 Kd; // Diffuse reflectivity
20 vec3 Ks; // Specular reflectivity
21 float Shininess; // Specular shininess factor
22 } Material;
23 */
24
25 vec3 blinnPhong( vec3 position, vec3 n , vec3 kd) {
26 vec3 ambient = vec3(0.25, 0.25, 0.25);//Light.La * Material.Ka;
27 vec3 intensity = vec3(0.95, 0.95, 0.95);
28 vec3 s = normalize(lightPos - position );
29 float sDotN = max(dot(s,n), 0.0 );
30 vec3 diffuse = kd * sDotN;
31 vec3 spec = vec3(0.0);
32 float Shininess = 48.0;
33 if (sDotN > 0.0) {
34 vec3 v = normalize(-position.xyz);
35 vec3 h = normalize(v + s);
36 spec = vec3(1,1,1) * pow(max(dot(h,n), 0.0), Shininess);
37 }
38 return ambient + intensity * (diffuse + spec);
39 }
40
41 vec3 blinnPhongDirectional( vec3 n , vec3 kd) {
42 vec3 ambient = kd * 0.5;//Light.La * Material.Ka;
43 vec3 intensity = vec3(0.8, 0.8, 0.8);//specular and diffuse
44 vec3 s = normalize(lightPos);// directional light
45 float sDotN = abs(dot(s,n));
46 vec3 diffuse = kd * sDotN;
47 vec3 spec = vec3(0.0);
48 float Shininess = 48.0;
49 if (sDotN > 0.0) {
50 spec = vec3(1,1,1) * pow(max(dot(s,n), 0.0), Shininess);
51 }
52 return ambient + intensity * (diffuse + spec);
53 }
54
55
56
57 void main(void){
58 int st2 = 0;
59 //two sided lighting:
60 vec3 Color = (rl<1.5)?vec3(1.0,0.4,0.2):vec3(0.0,0.4,1.0);
61 if (rl>2.5) Color = vec3(1,0,0);
62 if (rl>3.5) Color = vec3(0,1,0);
63 if (rl>4.5) Color = vec3(0,0,1);
64 if (gl_FrontFacing) fragColor = vec4(blinnPhongDirectional(normalize(Normal), Color), 1.0);
65 else fragColor = vec4(blinnPhongDirectional(normalize(-Normal), mix(Color,vec3(0.5,0.7,0.5),0.2)), 1.0);//a bit greener?
66
67 }