// GL Shading Language version 1.0 Fragment Shader // Orion Sky Lawlor, olawlor@acm.org, 2006/08/31 (Public Domain) // Computes normal lighting, and modulates texture by wood pattern. // Vertex/fragment shader interface varying vec4 color; // Material diffuse color varying vec3 position; // World-space coordinates of object varying vec3 normal; // Surface normal varying vec3 cameraDir; // Points toward camera varying vec2 texCoord; // Texture coordinates uniform vec4 lightDir; // Points toward light uniform sampler2D bump, refl; // Textures: bumpmap and diffuse reflectance // Input: from vertex.txt. Output: gl_FragColor. void main(void) { vec3 N=normalize(vec3(texture2D(bump,texCoord))-vec3(0.5)); // Points away from surface vec3 L1=normalize(vec3(lightDir)); // Points toward light vec3 H=normalize(normalize(cameraDir)+L1); gl_FragColor=pow(clamp(dot(N,H),0.0,1.0),1000.0) +vec4(vec3( +0.6*clamp(dot(N,L1),0.0,1.0) // diffuse +0.05 // ambient ),1.0) *texture2D(refl,texCoord); // Scale diffuse+ambient by texture }