Computes the Phong specular weight for a light source
#pragma glslify: phongSpec = require(glsl-specular-phong)
uniform vec3 eyePosition;
uniform vec3 lightPosition;
uniform float shininess;
varying vec3 surfacePosition;
varying vec3 surfaceNormal;
void main() {
vec3 eyeDirection = normalize(eyePosition - surfacePosition);
vec3 lightDirection = normalize(lightPosition - surfacePosition);
vec3 normal = normalize(surfaceNormal);
float power = blinnPhongSpec(lightDirection, viewDirection, normal, shininess);
gl_FragColor = vec4(power,power,power,1.0);
}
Install with npm:
npm install glsl-specular-phong
Then use with glslify.
#pragma glslify: phong = require(glsl-specular-phong)
Computes the specular power in the Phong lighting model.
lightDir
is a unit lengthvec3
pointing from the surface point toward the lighteyeDir
is a unit lengthvec3
pointing from the surface point toward the cameranormal
is the surface normal at the sample pointshininess
is the exponent in the Phong equation
Returns A float
representing the specular power
(c) 2014 Mikola Lysenko. MIT License