/* * Fragment shader to perform "angle-of-incidence" based shading: points near * "the edge" of an object will be more bright and more solid than points * near "the center" of the object. In reality, we use the dot product * between the viewing vector and the surface normal to determine this * weight. With specular lighting, can give the object a glassy look. * * Alexandri Zavodny, Fall 2010 * for CSE 40166/60166 Computer Graphics, University of Notre Dame */ varying vec4 theColor; varying vec3 theNormal; varying vec3 dirToLight; varying vec4 normalInDeviceCoords; void main() { float mag = 1.0 - dot(normalize(normalInDeviceCoords), vec4(0.0,0.0,-1.0,0.0)); //Uncomment this line to get a sharper falloff! //mag = mag*mag; float specularIntensity = max(dot(normalize(gl_LightSource[0].halfVector.xyz), theNormal), 0.0); vec4 specularColor = vec4(1.0,1.0,1.0,1.0); vec4 specularComponent = pow(specularIntensity, 50.0) * specularColor; float lc = dot(dirToLight, theNormal); gl_FragColor = clamp(specularComponent + vec4(mag, mag, mag, mag), 0.0, 1.0); }