<<

Normal Mapping and Spaces

University of Texas at Austin CS384G - Computer Graphics Don Fussell Maps

Like bump maps but normals already computed 3 elements per texel – x,y,z components of normal Defined in texture () space Must map to object space to use Problem: What vectors in object space correspond to the x,y, and z axes in texture space? Solution: Define two orthogonal vectors tangent to the surface and one normal to the surface Surface space can now be called

University of Texas at Austin CS384G - Computer Graphics Don Fussell 2 Mapping normal to surface Step 1: Find texture coordinate of surface Step 2: Look up texel at that coordinate Step 3: Find rotation that maps tangent space normal to object space normal for the given pixel Step 4: Rotate tangent space normal defined in the texel by this rotation to define the normal at the surface point z

n y=v b n'' z t n' x=u

Tangent space y (Texture map) Object space x

University of Texas at Austin CS384G - Computer Graphics Don Fussell 3 Axes in object space ϕ For in x = rsinθ cosϕ u = x = −rsinπvcos2πu 2π polar coordinates y = rsinθ sinϕ y = −rsinπvsin2πu π −θ z = r cosθ v = z = −r cosπv π ⎡ ⎤ ⎡ dx ⎤ dx ⎡ dx ⎤ ⎡ dx ⎤ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ − ⎥ ⎢ dϕ ⎥ ⎢ du ⎥ ⎡ −rsinθ sinϕ ⎤ ⎢ dv ⎥ ⎢ dθ ⎥ ⎡ −r cosθ cosϕ ⎤ ⎢ dy ⎥ ⎢ dy ⎥ ⎢ ⎥ ⎢ dy ⎥ ⎢ dy ⎥ ⎢ ⎥ t = ⎢ ⎥ = ⎢ ⎥ = ⎢ rsinθ cosϕ ⎥ b = ⎢ ⎥ = ⎢ − ⎥ = ⎢ −r cosθ sinϕ ⎥ du ⎢ dϕ ⎥ ⎢ ⎥ dv dθ ⎢ ⎥ 0 ⎢ ⎥ ⎢ ⎥ ⎢ rsinθ ⎥ ⎢ dz ⎥ ⎢ dz ⎥ ⎣ ⎦ ⎢ dz ⎥ ⎢ dz ⎥ ⎣ ⎦ ⎢ ⎥ − ⎢ du ⎥ ⎢ dv ⎥ ⎢ dθ ⎥ ⎣ ⎦ ⎣⎢ dϕ ⎦⎥ ⎣ ⎦ ⎣ ⎦

n = t × b need to normalize t, b, and n

University of Texas at Austin CS384G - Computer Graphics Don Fussell 4 Rotation – tangent and object space

Object space to tangent space For light vectors ⎡ t t t 0 ⎤ ⎢ x y z ⎥

⎢ bx by bz 0 ⎥ L' = ⎢ ⎥L ⎢ nx ny nz 0 ⎥ ⎢ ⎥ ⎣ 0 0 0 1 ⎦

Tangent space to object space

For normals ⎡ t b n 0 ⎤ ⎢ x x x ⎥ ⎢ ty by ny 0 ⎥ nʹʹ = ⎢ ⎥nʹ ⎢ tz bz nz 0 ⎥ ⎣⎢ 0 0 0 1 ⎦⎥ University of Texas at Austin CS384G - Computer Graphics Don Fussell 5 Messier for ()

Given a with vertices P0,P1,P2 and texture coordinates for those vertices We need to solve for t and b We already know how to get the triangle normal n

z

b n P1 (u1,v1) P2 (u2,v2) t P0 (u0,v0) y x Object space

University of Texas at Austin CS384G - Computer Graphics Don Fussell 6 Solving for t and b

V1 = P1 − P0 = (u1 − u0 )t + (v1 − v0 )b = Δu1t + Δv1b

V2 = P2 − P0 = (u2 − u0 )t + (v2 − v0 )b = Δu2t + Δv2b ⎡ ⎤ ⎡ ⎤⎡ ⎤ V1 Δu1 Δv1 t ⎢ ⎥ = ⎢ ⎥⎢ ⎥ V u v b ⎣⎢ 2 ⎦⎥ ⎣⎢ Δ 2 Δ 2 ⎦⎥⎣ ⎦ −1 ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ Δu1 Δv1 V1 t ⎢ ⎥ ⎢ ⎥ = ⎢ ⎥ u v V b ⎣⎢ Δ 2 Δ 2 ⎦⎥ ⎣⎢ 2 ⎦⎥ ⎣ ⎦ ⎡ ⎤⎡ ⎤ ⎡ ⎤ 1 Δv2 −Δv1 V1 t ⎢ ⎥⎢ ⎥ = ⎢ ⎥ u v u v u u V b Δ 1Δ 2 − Δ 2Δ 1 ⎣⎢ −Δ 2 Δ 1 ⎦⎥⎣⎢ 2 ⎦⎥ ⎣ ⎦

University of Texas at Austin CS384G - Computer Graphics Don Fussell 7 Why is it messy?

For smooth you average the and bitangents as well as normals of triangles sharing a to get different t, b and n at each vertex. The you interpolate these across the triangle. At each pixel, the t, b and n vectors you get are no longer orthogonal. So you have to fix them, e.g. using Gram-Schmidt orthogonalization, before you can make a rotation matrix from them.

University of Texas at Austin CS384G - Computer Graphics Don Fussell 8 Gram-Schmidt Orthogonalization

Start with n, make t’ orthogonal to it

-(t•n)n t' t tʹ = t − (t ⋅ n)n n

(t•n)n Normalize t’ Now make b orthogonal to both n and t’ bʹ = b − (b⋅ n)n − (b⋅ tʹ)tʹ Normalize b’

University of Texas at Austin CS384G - Computer Graphics Don Fussell 9