Presentation on theme: "1 Emboss Bump Mapping Michael I. Gold NVIDIA Corporation."— Presentation transcript:
1 Emboss Bump Mapping Michael I. Gold NVIDIA Corporation
2 Bump Mapping Real bump mapping uses per-pixel lighting Lighting calculation at each pixel based on perturbed normal vectors Computationally expensive For more information see: Blinn, J. Simulation of Wrinkled Surfaces. Computer Graphics. 12, 3 (August 1978),
3 Emboss Bump Mapping Emboss bump mapping is a hack Diffuse lighting only, no specular component Under-sampling artifacts Possible on today’s consumer hardware If it looks good, do it!
4 Diffuse Lighting Calculation C = (LN) Dl Dm L is light vector N is normal vector Dl is light diffuse color Dm is material diffuse color Bump mapping changes N per pixel Emboss bump mapping approximates (LN)
5 Approximate diffuse factor LN Texture map represent height field [0,1] height represents range of bump function First derivative represents slope m m increases/decreases base diffuse factor Fd (Fd+m) approximates (LN) per pixel
6 Approximate derivative Embossing approximates derivative Lookup height H0 at point (s,t) Lookup height H1 at point slightly perturbed toward light source (s+ s, t+ t) subtract original height H0 from perturbed height H1 difference represents instantaneous slope m=H1-H0
7 Compute the Bump Original bump (H0) overlaid with second bump (H1) perturbed toward light source Original bump (H0) Subtract original bump from second (H1-H0) brightens image darkens image
8 Compute the Lighting Evaluate fragment color Cf Cf = (LN) Dl Dm (LN) (Fd + (H1-H0)) Dm Dl encoded in surface texture color Ct –Could control Dl seperately if you’re clever Cf = (Fd + (H1-H0)) Ct
9 Is that all? Its so easy! We’re not quite done yet. We still must Build a texture Calculate texture coordinate offsets s, t Calculate diffuse factor Fd Both are derived from normal N and light vector L Now we have to do some math
10 Building a Texture Conserve Textures! Current multitexture hardware only supports two textures Bump map in ALPHA channel –Maximum bump = 1.0 –Level ground = 0.5 –Maximum depression = 0.0 Surface color in RGB channels Set internalformat to RGBA8 !!
11 Calculate Texture Offsets Rotate light vector into normal space Need Normal coordinate system Derive coordinate system from normal and “up” vector –Normal is z-axis –Cross product is x-axis –Throw away up vector, derive y-axis as cross product of x- and z-axes Build 3x3 matrix from axes Transform light vector into Normal space
12 Calc Texture Offsets (cont’d) Use normal-space light vector for offsets L’ = Mn L Use L’x, L’y for s, t Use L’z for diffuse factor! –If light vector is near normal, L’x, L’y are small –If light vector is near tangent plane, L’x and L’y are large What is L’z is less than zero? –Light is on opposite side from normal –Fade contribution toward zero
13 Implementation on TNT Calculate vectors, texcoords on the host Pass diffuse factor as vertex alpha –Could use vertex color for light diffuse color H0 and surface color from texture unit 0 H1 from texture unit 1 (same texture, different coordinates) ARB_multitexture extension Combiners extension (TBD)
14 Implementation on TNT (cont’d) Combiner 0 alpha setup: (1-T0a) + T1a –T1a-T0a maps to [-1,1] but hardware clamps to [0,1] –0.5 bias balances the loss from clamping Could modulate light diffuse color with T0c Combiner 1 rgb setup (T0c*C0a + T0c*Fda - 0.5) * 2 –0.5 bias balances the loss from clamping –scale by 2 brightens the image