diff options
author | Brian Paul <brianp@vmware.com> | 2009-12-03 09:49:27 -0700 |
---|---|---|
committer | Brian Paul <brianp@vmware.com> | 2009-12-07 07:46:02 -0700 |
commit | 8796dbf5196bcc75d39372570fa6347cd018354d (patch) | |
tree | 5079388e70609115a68b039c82871969f0fe5b1b /progs/glsl/CH11-bumpmaptex.frag | |
parent | 12981589b729de0242d6ea74d8e4e9889793088c (diff) |
progs/glsl: added texture mapping to bump demo
Press 't' to toggle texture map.
Diffstat (limited to 'progs/glsl/CH11-bumpmaptex.frag')
-rw-r--r-- | progs/glsl/CH11-bumpmaptex.frag | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/progs/glsl/CH11-bumpmaptex.frag b/progs/glsl/CH11-bumpmaptex.frag new file mode 100644 index 0000000000..b1f93b784d --- /dev/null +++ b/progs/glsl/CH11-bumpmaptex.frag @@ -0,0 +1,47 @@ +// +// Fragment shader for procedural bumps +// +// Authors: John Kessenich, Randi Rost +// +// Copyright (c) 2002-2006 3Dlabs Inc. Ltd. +// +// See 3Dlabs-License.txt for license information +// +// Texture mapping/modulation added by Brian Paul +// + +varying vec3 LightDir; +varying vec3 EyeDir; + +uniform float BumpDensity; // = 16.0 +uniform float BumpSize; // = 0.15 +uniform float SpecularFactor; // = 0.5 + +sampler2D Tex; + +void main() +{ + vec3 ambient = vec3(0.25); + vec3 litColor; + vec2 c = BumpDensity * gl_TexCoord[0].st; + vec2 p = fract(c) - vec2(0.5); + + float d, f; + d = p.x * p.x + p.y * p.y; + f = inversesqrt(d + 1.0); + + if (d >= BumpSize) + { p = vec2(0.0); f = 1.0; } + + vec3 SurfaceColor = texture2D(Tex, gl_TexCoord[0].st).xyz; + + vec3 normDelta = vec3(p.x, p.y, 1.0) * f; + litColor = SurfaceColor * (ambient + max(dot(normDelta, LightDir), 0.0)); + vec3 reflectDir = reflect(LightDir, normDelta); + + float spec = max(dot(EyeDir, reflectDir), 0.0); + spec *= SpecularFactor; + litColor = min(litColor + spec, vec3(1.0)); + + gl_FragColor = vec4(litColor, 1.0); +} |