2 // Fragment shader for procedural bumps
4 // Authors: John Kessenich, Randi Rost
6 // Copyright (c) 2002-2006 3Dlabs Inc. Ltd.
8 // See 3Dlabs-License.txt for license information
11 varying vec3 LightDir;
14 uniform vec3 SurfaceColor; // = (0.7, 0.6, 0.18)
15 uniform float BumpDensity; // = 16.0
16 uniform float BumpSize; // = 0.15
17 uniform float SpecularFactor; // = 0.5
22 vec2 c = BumpDensity * gl_TexCoord[0].st;
23 vec2 p = fract(c) - vec2(0.5);
26 d = p.x * p.x + p.y * p.y;
27 f = 1.0 / sqrt(d + 1.0);
30 { p = vec2(0.0); f = 1.0; }
32 vec3 normDelta = vec3(p.x, p.y, 1.0) * f;
33 litColor = SurfaceColor * max(dot(normDelta, LightDir), 0.0);
34 vec3 reflectDir = reflect(LightDir, normDelta);
36 float spec = max(dot(EyeDir, reflectDir), 0.0);
37 spec *= SpecularFactor;
38 litColor = min(litColor + spec, vec3(1.0));
40 gl_FragColor = vec4(litColor, 1.0);