Browse Source

Phong shader: finally fixed specular highlights.

The highlights are now based on camera position, which is finally the
way it should be since forever.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
d1f5ec7479
  1. 3
      src/Shaders/PhongShader.frag
  2. 4
      src/Shaders/PhongShader.vert

3
src/Shaders/PhongShader.frag

@ -8,6 +8,7 @@ uniform float shininess = 80.0;
in vec3 transformedNormal;
in vec3 lightDirection;
in vec3 cameraDirection;
out vec4 color;
@ -25,7 +26,7 @@ void main() {
/* Add specular color, if needed */
if(intensity != 0) {
vec3 reflection = reflect(-normalizedLightDirection, normalizedTransformedNormal);
float specularity = pow(max(0.0, dot(normalizedTransformedNormal, reflection)), shininess);
float specularity = pow(max(0.0, dot(normalize(cameraDirection), reflection)), shininess);
color.rgb += specularColor*specularity;
}

4
src/Shaders/PhongShader.vert

@ -9,6 +9,7 @@ in vec3 normal;
out vec3 transformedNormal;
out vec3 lightDirection;
out vec3 cameraDirection;
void main() {
/* Transformed vertex position */
@ -21,6 +22,9 @@ void main() {
/* Direction to the light */
lightDirection = normalize(light - transformedVertex);
/* Direction to the camera */
cameraDirection = -transformedVertex;
/* Transform the vertex */
gl_Position = projectionMatrix*transformedVertex4;
}

Loading…
Cancel
Save