1// 2// Fragment shader for procedural bumps 3// 4// Authors: John Kessenich, Randi Rost 5// 6// Copyright (c) 2002-2006 3Dlabs Inc. Ltd. 7// 8// See 3Dlabs-License.txt for license information 9// 10 11varying vec3 LightDir; 12varying vec3 EyeDir; 13 14uniform vec3 SurfaceColor; // = (0.7, 0.6, 0.18) 15uniform float BumpDensity; // = 16.0 16uniform float BumpSize; // = 0.15 17uniform float SpecularFactor; // = 0.5 18 19void main() 20{ 21 vec3 litColor; 22 vec2 c = BumpDensity * gl_TexCoord[0].st; 23 vec2 p = fract(c) - vec2(0.5); 24 25 float d, f; 26 d = p.x * p.x + p.y * p.y; 27 f = inversesqrt(d + 1.0); 28 29 if (d >= BumpSize) 30 { p = vec2(0.0); f = 1.0; } 31 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); 35 36 float spec = max(dot(EyeDir, reflectDir), 0.0); 37 spec *= SpecularFactor; 38 litColor = min(litColor + spec, vec3(1.0)); 39 40 gl_FragColor = vec4(litColor, 1.0); 41} 42