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
10 // Texture mapping/modulation added by Brian Paul
13 varying vec3 LightDir;
16 uniform float BumpDensity; // = 16.0
17 uniform float BumpSize; // = 0.15
18 uniform float SpecularFactor; // = 0.5
20 uniform sampler2D Tex;
24 vec3 ambient = vec3(0.25);
26 vec2 c = BumpDensity * gl_TexCoord[0].st;
27 vec2 p = fract(c) - vec2(0.5);
30 d = p.x * p.x + p.y * p.y;
31 f = inversesqrt(d + 1.0);
34 { p = vec2(0.0); f = 1.0; }
36 vec3 SurfaceColor = texture2D(Tex, gl_TexCoord[0].st).xyz;
38 vec3 normDelta = vec3(p.x, p.y, 1.0) * f;
39 litColor = SurfaceColor * (ambient + max(dot(normDelta, LightDir), 0.0));
40 vec3 reflectDir = reflect(LightDir, normDelta);
42 float spec = max(dot(EyeDir, reflectDir), 0.0);
43 spec *= SpecularFactor;
44 litColor = min(litColor + spec, vec3(1.0));
46 gl_FragColor = vec4(litColor, 1.0);