370 likes | 558 Views
Hardware Accelerated Anisotropic Lighting. Mark J. Kilgard NVIDIA Corporation. Credit for this Idea. Wolfgang Heirdrich and Hans-Peter Seidel (University of Erlangen, Germany)
E N D
Hardware Accelerated Anisotropic Lighting Mark J. Kilgard NVIDIA Corporation
Credit for this Idea • Wolfgang Heirdrich and Hans-Peter Seidel (University of Erlangen, Germany) • They were inspired by an technique developed by Malte Zöckler, Detlev Stalling, and Hans-Christian Hege (Konrad-Zuse-Zentrum für Informationstechnick in Berlin) • Scientific visualization technique that morphed into realistic rendering trick
Anisotropic Surfaces • What do these surfaces have in common? • Satin cloth • Christmas tree balls (the ornaments covered in threads) • Compact Discs • Brushed metal • Hair • Answer: they all exhibit anisotropic lighting characteristics
“Normal” Surfaces • Traditional lighting models consider 3D surfaces as being locally flat • The normal vector at a point on the surface is orthogonal to the flatness • Implicitly assumes surface tangents are uniformly distributed (isotropic distribution) • Effects such as bump mapping may perturb the surface normals, but substructure of the surface still modeled as locally flat
Some surfaces have a grain • Woven satin cloth has an inherent grain (locally, favors a particular surface tangent orientation) • As does brushed metal • As does hair • As do the groves on a record or CD • As do satin fibers on Xmas tree ornament • Accounts for unique visual appearance!
What creates anisotropy? • Key to anisotropic surfaces:distribution of surface normals along thesurface scratches or fibers is different from the distribution across them • A relatively distant observer sees the lighting result, but not the microstructure
Specular Highlight on Sphere Normal specular highlight looks like a “spot”
Anisotropic Sphere Consider satin thread Christmas tree ornament Specular highlight looks like a halo!
Visualize Sphere’s Grain Satin threads run from pole to pole Similar to pattern of hair on human head!
Different Lighting Effect Change the grain to lines of latitude... …changes the lighting appearance!
A Record or LP Grooves capture the light
Standard Local Lighting Model • Intensity at a surface point: Iout = Iambient + Idiffuse + IspecularwhereIambient = ka IaIdiffuse = Kd < L·N > IinIspecular = Ks pow(< V·R >, n) Iin
Symbol Cheat Sheet Iin -- incoming intensity from a lightKa -- ambient materialKd -- diffuse materialKs -- specular material
Symbol Cheat Sheet (2) < L·N > -- dot product of (normalized) light vector and surface normal vector < V·R > -- dot product of (normalized) view vector and reflection vectorpow(x, y) -- x raised to yth powern -- material shininess
Lighting a Fiber • How would you light a thread or hair? • There is no traditional surface normal! • Logically, each point on the thread has an infinite “circle” of normals perpendicular to the tangent at the point.
Normals for a Fiber Side view: possible normals tangent at a point Head on view: infinite circle of possible normals tangent sticks out of page!
Normals, Normals Everywhere! • Too many normals to pick from! • Which normal should be used for lighting? • Ideally, integrate the contribution of all normals. • To hard, so just pick the most significant normal and use it. • (Most significant normal’s contribution still will be less than full contribution.)
Most Significant Normal • Pick the normal that is co-planar with the light vector and view vector. • This vector will maximize the lighting dot products (i.e., it’s the most significant vector).
Math is Cool • Without determining the most significant normal (N) explicitly, the < L·N > and< V·R > dot products can be expressed in terms of L, T, and V. • Reminders: L -- vector to light for point on thread T -- tangent vector for point on thread V -- vector to viewer for point on thread
The Cool Math • < L·N > = sqrt( 1 - (< L ·T >) 2) • < V·R > = sqrt( 1 - (< L ·T >) 2) sqrt( 1 - (< V ·T >) 2) - < L ·T > < V ·T > • Cool observation:< L·N > and < V·R > can be determined by a bivariate function of< L ·T > and < V ·T >
Wish Hardware Could... • Compute the two dot products < L ·T > and < V ·T > • (Note: assume constant viewer and directional light so V and L vectors are constant, but T can vary per-vertex) • Then compute an arbitrary function based on the two dot productsWould you believe OpenGL does this!
OpenGL supports this! • OpenGL 4x4 texture matrix computes 4 dot products (we only need two). • Treat texture matrix rows as constant vectors. • Consider the texture coordinate to be the tangent vector (varying at vertices) • OpenGL also supports arbitrary bivariate functions, usually referred to as 2D texture maps! • Note that the output of the texture matrix is the input to our bivariate function!
Setting up the Texture Matrix Lx Ly Lz 1 Vx Vy Vz 1 0 0 0 0 0 0 0 2 Tx Ty Tz 1 1/2(< L ·T > ) +1 1/2(< V ·T > ) +1 0 1 = 1/2 • Rows contains L and V vectors • Also scale & bias from [-1, 1] dot product space to [0, 1] texture space
And pre-compute a 2D texture • Texture acts as 2D table to computeIout = Iambient + Idiffuse + Ispecular= Ka Ia + Kd < L·N > Iin + Ks pow(< V·R >, n) Iin • Varying parameters are in above equation are < L·N > and < V·R > (I.e, bivariate)
Brightness • It may be desirable to raise the diffuse and specular terms to a small power (between 2 or 4) to account for the fact that the most-significant normal does not account for the entire lighting of the anisotropic surface
Example 2D Texture < V ·R > axis < L ·N > axis
Anisotropic Rendering • When rendering anisotropic surfaces • Setup and enable 2D texture that encodes lighting model as a function of < L·N > and < V·R > • Setup texture matrix as described • Pass per-vertex tangent vector of surface or fiber as texture coordinate using glTexCoord3f(Tx,Ty,Tz) • Result: anisotropic lighting!
Caveats • If tangent vectors need to be transformed to eye space, concatenate inverse transpose of modelview matrix into texture matrix with glMultMatrix • Send only unit length tangent vectors (there is no equivalent to glEnable(GL_NORMALIZE) to unit-ize your tangent vectors texture coordinates) • Per-vertex lighting artifacts apply
Self-shadowing • Anisotropic light model does not account for self-shadowing due to back faces (lighting fibers do not have this issue) • Standard OpenGL lighting models self-shadowing by clamping negative lighting dot products to zero • By enabling and modulated with a extremely saturated OpenGL light source, self-shadowing can be supported • This requires sending normals
Self-shadowing Example Back-side not self-shadowed (bad, too bright) Backside self-shadowed(good)
Multiple Lights Sources • As described, each light requires a distinct 2D texture and texture matrix • Multiple passes with additive blending can simulate multiple light sources • ARB_multitexture with an additive texture environment can also support multiple lights • Also, a 3D texture could be used to handle two lights (would require a big texture)
Modeling Anisotropic Surfaces • Unfortunately, few 3D modelers have support for assigning anisotropic tangent vector distributions • Can be assigned implicitly for common shapes like disks and spheres
References • Heidrich and Seidel “Efficient Rendering of Anisotropic Surfaces Using Computer Graphics Hardware,” http://www9.informatik.uni-erlangen.de/eng/research/rendering/anisotropic/ • Zöckler, Stalling, and Hege, “Interactive Visualization of 3D-Vector Fields Using Illuminated Stream Lines,” Proceedings of Visualization ‘96, pp. 107-113. http://www.zib.de/stalling/isl.html • David Banks, “Illumination in Diverse Codimensions,” SIGGRAPH ‘94 Proceedings, pp. 327-334.
3D Vector Field Visualization by Zöckler, Stalling, and Hege Electrostatic field of a benzene molecule
Conclusions • Unconventional light models that incorporate anisotropic lighting effects can be hardware accelerated by OpenGL • A large class of objects with interesting visual properties can be rendered in real-time • Games that incorporate anisotropic lighting effects have opportunity to stand out from the crowd!