09.01.2015 Views

How to Bump Map a Skinned Polygonal Model - NVIDIA Developer ...

How to Bump Map a Skinned Polygonal Model - NVIDIA Developer ...

How to Bump Map a Skinned Polygonal Model - NVIDIA Developer ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Stanford Shading Group<br />

presentation<br />

<strong>How</strong> <strong>to</strong> <strong>Bump</strong> <strong>Map</strong> a<br />

<strong>Skinned</strong> <strong>Polygonal</strong> <strong>Model</strong><br />

May 8, 2000 (updated)


Mark J. Kilgard<br />

Graphics Software Engineer<br />

<strong>NVIDIA</strong> Corporation


Real <strong>Bump</strong> <strong>Map</strong>ping is<br />

Practical and Robust Today<br />

<strong>NVIDIA</strong> GPU bump mapping is fast and good<br />

• Better than “pseudo” bump mapping techniques such as<br />

embossing and DX6 <strong>Bump</strong>Env<br />

• See whitepaper “A Practical and Robust <strong>Bump</strong>-mapping<br />

mapping<br />

Technique for Today’s GPUs”<br />

– in Advanced OpenGL Game Development course notes<br />

– On <strong>NVIDIA</strong>’s web site, www.nvidia.com/<strong>Developer</strong><br />

• I fully expect other hardware vendors <strong>to</strong> expose similar<br />

techniques based on the same basic math


The <strong>NVIDIA</strong> GPU <strong>Bump</strong><br />

<strong>Map</strong>ping Technique<br />

Technique Details<br />

• Requires <strong>NVIDIA</strong> GPU features of GeForce/Quadro<br />

– NV_register_combiners<br />

– EXT_texture_cube_map<br />

– ARB_multitexture<br />

• Tangent space formulation<br />

• Ambient, diffuse, and specular contributions<br />

• Robust filtering, self-shadowing, shadowing, local viewer and light<br />

• Three passes for full effect with texture decal


The “bumpdemo”<br />

Torus Example<br />

A nice shiny bump mapped <strong>to</strong>rus


Ana<strong>to</strong>my of the technique<br />

Three passes (or just two if no specular)<br />

× +<br />

diffuse<br />

decal<br />

specular


The Big Issue<br />

Can I bump map more than a <strong>to</strong>rus<br />

• The <strong>to</strong>rus has the advantage of having a nice parametric<br />

representation for orienting tangent space<br />

– partial derivatives in terms of parametric variables exist<br />

• Games tend <strong>to</strong> use ad hoc polygonal models<br />

– no explicit parametric basis available<br />

– but game models do have textured decal “skins”<br />

– Insight: infer an ad hoc tangent space from the model’s<br />

mapping between vertices and skin texture coordinates!


<strong>Skinned</strong> <strong>Polygonal</strong><br />

<strong>Model</strong>s<br />

Example: Quake 2 models in the “.md2” format<br />

• Decal skin texture, typically 128x128 linear filtered<br />

• Shared vertex list<br />

– each vertex has (s,t) texture coordinate in<strong>to</strong> the skin<br />

• A set of key frames<br />

– each triangle is three vertex indices<br />

– each frame vertex is (x,y,z) and a quantized normal<br />

• Low polygon count, usually 400-800 polygons per model


Quake 2 <strong>Model</strong>s<br />

Piece by Piece<br />

<strong>Model</strong> Key Frames<br />

Quake 2 interpolates between key frames


Quake 2 <strong>Model</strong>s<br />

Piece by Piece<br />

Knight model’s decal skin<br />

Texture coordinates map<br />

triangles <strong>to</strong> skin.<br />

Note clever packing of<br />

decal skin. Only half<br />

face because triangles<br />

“mirror” the face.


Standard Quake 2<br />

<strong>Model</strong> Rendering<br />

Texture key-frame with decal skin<br />

+<br />

Key-frame<br />

model<br />

geometry<br />

Decal<br />

skin<br />

Result


GPU <strong>Bump</strong>-mapped<br />

Quake 2 <strong>Model</strong> Rendering!<br />

