varying vec3 n, l, h; varying float i; #vertex void main() { vec4 pos; // normal vector, light direction, half vector n = normalize(gl_NormalMatrix * gl_Normal); l = normalize(vec3(gl_LightSource[0].position)); h = normalize(gl_LightSource[0].halfVector.xyz); // the rest gl_TexCoord[0] = gl_MultiTexCoord0 * 4.0; pos = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; i = 1.0 - 0.1 * pos.z; gl_Position = pos; } #fragment uniform sampler2D tex; void main() { float c, d, s; vec3 nn; // distortion texture lookup nn = vec3(texture2D(tex, vec2(3.0 * gl_TexCoord[0].s, 2.0 * gl_TexCoord[0].t))); nn -= vec3(0.5, 0.5, 0.5); // lighting nn = normalize(n + 0.3 * nn); d = dot(nn, l); if (d > 0.0) { s = pow(max(dot(nn, normalize(h)), 0.0), 30.0); d *= 0.75; } else { s = 0.0; d = 0.0; } // color assembly nn = vec3(0.150, 0.075, 0.031) // ambient + vec3(0.500, 0.421, 0.200) * d // diffuse + vec3(0.900, 0.900, 0.900) * s; // specular gl_FragColor = i * vec4(nn, 0.0); }