kinect-viewer / lighting.fs

Cliff Biffle f60d65c 

 * Copyright 2010 Cliff L. Biffle.  All Rights Reserved.
 * Use of this source code is governed by the Apache License 2.0,
 * which can be found in the LICENSE file.

 * Computes lighting per-vertex using Blinn-Phong, plus diffuse/ambient.
vec4 light_vertex(vec3 normal) {
  vec3 eyeSpaceNormal = normalize(gl_NormalMatrix * normal);
  // Note: this forces all lights to be directional lights.
  vec3 lightDir = normalize(vec3(gl_LightSource[0].position));
  float NdotL = max(dot(eyeSpaceNormal, lightDir), 0.0);
  // Diffuse
  vec4 diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
  vec4 ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient
               + gl_FrontMaterial.ambient * gl_LightModel.ambient;
  vec4 specular = vec4(0, 0, 0, 0);
  if (NdotL > 0.0) {
    float NdotHV = max(dot(eyeSpaceNormal, gl_LightSource[0], 0.0);
    specular = gl_FrontMaterial.specular * gl_LightSource[0].specular
             * pow(NdotHV, gl_FrontMaterial.shininess);
  return NdotL * diffuse + ambient + specular;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.