Presentation on theme: "Michael I. Gold NVIDIA Corporation"— Presentation transcript:
1 Michael I. Gold NVIDIA Corporation Emboss Bump MappingMichael I. GoldNVIDIA Corporation
2 Bump Mapping Real bump mapping uses per-pixel lighting Lighting calculation at each pixel based on perturbed normal vectorsComputationally expensiveFor 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 componentUnder-sampling artifactsPossible on today’s consumer hardwareIf it looks good, do it!
4 Diffuse Lighting Calculation C = (L•N) Dl DmL is light vectorN is normal vectorDl is light diffuse colorDm is material diffuse colorBump mapping changes N per pixelEmboss bump mapping approximates (L•N)
5 Approximate diffuse factor L•N Texture map represent height field[0,1] height represents range of bump functionFirst derivative represents slope mm increases/decreases base diffuse factor Fd(Fd+m) approximates (L•N) per pixel
6 Approximate derivative Embossing approximates derivativeLookup 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 H1difference represents instantaneous slope m=H1-H0
7 Compute the Bump Original bump (H0) Original bump (H0) overlaid with second bump (H1) perturbedtoward light sourcebrightens imagedarkens imageSubtract original bumpfrom second (H1-H0)
8 Compute the Lighting Evaluate fragment color Cf Cf = (L•N) Dl Dm (L•N) (Fd + (H1-H0))Dm Dl encoded in surface texture color CtCould control Dl seperately if you’re cleverCf = (Fd + (H1-H0)) Ct
9 Is that all? Its so easy! We’re not quite done yet. We still must Build a textureCalculate texture coordinate offsets s, tCalculate diffuse factor FdBoth are derived from normal N and light vector LNow we have to do some math
10 Building a Texture Conserve Textures! Current multitexture hardware only supports two texturesBump map in ALPHA channelMaximum bump = 1.0Level ground = 0.5Maximum depression = 0.0Surface color in RGB channelsSet internalformat to RGBA8 !!
11 Calculate Texture Offsets Rotate light vector into normal spaceNeed Normal coordinate systemDerive coordinate system from normal and “up” vectorNormal is z-axisCross product is x-axisThrow away up vector, derive y-axis as cross product of x- and z-axesBuild 3x3 matrix from axesTransform light vector into Normal space
12 Calc Texture Offsets (cont’d) Use normal-space light vector for offsetsL’ = Mn LUse L’x, L’y for s, tUse L’z for diffuse factor!If light vector is near normal, L’x, L’y are smallIf light vector is near tangent plane, L’x and L’y are largeWhat is L’z is less than zero?Light is on opposite side from normalFade contribution toward zero
13 Implementation on TNT Calculate vectors, texcoords on the host Pass diffuse factor as vertex alphaCould use vertex color for light diffuse colorH0 and surface color from texture unit 0H1 from texture unit 1 (same texture, different coordinates)ARB_multitexture extensionCombiners extension (TBD)
14 Implementation on TNT (cont’d) Combiner 0 alpha setup:(1-T0a) + T1a - 0.5T1a-T0a maps to [-1,1] but hardware clamps to [0,1]0.5 bias balances the loss from clampingCould modulate light diffuse color with T0cCombiner 1 rgb setup(T0c*C0a + T0c*Fda - 0.5) * 2scale by 2 brightens the image