b0VIM 8.05WZ9P/angus17Anguss-MacBook-Pro.local~angus17/Dropbox/MAMP_htdocs/ccl_UCSC/courses/cmpm163/code/week1/w1_phongShader.htmlutf-8 3210#"! Utp[bn ad aq[VKB;:avPO0 p ' & p   i . ) f a \  f 1 ( '   QPcbaLK&T%p^$zLC color2 += spec2 * light2_specular; float spec2 = pow( max(dot(R2, V), 0.0), spec_intensity); vec3 R2 = normalize(reflect(-L2,N)); //specular vec3 color2 = diff2 * light2_diffuse; float diff2 = max(0.0, dot(N, L2)); //diffuse } outColor1 = clamp(vec4(color1,1.0), 0.0,1.0); } else { outColor1 = vec4(light1_specular,1.0); if (spec1 > 1.0) { color1 += spec1 * light1_specular; float spec1 = pow( max(dot(R1, V), 0.0), spec_intensity); //raising the value to a particular intensity value shrinks the size of the specular highlight so that only a reflection vector (R1) that is very close to the view vector (V) will be applied to this fragment. vec3 R1 = normalize(reflect(-L1,N)); //get light vector reflected across the plane defined by the normal of this geometry //specular highlights depend upon the position/orientation of the camera and the direction of the light reflecting off of this geometry vec3 color1 = diff1 * light1_diffuse; float diff1 = max(0.0, dot(N, L1)); //just to make sure not negative //diffuse light depends on the angle between the light and the vertex normal vec4 outColor2 = vec4(0.0); vec4 outColor1 = vec4(0.0); void main() { uniform vec3 light2_specular; uniform vec3 light1_specular; uniform vec3 light2_diffuse; uniform vec3 light1_diffuse; uniform vec3 ambient; //general ambient light in the scene applied to all objects float spec_intensity = 32.0; //higher value indicates more rapid falloff varying vec3 V, N, L1, L2; precision mediump float; } gl_Position = projectionMatrix * position; //of course, we always have to output our vertices in clip coords by multiplying through a projection matrix. V = normalize(-P); //reverse direction of position vector to get view vector from vertex to camera L2 = vec3(normalize(L2_cam - position).xyz); L1 = vec3(normalize(L1_cam - position).xyz); //get the normalized vectors from each light position to the vertex positions vec4 L2_cam = viewMatrix * vec4(light2_pos, 1.0); vec4 L1_cam = viewMatrix * vec4(light1_pos, 1.0); //the lights positions are defined in WORLD coordinates, we want to put them in CAMERA coordinates too N = vec3(normalize(viewMatrix * modelMatrix * vec4(normal.xyz, 0.0) ).xyz) ; //get the normalized vertex normal in CAMERA coordinates vec3 P = position.xyz; //use xyz vals to calculate vectors between vertex, light, and camera vec4 position = viewMatrix * modelMatrix * vec4(position, 1.0); //get the vertex position in CAMERA coordinates void main() { varying vec3 N, L1, L2, V; uniform vec3 light2_pos; uniform vec3 light1_pos; attribute vec3 normal; attribute vec3 position; uniform ma //Three.js gives us these automatically when a perspective camera is bound to the renderer
} overflow: hidden; margin: 0px; body {