<strong>Bump</strong>-map map model with bump, gloss, & decal skin<br />

<strong>Bump</strong><br />

skin<br />

+<br />

Key-frame<br />

model<br />

geometry<br />

Decal<br />

skin<br />

Gloss<br />

skin<br />

WOW!<br />

Result


Quake 2 <strong>Bump</strong> <strong>Map</strong>ping<br />

Rendering Passes<br />

× ) + (<br />

×<br />

( ) + (<br />

) =<br />

Diffuse<br />

Decal<br />

Specular<br />

Gloss<br />

Final result!


More <strong>Bump</strong>-mapped<br />

Knight Examples<br />

Different light positions and key-frames<br />

All lighting including specular is computed per-fragment!


<strong>Bump</strong> <strong>Map</strong>ping<br />

<strong>Model</strong>s<br />

Viva la difference


What is tangent space<br />

Very important concept<br />

• It is a coordinate space that varies over a rendered object<br />

• Assumes the (unperturbed) surface normal is always (0, 0, 1)<br />

– but that’s not enough <strong>to</strong> define a coordinate system<br />

– needs a tangent vec<strong>to</strong>r in the plane of the surface <strong>to</strong> orient<br />

the coordinate system<br />

• Tangent space is very convenient for lighting with a<br />

perturbed normal<br />

– very good for bump mapping


More about tangent space<br />

Normals, tangents, and binormals<br />

• Say the surface is defined by a bivariate vec<strong>to</strong>r parametric<br />

equation, (x, y, z) = F(u, v)<br />

• The tangent is the normalized vec<strong>to</strong>r (∂x/(<br />

∂u,<br />

u, ∂y/<br />

y/ ∂u,<br />

u, ∂z/<br />

z/ ∂u)<br />

u)<br />

• The normal is the cross product of the tangent vec<strong>to</strong>r and the<br />

normalized vec<strong>to</strong>r (∂x/<br />

∂v,<br />

v, ∂y/<br />

y/ ∂v,<br />

v, ∂z/<br />

z/ ∂v)<br />

v)<br />

• The binormal is the cross product of the tangent and normal<br />

• The tangent, binormal, and normal form an orthonormal basis<br />

– in English, that’s s a coordinate system


Parametric Approach<br />

<strong>to</strong> Tangent Space<br />

Forming tangent space<br />

• It is easy with an explicit parametric representation<br />

– such as a <strong>to</strong>rus<br />

• Just compute the vec<strong>to</strong>rs from the previous slide from the<br />

parametric representation<br />

• To be practical, we just compute a tangent space basis at<br />

vertices<br />

– assumes reasonable tessellation around curvature


Tangent Space Basis<br />

is a Gateway for Vec<strong>to</strong>rs<br />

Object-space vec<strong>to</strong>r <strong>to</strong> tangent-space<br />

Ltx Lty Ltz =<br />

Lox Loy Loz<br />

Tx<br />

Bx<br />

Nx<br />

Ty<br />

By<br />

Ny<br />

Tz<br />

Bz<br />

Nz<br />

<strong>How</strong> <strong>to</strong> transform a light vec<strong>to</strong>r in<br />

object space <strong>to</strong> tangent space


<strong>Skinned</strong> <strong>Polygonal</strong> <strong>Model</strong>s<br />

Each vertex consists of<br />

• (x, y, z) object-space position<br />

• corresponding (s, t) on the skin texture<br />

• And each triangle in the model has three such vertices<br />

Insight!<br />

• Per polygon, compute the following plane equations<br />

–AA 0 x + B 0 s + C 0 t + D 0 = 0<br />

–AA 1 y + B 1 s + C 1 t + D 1 = 0<br />

–AA 2 z + B 2 s + C 2 t + D 2 = 0


Compute Partial Derivatives<br />

form Polygon Plane Equations<br />

Make a per-polygon polygon tangent and binormal<br />

• tangent is normalization of (∂x/(<br />

∂s,<br />

s, ∂y/<br />

y/ ∂s,<br />

s, ∂z/<br />

z/ ∂s)<br />

s)<br />

