scg3  0.6
phong_frag.glsl
Go to the documentation of this file.
1 /**
2  * \file phong_frag.glsl
3  * \brief Phong fragment shader, uses external functions applyLighting()
4  * and applyTexture().
5  */
6 
7 #version 150
8 
9 smooth in vec3 ecVertex;
10 smooth in vec3 ecNormal;
11 smooth in vec4 texCoord0;
12 
13 uniform mat4 colorMatrix;
14 
15 out vec4 fragColor;
16 
17 
18 // --- declarations ---
19 
20 
21 void applyLighting(const in vec3 ecVertex, const in vec3 ecNormal,
22  out vec4 emissionAmbientDiffuse, out vec4 specular);
23 
24 vec4 applyTexture(const in vec4 texCoord, const in vec4 emissionAmbientDiffuse,
25  const in vec4 specular);
26 
27 
28 // --- implementations ---
29 
30 
31 void main(void) {
32 
33  // apply lighting model (to be defined in separate shader)
34  vec4 emissionAmbientDiffuse, specular;
35  applyLighting(ecVertex, ecNormal, emissionAmbientDiffuse, specular);
36 
37  // apply texture and determine color (to be defined in separate shader)
38  vec4 color = applyTexture(texCoord0, emissionAmbientDiffuse, specular);
39 
40  // transform color by color matrix
41  vec4 transformedColor = colorMatrix * vec4(color.rgb, 1.);
42  transformedColor /= transformedColor.a; // perspective division
43 
44  // set final fragment color
45  fragColor = clamp(vec4(transformedColor.rgb, color.a), 0., 1.);
46 }