2 * \file phong_frag.glsl
3 * \brief Phong fragment shader, uses external functions applyLighting()
9 smooth in vec3 ecVertex;
10 smooth in vec3 ecNormal;
11 smooth in vec4 texCoord0;
13 uniform mat4 colorMatrix;
18 // --- declarations ---
21 void applyLighting(const in vec3 ecVertex, const in vec3 ecNormal,
22 out vec4 emissionAmbientDiffuse, out vec4 specular);
24 vec4 applyTexture(const in vec4 texCoord, const in vec4 emissionAmbientDiffuse,
25 const in vec4 specular);
28 // --- implementations ---
33 // apply lighting model (to be defined in separate shader)
34 vec4 emissionAmbientDiffuse, specular;
35 applyLighting(ecVertex, ecNormal, emissionAmbientDiffuse, specular);
37 // apply texture and determine color (to be defined in separate shader)
38 vec4 color = applyTexture(texCoord0, emissionAmbientDiffuse, specular);
40 // transform color by color matrix
41 vec4 transformedColor = colorMatrix * vec4(color.rgb, 1.);
42 transformedColor /= transformedColor.a; // perspective division
44 // set final fragment color
45 fragColor = clamp(vec4(transformedColor.rgb, color.a), 0., 1.);