/
Cass Everitt Cass Everitt

Cass Everitt - PDF document

tawny-fly
tawny-fly . @tawny-fly
Follow
393 views
Uploaded On 2016-07-10

Cass Everitt - PPT Presentation

2 Why PerPixel LightingReviewOpenGL Transforms and SpacesOpenGL Pervertex LightingPervertex LightingSurfacelocal SpaceOther namesWhy is this necessarySurfacelocal SpacePerVertex LightingIn oth ID: 398016

2 Why Per-Pixel Lighting?ReviewOpenGL Transforms and

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "Cass Everitt" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Cass Everitt 2 Why Per-Pixel Lighting?ReviewOpenGL Transforms and SpacesOpenGL Per-vertex LightingPer-vertex LightingSurface-local SpaceOther namesWhy is this necessary?Surface-local SpacePer-Vertex LightingIn other spaces? 3 Because it’s hardware acceleratedBecause everyone else is doing it Don’t be the last on your block 4 You get total control, but this means youglShadeModel(GL_PHONG)glEnable(GL_BUMP_MAPPING)If you don’t know how to implement per-vertex lighting, learn how to do that firstPer-pixel shading is an extension of per-vertex shading (for the most part) 5 OpenGL TransformationsOpenGL operation transforms coordinates through several spacesEach of the spaceshas various properties that make it useful Vertex attributes are specified Lighting, eye-linear texgen, and fog happen in Clipping happens after projection in Rasterization happens in MODELVIEW matrix object space eye space PROJECTION matrix clip space Perspective Divide normalized device coordinates viewport/depthrange scale & bias window space 6 world space is not an explicit space in OpenGL 7 eye space x-x-zz 8 Object Space Object Space For -zObject Space For -z Each object has its own origin, orientation, and scale 9 OpenGL Per-Vertex Lightingeye spaceNot essential, but convenient 10 Lighting in eye space x-x-zz 11 Lighting in eye space(2) nllEE hThe vectors… 12 into Normals are not simply transformed by the modelview matrix like positionYou may know from the Red Book or various normals are transformed by the inverse-transpose of the modelview matrixbut let’s consider why…The following slides should help provide some intuition about the transforming of normals 13 of position does not affect normals -z x -z 14 just like it is to position -z x -z 15 Uniform scalingdirection of -z x -z Note that we are considering how the directionnormalis affected by transforming the position 16 direction of Opposite of the way position is affected –or the inverse of the scaling matrix that’s applied to position x -z x -z Note that we are considering how the directionnormalis affected by transforming the position 17 To summarize, these are the basic position transformations and the corresponding normal positionnormal Note that any sort of scaling applies inversely to the normal –we treat all scales (uniform and non-uniform) the sameThis is why we need GL_NORMALIZE and GL_RESCALE_NORMAL for OpenGL lightingWe have to deal with it in per-pixel lighting as well 18 How does this match what OpenGL does?For simplicity, consider , the modelview matrix, is composed of a scale and a rotationis distributiveFor rotation (orthonormal) matrices , andFor scaling (diagonal) matrices This matches our 19 Object SpaceNothing in the lighting equation requires -consider lighting in Non-uniform scaling in the modeling matrix would complicate things, so we will ignore that for now…If the modeling matrix is simply a rigid body Need to transform the light into object space from eye No need to transform each normal now (cheaper) 20 object space -x-zz 21 object space -x-zz 22 object space nnllEE hThe vectors… Note that the dot products are the same whether the vectors are in eye space all vectors are in the same space 23 Surface-local SpaceThis gets called a lot of things… surface-local spacesurface-local spaceis a class of spaces defined for every point on a surfaceand surface-local spacesthat give specific definitions to the basis vectorsConsider one additional transform surface-local space MODELVIEW matrix object space eye space PROJECTION matrix clip space Perspective Divide normalized device coordinates viewport/depthrange scale & bias window space surface-local matrix surface-local space 24 Surface-local Spacesurface-local spacewe use are every pointNote that for per-pixel lighting the geometric surface normal is generally what we use in the lighting The x and y axes are orthogonal and in the Now the entire scene can be defined relative to any point on any surface in the scene –not just relative to any object 25 surface-local space x-x-zz nlEE h 26 surface-local space 27 If we specified vertices in surface-local space, they’d glNormal3f(0,0,1); glVertex3f(0,0,0);, would provide the object space orientation, and it would vary per-vertex:--tangent vector--binormal vector--object space vertex normal--object space vertex position 28 surface-local As with lighting in local space is a perfectly valid coordinate frame to We simply transform the light and eye into surface-local space –the normal is known by definition, so Compare surface-local space lighting: the light vector or eye vector are “free”, but you must transform each normal into lighting: the normal is free, but you must transform the light and eye vectors into 29 Getting back to the original point…We really want to evaluate the lighting equation Rather than passing in normals per-vertex, we’ll fetch them from a texture mapWe simulate surface features with illumination only per-vertex normalsper-pixel normals simulated surface 30 (2)map) clearly uses normals that are not aligned with the +z axis in This makes the tangent and binormal vectors important (see discussion later)With GeForce2 we have enough horsepower to but we don’t have so much horsepower that we can do it in eye space!That would require transforming each normal into eye space (after fetching it from the texture map) 31 (2)Fetched normals are already in the correct spaceLight and eye vector interpolate nicely as long as the tangent and binormal are “well behaved”limited range and precision not a big penaltylighting, you can’t have a non-uniform scale without requiring a per-normal transform and renormalizedon’t do lots of non-uniform scaling --it won’t behave correctly 32 (3)capable of eye space lighting per-The NV_texture_shader extension provides a 3x3 “texel matrix” that can be used to transform fetched normals from surface-local space into eye space for lighting calculationsSupports non-uniform scale with renormalization per-pixel!lighting in a single pass –an operation that 33 Whether we implement per-pixel lighting in surface-local space binormal vectors need to be well-behaved from 1T2B2B1 ,,21TTa ,,21BBa 1T2B2B1 34 Another way to look at the problem case: T1T2B2B1 1T2B2B1 B2 1T2B1 x -y surface-local space for vertex 1surface-local space for vertex 2 The vectors we interpolate over the polygon are: very denormalized -yx1122 35 In the previous case, we considered transforming the light into the surface-local space this is what we would do for GeForce2For GeForce3, we can interpolate the 3x3 matrix over the surface and transform the normals by it –for this case if the tangent and binormal are not well-behaved, other anomalous behavior will Normal “twisting”Incorrect bump scale/smoothingThe interpolated matrix should be “nearly orthonormal” 36 Please check out the NVIDIA OpenGL SDK How do you compute a surface-local matrix for textured polygonal models?How do you animate per-pixel shaded surfaces? 37 Cass Everitt www.nvidia.com/Developer