// GL Shading Language version 1.0 Fragment Shader // Orion Sky Lawlor, olawlor@acm.org, 2006/08/31 (Public Domain) // Vertex/fragment shader interface varying vec4 color; // Material diffuse color varying vec3 normal; // Surface normal // Input: from vertex.txt. Output: gl_FragColor. void main(void) { vec3 N=normalize(normal); vec3 L1=normalize(vec3(0,1,0)); /* +Y direction */ vec4 C1=vec4(1,1,1,1); /* white light */ vec4 diffuse1=C1*clamp(dot(N,L1),0.0,1.0); vec3 L2=normalize(vec3(1,0,0)); /* +X direction */ vec4 C2=vec4(1,0,0,1); /* red light */ vec4 diffuse2=C2*clamp(dot(N,L2),0.0,1.0); gl_FragColor=diffuse1+diffuse2; /* total color is sum of light sources */ gl_FragColor.a=1.0; /* Force object to be opaque */ }