Debian Codegraph @

tests/manual/clip-planes-qml/phong-clip.frag

raw
1 #version 150 core
2
3 // TODO: Replace with a uniform block
4 uniform vec4 lightPosition;
5 uniform vec3 lightIntensity;
6
7 // TODO: Replace with a struct
8 uniform vec3 ka; // Ambient reflectivity
9 uniform vec3 kd; // Diffuse reflectivity
10 uniform vec3 ks; // Specular reflectivity
11 uniform float shininess; // Specular shininess factor
12
13 in VertexData {
14 in vec3 position;
15 in vec3 normal;
16 } v_in;
17
18 out vec4 fragColor;
19
20 vec3 adsModel( const in vec3 pos, const in vec3 n )
21 {
22 // Calculate the vector from the light to the fragment
23 vec3 s = normalize( vec3( lightPosition ) - pos );
24
25 // Calculate the vector from the fragment to the eye position
26 // (origin since this is in "eye" or "camera" space)
27 vec3 v = normalize( -pos );
28
29 // Reflect the light beam using the normal at this fragment
30 vec3 r = reflect( -s, n );
31
32 // Calculate the diffuse component
33 float diffuse = max( dot( s, n ), 0.0 );
34
35 // Calculate the specular component
36 float specular = 0.0;
37 if ( dot( s, n ) > 0.0 )
38 specular = pow( max( dot( r, v ), 0.0 ), shininess );
39
40 // Combine the ambient, diffuse and specular contributions
41 return lightIntensity * ( ka + kd * diffuse + ks * specular );
42 }
43
44 void main()
45 {
46 fragColor = vec4( adsModel( v_in.position, normalize( v_in.normal ) ), 1.0 );
47 }