– or normalization of ( -B 0 /A 0 , -B 1 /A 1 , -B 2 /A 1 )<br />

• binormal is normalization of (∂x/(<br />

∂t,<br />

t, ∂y/<br />

y/ ∂t,<br />

∂z/<br />

z/ ∂t)<br />

t)<br />

– or normalization of ( -C 0 /A 0 , -C 1 /A 1 , -C 2 /A 1 )<br />

• normal is the cross product of the tangent and binormal<br />

– important! you need <strong>to</strong> invert the sign if the area of the<br />

triangle in texture space is opposite of the area of the<br />

triangle in object space


Apply the GPU <strong>Bump</strong><br />

<strong>Map</strong> Technique<br />

The approach<br />

• Compute tangent space on a polygon-by-polygon basis<br />

• To match the per-vertex lighting on flat surface resize the<br />

normal, binormal, and tangent vec<strong>to</strong>rs <strong>to</strong> match the model’s<br />

per-vertex normal in tangent space<br />

• Use this 3x3 matrix <strong>to</strong> transform object-space light and half-<br />

angle vec<strong>to</strong>rs in<strong>to</strong> object space<br />

• Perform the GPU bump map technique


Painting the<br />

<strong>Bump</strong> Skin<br />

Example for the knight<br />

• Same <strong>to</strong>pology as decal skin, easy-<strong>to</strong>-author<br />

author<br />

<strong>Bump</strong> skin height-field<br />

Decal skin


Warning about<br />

Pre-lit Decal Skins<br />

Most Quake 2 decal skins are “pre-lit”<br />

• Skins for bump mapping should encode materials, not colors<br />

– because bump mapping supplies the per-pixel pixel lighting!<br />

– so eliminate pre-lighting from decal skins<br />

– otherwise, you get double lighting


Decal Skin<br />

Comparison<br />

Pre-lit skins versus non-pre-lit skins<br />

Original pre-lit knight<br />

decal skin<br />

Modified “un-lit” knight decal<br />

skin for bump mapping


Gloss <strong>Map</strong> Modulates<br />

Per-fragment Specular<br />

Alpha channel of decal hides “free” gloss map<br />

• Per-fragment modulation of specular pass<br />

• Used on knight <strong>to</strong> avoid shiny<br />

face, belt, and cloth<br />

• Same skin <strong>to</strong>pology as other maps<br />

Decal<br />

skin<br />

Gloss<br />

skin


Assumptions<br />

Things that should be approximately true<br />

• The normal and binormal are not guaranteed <strong>to</strong> be<br />

orthogonal<br />

– but hopefully will be close since artists would otherwise be<br />

working on con<strong>to</strong>rted skins (so ok assumption)<br />

• <strong>Model</strong> is reasonably tessellated, particularly in regions of<br />

high curvature change (usually ok assumption)<br />

• Good continuity of light and half-angle angle tangent-space vec<strong>to</strong>rs<br />

across polygons (poor assumption)


Tangent Space<br />

Vec<strong>to</strong>r Continuity<br />

Visualizing this assumption, not that good<br />

tangent space light vec<strong>to</strong>r<br />

tangent space half-angle angle vec<strong>to</strong>r


Worst-case Tangent<br />

Vec<strong>to</strong>r Discontinuities<br />

Change across polygons<br />

A<br />

B<br />

polygons in skin texture space<br />

A<br />

B<br />

polygons in object space<br />

arrows indicate increasing t texture coordinate


Tangent Continuity<br />

Solutions<br />

Reorient and repack all polygons in skin textures


<strong>Bump</strong>-mapped <strong>Skinned</strong><br />

<strong>Polygonal</strong> <strong>Model</strong>s<br />

More examples


Credits<br />

Where credit is due<br />

• Sim Dietrich and Doug Rogers invented the idea of creating<br />

an ad-hoc tangent space from skinned polygonal models<br />

• Cass Everitt developed the bump skin re-packing technique<br />

• Quake 2 .md2 models designed by<br />

– faerie model, Brian Collins<br />

– alien model, RichB<br />

– Boba Fett model, Dan Bickell<br />

– Perelith Knight model, James Green

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!