Interactive Comp Graph
Interactive Comp Graph CS 5610
Popular in Course
Popular in ComputerScienence
Marian Kertzmann DVM
verified elite notetaker
This 85 page Class Notes was uploaded by Marian Kertzmann DVM on Monday October 26, 2015. The Class Notes belongs to CS 5610 at University of Utah taught by Staff in Fall. Since its upload, it has received 14 views. For similar materials see /class/229989/cs-5610-university-of-utah in ComputerScienence at University of Utah.
Reviews for Interactive Comp Graph
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 10/26/15
WVID IAquot Mathematics of PerPixel Lighting Cass Everitt NVIDIA Corporation cassnvidiaconr Review Why PerPixel Lighting onenGL Transinrrns and Specs uh nu ght n Why PerPixel Ligh g This is do tyourself lighting Because it looks better than Because everyone else is do Dnn39l h pervertex lighting Because it39s hardware accelerate ing lt elhe last an ynur hlnck If you don39t know h You gettotal control but this means you have to do it all mimynml ow to implement pervertex lighting learn how to do thatiirst Perpixel shading is an extension of pervertex shading forthe most part Nu qlshadeundeltm minim Nu gunman Example Scene warmspace quot E wewobndavthrange sage r Dias warm norman tnmnmi R mzlllm maven In Wm WM Nate warm 5 net n exvllcnsvace n EvenGL Object Space GAMISWCE Fur Q Object may Fur 63 72 72 Each ubleci has its 0Wquot unuin orientation and scale OpenGL PerVertex Lighting For DpenGL PerVertex Lighting all calculations en inc ace P ye Not essential but convenient For each DpenGL pervertex light the mination is computed C spazxamiamae 0 Wed Ce womanxquot h quotwe as assuming separate Lighting in eye space m The Vanni Transforming Normals To evaluate the lighting equation in Eyexpa 2 st be transformed from object p normals mu into Eyexpace Normals are not simply transformed by the mo delview m atrix like position You may know from the Red Book or various other sources that normals are transformed b the inversetranspose ofthe modelview matrixquot b ut let39s consider why The following slides should help pro in 39 tuition about thetransrorming ofn vide some ormals Transforming Normals 3i Romioii is applied to iioriiialsjiisi like it is to position M l i r39 Uniform scaling of posmon does quot0 affemhe V Nonuniform scaling of position does arremlie i I dlrmon normals direciioii oriioriiials 0 asiie iiiiiie way iiiisiiiiin is siieeien eiiiiiie iiiuse z niiiie SEZIIHE maiix that39s mulled iii iiiisiiiiin Note Mal WE ale 07W E nsidEYiVVE him We diIE39CIiOH U1 a nulmal is a ecled m iisnsiuimine the pusiiiin We met We sie oni cuisineiine how We direction iii 15 a iiuimsi lsa ecied nviisnsiiiimineme pusiiinn 15 Transforming Normals 1i eiliizse zrelhe basic iii nn iins and ilie EDHESFDH nn niimizil n Hiiw niies iliis match wlizii OpenGL niiiis iiznsliiimziiiii 4 f quoti M quoti7 i e y eiinsineiM ilie miineliiiew mziiix is gt quotans a m composed iilzisezile and ii iiiiziiiiin i ruiaiiuri is i ii iiie V Fnrnllllnnm mnnmlimmces lquotl39lnn in SE8 we Forst iininiiiiiimiimie x39 lliiieilizii my siin iiisezilinii ZFFIIES iiiiieisemiiilie niimizil eweiimi all scales luniliimi znn nnnrun nnm ilie same this is why we neen 6L NORMALIZE mn GL RESCALE NORMAL 39nf onenci liiiiiiinu We hZVEIn nezil Wllh II in FEPFIXEI liiiliiinii as well Object Space PerVertex Lighting f Example Scene nbjetn39pace for Nothing in the lighu39ng eguau39on require evaluakion in eye pace pace inste d N n nnurmscamglnlhemoddingmarlxwuuidmmvilmleihlngsi s v wineneelnemmw If hem del39 transform then khi emu to 7 WA Mn need In lransmrm each nnlmzl nnW lmeanen ing matrix is simply a rigid body s is eas ueeu In imnsarmihe imm lnln objntspaea39mm eye space s consider lighting in object incai lluhl smiles in nite ilghi sauce 1 s Lighting 6 in uhjectxpace nbjectspace for 21 Q 39szeihaHhe eel producls stems sane melnenne vectws39av lrl emenpaerm 011921 asimh as aH yeuors are nine vie mace rmsgetecnieunmmmmesquot sin104011 spam aYIgnlJPlzl mumquot We ne imeeueu We um eme ucmc nmmmm tn the a mime Cnnldernmmnlmllnndmm 1mm liemelee Want in Minivan sigmaincur Space 2 The classes ofmr zcerloml pace we use are de ned for eve point on a surface such thanhe point is anhe ori in and the geometric surrace 39 X39s lime lhm var nerrnlxel lighung lhe genmanc smace nnlmzl IS genemw nomha we use In lhe Imhunu mummn x and y axes are onhogonal and in the tangent plane onhe surface the entire scene can be de ned relative to any poim on any sur ce in the scene notjust relative to any object Lighting 6 in mgfaceInwlspape The vemurs gt Surfacelocal mat PerVertex Lighting In sulfatetutu space all be thes glllurrnalaltnnnl The s celocal nra rix s would providethe abjectxpaceposition dth ab pace rien ationanditw l ry rte v T 5 N P S I B N P 7 T 5 N R I I I l vectors later lfwe speci ed vertices in w zcelecal pace they39d am e39 glVertemlnM More on the tangent and binorrnal T and 5 As with lighting in eye pace orabject pace w zce lacalxpace is a perfectly valid coordinate lime to evaluate the lighting equation Cornpare eye puce and w zceleculrpuce lighting Eyech lighting the lightvectnrur eyevectnr are quot22quot hut ynu rnust translnrrn each nnrrnal inln SAY1102400111 space lighting the nurrnal is tree hut ynu rnusttranslurrn the light and eye vecturs inln surfwerlocnl space Rathertnan passin fetch them from at 1 1 perevertex nurrnals PerPixel Lighting Getting back to the original point We really want to evaluate the lighting equation perpixel g in no exture rnap We simulate survace tenures wrth rllurnrnarnn nnw M pereplxel nerrnals rrn als pervertex we39ll PerPixel Lighting in Thetexture rnap containing nonnals nonnal nrap clearly uses nonnals that are not aligned with the 1 axis in w zceelccalapace This makes Ihelzngenl and hinnrmzlveclnrs pnnant lsee discussinn laterl With GeForceZ we have enough horsepowerto evaluate the illumination equation at each pixel butwe don39t have so much horsepowerthatwe can do it in eye space Thatwnuld require translnrrning each nnrrna n eye space alter letchrng it lnrrn thetexture rnapl PerPixel Lighting tzl The better solution is to light in w zcelacalepace Fetche rmals are already in the cunectspace ate nicely as lung as well behavedquot All remaining arithmetic can be evaluated with register combiners d ge and precisiun nut a hig penalty Minor limitation as with abjectxpace pervertex lighting you can ave a 39 a nl the tangent and hinurmal are learnsmnanummrmsaeine ltvu behavecone y PerPixel Lighting 13 GeForcea is capable of eye space lighting per ixel The NV texture shader extensinn pruvides am leer matrixquot that can he used In translurm letched nurmals tram surlzceelnczl space inln eye space lur lighting calculatiuns Suppurts e nnneunilnrm scale with renurmalizatiun el n addition GeForcea can do specular diffuse and decal register combinersstyle perpixel lighting in a single pass operation that requires 3 passes on GeForcezl 31 32 l Wh rweimplementper pixel lighting In 5 Anotherwayto look atthe problem case w xcelncalepgce oreyeepgce the tangentand mama binormal vectors need to be wellbehaved from 39M 3 vertex to vertex n Speci cally Iltvrlzvmr and Ilvwizv i r Ir 1 warmly quotl quota quotl rheveumve lmelpulate we Ir 1 m the pnveuneie 7 good bad 7 r 4 aa so Tangent and Binormal tal in the previous case we considered transforming the light into the w zcelaml cc of each vertex and interpolating it forthe perpixel light vector this is whatwewould d rorseForcez forthis case ifthe tangent and binormal are not wellbehaved other anomalous behaviorwill result llurmal twisting lncurrecthumpscalesmuuthing The interpulated matrixshuuld he nearly urthunurmalquot Implementation topics Please check out the NVIDIA DpenGL SDK presentations for information on these related topics Hnw du ynu cumpute zmxmvespnce surlzceelnczl matrixlurtextured pulygunal mndeb Hnw du ynu animate perepixelshzded surtaces Questions Cass Everm wwwnvidiacomIDeveloper An Interactive Introduction to OpenGL Programming An Interactive Introd uction to OpenGL Programming Dave Shreiner Ed Angel Vicki Shreiner OpenGL and GLUT Overview Vicki Shreiner i What Is OpenGL A State Machine rW at ou ll See Today I I General OpenGL Introduction Rendering Pr 39tives OpenGL and GLUT Overview k I What is OpenGL ampwhat can it do for me OpenGL in windowing systems Why GLUT A GLUT program template i What Is OpenGL Graphics rendering API An Interactive Introduction to OpenGL Programming i Related APls i has I AGL GLX WGL t r we H Ity Toolkl Pi Preliminaries GLUT Basics ure w Libraries I Enumerated Types Emer 9 An Interactive Introduction to OpenGL Programming Sample Program void main int argc cllar arqv t t In 12 mm GHI TinolmLE qlutInitDisplayllnde mu qi tquot a eWinan arqv0 qlutllainLnnp l l GLUT Callback Functions Routine to call when something happens r 9 m t quotRegisterquot callbacks with GLUT qlutDi 1 r y unc display qlutIdleE unC Rue qlutKeyhnazlE unc keyboard l lldle Callbacks Use for animation and continuous update u I ol unc ion 7 void id1e void t dt glutPostRedisplay 7 l OpenGL Initialization Set up whatever state you39re 9 void init void glCl glCl glEnab1e GLLIGHTO glEnab 1e 61 LIGHTING 7 glEnab1e GLDEPTHTEST l Rendering Callback r Do all of your drawmg here glutDip1ayPunc display void zlisplay void t 1 gm 1 m qlutSwapHuffersO l User Input Callbacks a Process user input lutKo switch key case i i ex t sir break case 2 k g to use eaColor 00 00 00 10 7 eaDepth 10 L q ondrune keyboard void keyboaxd char key int x int y case 939 msuccsss case R GLTRUE An Interactive Introduction to OpenGL Programming l t l i Elementary Rendering I Geometric Primitive Elementary Rendering 39 Managing OpenGL State 39 OpenGL Buffers Vicki Shreiner l l l OpenGL Geometric Primitives l r Valid Polygons vs Invalid Polys All geometric rti ve ces D sum rme lvlilnl i 39llll IvlilINEil P Simple Example void dramhombn GLfloat l OpenGL Command Formats colorI glEegin GLQUADS grcorozzr r g1Vertax3 v v v Vestal An Interactive Introduction to OpenGL Programming i i Specifying Geometric Primitives openGL C r Models I Prim es are spe ed u 9117mm pm m n 912nm um red greed 11 91mm nnnrrls3 gmegini bxin 39 i fn 1 a 7 n a Vents i groan 1 red green 11 i glvertexifvi nnnrds i glint i i Shapes Tutorial Fuji GLiynumm Element in i 39 Y mmer Vertex Array 1 n ELM e hanklndines 1 2 1 L E dms Raince function all am it rixhtlndines Y Rain e taintAdam processmg of vertxces ngrawElementSiGL Pnumml 4 m unsrmlminu a hanklndinesi glblawElementsi L Pnumml 4 GLilmsImlEDinu E I am Indinesi glbrawElementsi h Pnumml 4 GLilmsIGuEDiHuE right mum An Interactive Introduction to OpenGL Programming Buffer Objects 39 Reduce data transfer Like Display Lists except only for vertex arrays and texture arrays in some extensions OpenGL s State Machine All rendering attributes are encapsulated in the OpenGL State Controlling Rendering Appearance I From Wireframe to Texture Mapped Geometry Seeing in 3D I The world in basic shapes Simple but not too simple An Interactive Introduction to OpenGL Programming l Appearance Manipulating OpenGL State V l I Texture i by current state I Appearanc s controlled Bump Displacement mapping M 9 W at H I Re ectionsRefractions y er mum g V Manipulating vertex attributes is must earn anipulate state qlcnlnr 0 ex gum1 ql39l39excnnrzl o l l i Controlling current state x That s it fortoday Setting State ganintSize size nemppm repeat Patten snoom guns able An Interactive Introduction to OpenGL Programming l r 1 Matrix Stacks General Transformation Commands 39 Modelview Texture Projection l l Load and Mult Matrices DpenGL uses column instead of row vectors Let i be the current matrix and can 39lll m 39 errnuitipiicaticn the final matrix I ays CM 39 V d glmu Matr X dxcomt TYPE m Matrices are defined like this use float rn16 l m1 m5 m9 m13 M me W110 W114 M3 M7 mu mics m4 ms miz M15 l 1 Matrix Stacks Camera Coordinate System Modelview De nes where the camera is pointing I Defaults to at origin looking a I Texture Usually p nts at the scene Projection 39 Righthand System An Interactive Introduction to OpenGL Programming World Coordinate System Object Coordinate System 39 Th concept helps to create a scene in Usually cons ered the Ident ty Mat x m 1 mm Righthand System M DELV39EW Transformations Rotation d Scaling In OpenGL transformation are performed 39 o te order they are called I Rotation and Scaling is done about orIgIn OpenGL and Matrices x4 a rays n n rices am i provides and r o n r W ok at Transformation m atrices 1 ummguneennwnwaanum 245 leciureiollaIGLMl u 7 avg a An Interactive Introduction to OpenGL Programming Texture Mapping Thanks to Ed Angel UNM Example Mappings AL whnc Womb in Imus arm iimklrw ea Texture Mapping k Texture Mapping k The souptih is easily described by pasting alabel ohthe h cylinder xture mapping associates the color of a poihtwith the colorih an image the nexture gt3 Ni ii Question to address Which point of thetexture do we use for a glven point on the suriace Establish a mapping from surface points i ii HHNW rim an i to image points 2 Texture Mapping Texture Interpolation Specify where the vertices in world space are mapped to in texture space An Interactive Introduction to OpenGL Programming Interpolating Coordinates Pipelines a d Texture Mapping k Texture mapplng is done at rasterlu on inianmiiai mi when descrlbmg a scene you assume tnattexture Interpolatlon will be done in wond space er pective proiection mans tnattne r Perspective correct texture mapping does the rlght thing but at a cost Is it a problem wmi orthographic Vlewlrlg Texture Index Interpolation ii i ii mm M in i i iii in mm W Minimum M m i in M ii iii Perspective Correction Hint a Texture coo dinate and solo terpolation eime ii l Noticeable for polygons on edgequot gluintt 3m 1 m7DRREC may hint Mini iiiiviiiiiiwim mu m Jermain mi q An Interactive Introduction to OpenGL Programming Texture Mapping and the q OpenGL Pipeline Texture Example I Images and geometry flow through separate pip es thatjoin at the The texture below Is a 256 x 256 image that has been mapped to a rectangular oly ich is vi e rasterlzer Hipie 39 p gon wh ewed in perspectiv Applying Textures l Applying Textures ll Three steps LN Texture Objects Texture Objects cont w Like display iists rortexture images Create texture objects with texture data and 39 1 E E L 39 D qlBjndTextuIe target it Generate texture names Bind textures before usin qlBindTexture target it quenTextures n texId An Interactive Introduction to OpenGL Programming 3152 Texmre FBI Converting A Texture Image k If dimensions ofimage are not power on Define atexture image from an array of qiuscaienaqe format 7 xels in CPU memo emailn wateryn n or qlTexIlaquD target leig1 components w 1 bottle foxmat type texel 39 UN is for source image n in 13 n 17 u typeiout is for destination image I Teer colors are processed by pixel o Image interpolated and filtered during pipeline callng Specifying a Texture amp mapping 3 Other Methods TeXtUI e Use frame bufferas source oftexture image Based on parametric texture coordinates u r Entitmer r r gl39l excooxd O speci ed at each vertex qlmwrexImaqezDr rm spa qlt opy l exlmaqeLD 1 1 a Modify part of a defined texture guexsubnagezm ql l39exSubIlaqe1D Do both with gliiopy exsubllageZDI Basic OpenGL Texturing srreciryiexiure can res lnrlhe miymm n l iii n An Interactive Introduction to OpenGL Programming Basic OpenGL Texturing cont Nasty Details Enabletexturing glEnab1eGLTEXTURE2D State howthe texture will be used m it u there are a lame range n unmnnsmr cnnlmllmljlhe mm m Iexlurerlaa J r Texturing is done afterlighting Example Texture Map xample illl39exl almtu39ll Emmi EL Tmmimnpis EULAn r illl39exl armtu39ll 1171 EL Tmmim x39nmEizD J mineral l Drip mm Texture Functions Basic OpenGL Texturing Controls how texture is applied qlTexEnVfi v 7 7 w prop palm TEXTUREENVMODE made GLiuoDuLM E GLi LEND GLiruayanE I Set blend colorw h GLTZXTUREENV oomR An Interactive Introduction to OpenGL Programming Basic OpenGL Texturing Q Basic OpenGL Texturing cont k Specify texture coordinates for the polygon Enable texturing glEnableGITEXTUREZD m t State how the texture will be use rvlT l 94 gJT DLJfllllll gl r Uzi l Create atexture object and fill itw h texture 39 TeXturing is done after lighting data Nasty Details Example Texture Map There are a large range of functions for controlling the layout of texture data l wquot 3 mm a a m l Is There Room for a Texture Texture Residency Query largest dimension oftexture image Working set oftextures lay e me my u quetIntqex v 39 exture proxy lll r An Interactive Introduction to OpenGL Programming i Tutorial Texture t An Interactive Introduction to OpenGL Programming Texture Mapping Ed Angel Example Mappings Model with smith A pa L do We ac ohlnnr 5 t ionkulu renneuct Texture Mapping Texture Mapping k t The soup tin is easily described by pasting a label on the plain cylinder Texture mapping associates the color of a point with the color in an image the texture Question to address Which point orthe texture do we se for a given point on the su ace Establish a mapping from surface points to image points rim 7 r Texture Mapping Apply a 1D 2D or 3D Image to geometric pr ves Uses of Textu 39ng Texture Interpolation Specify where the Linearly interpolate the mapping for other points in world space An Interactive Introduction to OpenGL Programming lnterpolating Coordinates Q 39 Pipelines and Texture Mapping Kr Texture mapping is done at rasterization i When descri mg a scene you assurnethat texture interpolation will be done in world space Which property of per roiection means that the wron thingquot will hap n apply our simple 39 de Perspective correct texture mapping does the right thing but at a cost is it a problem with orthographic viewing Texture Index Interpolation M Hi i v rm rm i new nan inn int wkl lwtl39 mt DINw Texture Interpolation Problem Perspective Correction Hint g Texture coordinate and color interpolation ellllerlln m II n n 9 L l39ll pt ll e l ceable for polygons on edgequot ngint argue min I I monogram me NailE m lullMm no on rnmrmwm rim Hm WeirMd m in mm slur JIM We ran An Interactive Introduction to OpenGL Programming Perspective Correct Texturing g Texmre Mappmg and the k OpenGL Pipe Images and geometry ow through separate pipelines that join at the rasterizer quotcomplexquot textures do not affect geometric complexity l Texture Example 1 Applying Textures l t l The texture below is a a Three steps 256 x 256 image that has been pecify texture mapped to a rectangular polygon which is viewed in I r L 9 75 PerSPECtiVE ssign texture coordinates to vertices pecify texture parameters 39 mtenng l I Applying Textures ll l specify textures in texture objects re images set texture flter r set texture function 39 r set texture wrap mode Generate texture names set optional perspective correction hint glGenTextureS nr texms 7 An Interactive Introduction to OpenGL Programming Texture Objects cont Q 39 lsn rgy Tenure Create texture objects with texture data and state gmind39l exturet target 1 D Define a texture image from an array of texels in CPU memory quot4 ngexImage2D target level 390 gnent n a border a at type texcl 4 s m r Eind textures before using gmimnextuet t I Teer colors are processed by pixel pipe 39 Ine pixel scalesbiases Converting A Texture Image Q spec39fy39ng a Texmre39 Other Methods ensions of image are not power of 2 Use frame buffer as source of textur r un glcopyrexnagezn glCoPYTOxImag1D Mo fy part of a de ned texture quexsubnnqozn qlTexSubImaqe1D Do both with chopyTexsubzuagezw Mapping a Texture Baslc OpenGL Texturlng Based on parametric texture coordinates qu oxCoouiN spe ed at each vertex An Interactive Introduction to OpenGL Programming Basic OpenGL Texturing Basic OpenGL Texturing cont Q Speclfytexturecanmmateslnrtnepnlygnn Enabletexturin glEnab1eGLTEXTURE2D 39 3999 91 quotE WE 9quot State how the texture will be used zq rr r x u r r r 7 mm xt r r create a texture men arm nu nwnn tenure data m it um rtiienbieds rm mime iure Texturing is done afterlighting Nasty Details i Example Texture Map There are a large range nHunclinns or controlling the layout nl Iexlure data inumua 42km Madam DEMGL not to Wrapping Mode Texture Functions Controls how texture is applied qlTexEnvfi v XE marina w TEXTUREENVMODE modes 39 GLMODULRTE 39 h aw cowx An Interactive Introduction to OpenGL Programming Is There Room for a Texture Q Texture Residency Query largest mension oftexture image wor 39t truareteture m t Jenn2312 5 1m m If too many textures not all are resident i i r 1 out other ta m the this one ta me i Tutorial Texture An Interactive Introduction to OpenGL Programming Texture Mapping 5 Map a 2D Texture onto an Object Texture Coord Generation Consider a Cylinder Texture Mapping Q What if we don t have a cylinder or sphere An Interactive Introduction to OpenGL Programming ngexGen Powerfuler ble underutilized ngexGen cont d How TeXGen Flts In the TampL Plpe 8 Generate texture coordinates from geometry Reference Plane Object Linear Mapping Uses plane equation Texture is attached to object a E an params nncn ngexGenfvl Lisy GLinHJEC39LPLmlE parallsl unis GLi39mx39nmaismLunDE I Computes dot product EL H mm u m gmnahle 1 GLi39mx39muismLSl Default mapping entity An Interactive Introduction to OpenGL Programming Object Linear Sample Object Linear Mapping Texture is quotattachedquot to object Demo Eye Linear Mapping Eye Linear Sample Texture is quotfixedquot in eye space Texture is fixed in eye space an params ginxsenzvmks GILEYELPLMIE parallsj GLi39mx39nmEiGmLunDE i s a 7 mun gmnahle 1 GLimxwuismLSi r Default mapping Is Identity Eye Linear Mapping Uses Demo Projected shadows ig s Aligning screen space textures up Distance functions An Interactive Introduction to OpenGL Programming Sphere Mapping Q 39 Sphere Map I Based on reflection vector a Show PDF s 139 7 Ex39rmmismliunnil gmnahle 1 arimxwuimzisi I S T coordinates only Ph g Shading Sphere Mapping Spheremap Details 8 Based on re ection vector u Uses Texture Mapping during Modeling Environment mapping Precomputed specular lighting recall lighting lecture Banana An Interactive Introduction to OpenGL Programming Texture Mapping during Modeling Texture Mapping during Modeling 4 I Banana 0 Banana Twopart mapping 0ne solution to the mapping problem is to rst map the texture to a simple intermediate surface Example map to cylinder Cylindrical Mapping Spherical Map We can use a parametric sphere in m in a similar mannerto the cylinder but have to decide where to put the distort39on Spheres are used in environmental maps An Interactive Introduction to OpenGL Programming Spherical Map 0 0 5 i 105l 0 ill Second Mapping 0 Map from intermediate object to actual object Normals from intermediate to actual Normals from actual to intermediate 39 Vectors from center of intermediate intermediate IIwa Intermediate surface Object Normal More Examples Cylindrical Texture AIzrpping Paul Bourke 1987 p astronomyswin edu aupbourketemuretexturemapp39 Box Mapping Easy to use with simple orthographic projection Also used in environment maps Baclc Left iBo om High Top Front S Mapping t Map texture onto an Tst quot T Xyz intermediate surface T xyz gt 0xyz Map intermediate surface onto the object 12 An Interactive Introduction to OpenGL Programming Table 2 Table 2 O ect Bad OK Normal Bad Cen lam quot PK K o Ject Centro K Ob ct C V Centrold open cyl Box Sphere A Interme late Sh nk ISNIBox Redundant k SNIBox W e wrap I39 re I Gettin Finer Hi hli htand Li htin Fx Ph ng Shadlng g g g g g Run the computation in fragment programs Getting Highlights Right U Texture Tricks Phong Shading 7 Sphere mapping approximates Phongi Shading m rm wagon T Wyn gimp An Interactive Introduction to OpenGL Programming W y would texturing help Ph g Shading I Put linear interpolation BEFORE highly a Spheremap Details XP nonlinear computation E Phong Shading Phong Shading 9 Ph g Shading WW lbitcllilazlll l i39ilihti mu MIN 1 mama 229 u Steps to adding texture highlights m a N C mihxwllmx mm um i An Interactive Introduction to OpenGL Programming Phong Shading Ph g Shading Corn are the Results End of Ph g Shading Lightmap I Lightmaps Segmenting the lighting An Interactive Introduction to OpenGL Programming Lightmaps k 39 Moving Local Lights 39 Recreate the texture simple but slow Manipulate the lightmap Translate to move relative to the surface Scale to change spot size Change base polygon color to adjust intensity 39 Projective textures ideal for spotlights 39 3D textures easy to use if available Lightmaps Creating a lightmap 39 Light white tesselated surface with local light 39 Render capture image as texture 39 Texture contains ambient and diffuse lighting 39 glLight parameters should match light 39 Texture can also be computed analytically Lightmaps Lightmap building tips COHS ElIlI V21 11 Intensity changes from l39gl hould be minimal near edge of lightmap Spotlights as Lightmap Special Case k 0 Ma in Sin ole S otli ht Texture Pattern Use texture matrix to perform spotlight texture coordinates transformations Lightmaps Q 1 Creating a lig htmap Render surface lit by local light Create a Texture Map from Image Lightmaps Lighting with a Lightmap 39 Local light is affected by surface color and texture Two step process adds local light contribution Modulate textured unlit surfaces with lightmap Add locally lit image to scene 39 Can mix OpenGL lightmap lighting in same scene 16 An Interactive Introduction to OpenGL Programming Lightmaps Creating local contribution E h my Lightmaps Adding local light to scene Lightm qr rm Lightmaps in quakez Packing Many Lightmaps into a Single Texture 1 Quake l light map texture image example Lightmaps Lightmaps quot Lightmap considerations LIghtmap considerations M An Interactive Introduction to OpenGL Programming Multitexturing intuitive tunnr allows the use ofmultiple textures at one time it is a standard feature of DpenGL13 and later An ordinary texture combines the base color of a polygon with color from the texture image in multitexturing this result of the rst textun39ng can be com ined with colorfrom another texture Each texture can be applied with different texture coordinates Texture Units Texture Units Multitextuan uses multiplete HE LU Texture units are named GL TEXTURED GL TEXTURE1 etc A texture unit is a part of the rendering pipeline that applies one texture to whatever is bang drawn The unit names are used WI two new functions Each unit has atexture atexture environment and optional texgen mode glActiveTexturetexture unit mquot quotI Hi tie in E tuie i H l 39 Most current hardware has from 2 to a texture units i ii iii glMultiTexCoord2ftexture unit s t t E LHF lliii Zilill Lil39lit Multitextu re Ligh mapping An Interactive Introduction to OpenGL Programming Multitexture Lightmaps Billboards 1 s d the correct texture maps Find the plane of the surface Use GLEYEPLANE with surface plane I Scale and translate the texture coords Combine sum the lightmap and the other t xture on the surface use multitexturing I Renderthe surface Billboards Slide Credits Michael Gold NV 0 Cass Everitt N a Paul Heckbert N dia Michael Gold NVidia Cass Everitt NV a Paul Heckbert NVI Ia An Interactive Introduction to OpenGL Programming The Madam John EEGPU Overview Dataparallel programming basics The GPU as a dataparallel computer Hello World GPGPU Example EEGPU DataParallel Programming Basics What is a dataparallel program Exposes parallelism Explicitly expresses data dependencies Stream programming is dataparallel model Stream programs are dependency graphs Kernels are graph nodes Streams are edges flowing between kernels EIEGPU s Stream Programming Basics Kernels exploit both instruction ILP and data SIMD level parallelism They should have simple control and high arithmetic intensity Computation is expressed as kernels ovals Data is expressed as streams arrows The stream model exploits parallelism without the complexity of traditional parallel programming EIEGPU 4 Modern Graphics Pipeline Fragment Processor c39 39 39 O u u O 39 n 0 I o I 39 39 I I l O n I I O I I O D o I O I I I O I I O O l O I O O I C O I O I O I O I l I u o u n u EEGPU s Programming a GPU for Graphics Application specifies geometry rasterized Each fragment is shaded w SIMD program Shading can use values from texture memory Image can be used as texture on future passes GPU as a Stream Processor mm Draw a screensized quad creates stream of fragments Run kernel fragment program over stream of fragments Read stream data from textures Write stream of results to frame buffer GPU as a Stream Processor Streams 9 Textures Kernels 9 Fragment program 0 forEach execution 9 Draw single large quad Hello World GPGPU Example 3 x 3 Image processing convolution Inputs image weights Output blurred image CPU version image loadImage WIDTH HEIGHT blurImage allocZeros WIDTH HEIGHT for x0 x lt WIDTH x for y0 y lt HEIGHT y for i1 i lt 1 i for j1 j lt 1 j float w computeWeightij blurImagexy w imagexi yj EIEGPU 9 Hello Warltd Example GPU Version 1 Load image into texture Figure courtesy of Mark Harris 2 Create blurImage texture to hold result EEGPU 1o Hello World GPGPU Example GPU Version 3 Load fragment program kernel Example shown in Cg float4 blurKernel uniform samplerRECT image float2 winPos WPOS out float4 blurImage blurImage float40000 for i l i lt 1 i for j l j lt 1 j float2 texCoord winPos float2ij float w computeWeightij blurImage w texRECT image texCoord mew 11 Hello World GPGPU Example GPU Version 4 Configure OpenGL to draw 11 No projection or rescaling glMatrixMode GLPROJECTION glLoadIdentity gluOrth02D0 l 0 1 glViewport0 0 WIDTH HEIGHT glMatrixMode GLMODELVIEW glLoadIdentity 5 Bind image and blurKernel texture and fragment program 6 Bind blurImage as render target EIEGPU 12 Hello W orld GPGPU Example GPU Version 7 Execute kernel on each stream element Draw quad of size WIDTH x HEIGHT 2 ngegin GLTRIANGLES glVertex2f0 0 glVertex2f2 0 glVertex2f0 2 1 quot glEnd mew 1s Hello World GPGPU Example What happened blurKernel executed on each element of image Rendering replaced outer two loops of CPU version blurKernel performed gather operation at each element 9 0 6 Gather Result blurImage was written to framebuffer texture EEGPU 14 Hello World GPGPU Example Get the source code for GPGPU exam ples httpwwwqpqpuorqdeveloper httpdownloadnvidiacomdeveloperSDKIndividual Sampl essamgleshtml gpgpufluid gpgpudisease gpupartices httpwwwaticomdevelopersdkRadeonSDKHtmlSample sOpenGLHW maqe Processinqhtm EEGPU 1s Questions GPU as stream processor Stream programming model Hello World example mow 1e References EIEGPU ATl Developer web site httpllwwwaticomldeveloperl GPGPU Developer web site httpllwwwgpgpuorgld veloper N Goodnight C Woolley G Lewin D Luebke G Humphreys A Multigrid Solver for Boundary Value Problems Using Programmable Graphics Hardware Graphics Hardware 2003 pp 102 111 M Harris W Baxter T Scheuermann A Lastra Simulation of Cloud Dynamics on Graphics Hardware Graphics Hardware 2003 pp 92 1 01 WD Hillis and G Steele Jr Data Parallel Algorithms Comm ACM 2912 December 1986 pp 1170 1183 U Kapasi W Dally S Rixner P Mattson J Owens B Khailany Efficient Conditional Operations for Dataparallel Architectures In Proc of the 33rd Ann lnt39l Symp on Microarchitecture 2000 pp 159 170 A Lefohn J Kniss C Hansen R Whitaker A Streaming NarrowBand Algorithm Interactive Deformation and Visualization of Level Sets IEEE Transactions on Visualization and Computer Graphics JullAug 2004 pp 422 433 NVlDIA Developer web site httplldevelopernvidiacomlpagelhome 17 John VISV DI5 EEGPU Outline Moore s Law brings opportunity Gains in performance and capabilities What has 20 years of development brought us How can we use those transistors Microprocessors Stream processors Today s commodity stream processor the GPU EEGPU The past 1987 20 MIPS CPU 1987 courtesy Anant Agarwal EEG PU The future 2007 1 Billion Transistors 2007 courtesy Anant Agarwal EEGPu Taday s VLSIJ gt lt 05mm to scale 50pJFLOP 12mm rl cou esy Pat Hanrahan EIEGPU TdJay s fLSIJ 1 Expcits Ample Computation 12mm rl cou esy Pat Hanrahan mew EJ gt lt 05mm 1 Exploits Ample Computation 2 Requires Efficient Communication 12mm rl cou esy Pat Hanrahan mspu NVIDIA Historicals 10000 t 1000 100 Fil Rate Geometry Rate 10 Jul Jul Jul Jul Jul Jul Jul Jul Jul 96 97 98 99 00 01 02 03 04 Production Date GPU History Features 19922000 GP Outline Moore s Law brings opportunity Gains in performance and capabilities What has 20 years of development brought us How can we use those transistors Microprocessors Stream processors Today s commodity stream processor the GPU EEGPU Characteristics of Graphics Apps Lots of arithmetic Lots of parallelism Simple control Multiple stages Feed forward pipelines Latencytolerant I deep pipelines What other applications have these characteristics EIEGPU Application Microprocessors A Solution Microprocessors address a different application space Scalar programming model with no native data parallelism Excel at controlheavy tasks Not so good at dataheavy regular applications Few arithmetic units little area Optimized for low latency not high bandwidth Maybe the scalar processing model isn t the best fit Pentium III 281 M T EIEGPU Stream Programming Abstraction Let s think about our problem in a new way Streams Stream Collection of data records Q All data IS expressed In streams stream Kernels Inputsoutputs are streams Perform computation on streams Can be chained together 3 EIEGPU Why Streams Ample computation by exposing parallelism Streams expose data parallelism Multiple stream elements can be processed in parallel Pipeline task parallelism Multiple tasks can be processed in parallel Kernels yield high arithmetic intensity Efficient communication Producerconsumer locality Predictable memory access pattern Optimize for throughput of all elements not latency of one Processing many elements at once allows latency hiding EIEGPU Taxonomy of Streaming Processors In common Exploit parallelism for high computation rate Each stage processes many items in parallel dp Several stages can run at the same time tp Efficient communication Minimize memory traffic Optimized memory system What s different Mapping of processing units to tasks in graphics pipeline EIEGPU Stream Processors Fewer processing units than tasks Time multiplexed organization Each stage fully programmable Stanford Imagine 32b stream processor for image signal and graphics processing 2001 Stanford Merrimac 64b stream processor for scientific computing 2004 Core of Stanford Streaming Supercomputer Challenge Efficiently mapping all tasks to one processing unit no specialization EIEGPU Stanford Imagine 2001 6391 ail l Mip564 Mi 564 2 c 80 star 39 Custer Cluster g 0 3 102nm Grist Cluster i Ig mi t hes l 1 A arse Ousa39 9E7 Stanford Merrimac 2004 MIT RAW Tiled Processor Architecture SMEM PC SWITCH 7 More processing units than tasks MIT RAW IBM Cell Each tile is programmable Streams connect tiles Task parallel organization Lots of ALUs and registers Short programmable wires Challenge Software support courtesy Anant Agarwal EEGPU Cell By the numbers 4 GHz 256 GFLOPS 32b FP 256 GBs memory BW 234M transistors Architecture 1 Power core scalar 8 SPEs 128b SIMD Challenge Software support EEGPU GPU SpecialPurpose Graphics Hardware Taskparallel organization 397 Assign each task to processing unit Hardwire each unit to specific task huge performance advantage Provides ample computation resources Efficient communication patterns Dominant graphics architecture I ATI Flipper 51M T VIE 05 Today s Graphics Pipeline Graphics is well suited to Application The stream programming model Command Stream hardware organizations GPUs are a commodity stream I Geometry processor What if we could apply these techniques to more general purpose problems GPUs should excel at tasks that require ample computation and efficient communication What s missing Display EIEGPU The Programmable Pipeline ii i i g j E QQQQQQQQQ 32122 1m quot GeForce 6800 courtesy NVIDIA EIEGPU Conclusions Adding programmability to GPUs is exciting Confluence Lots of computation expertise in harnessing that computation commodity production programmability GPUs have great performance Computation amp communication Programmability allows them to address many interesting problems Many challenges remain Algorithms programming models architecture languages tools Next stop The GPGPU Programming Model EIEGPU Stenciling Alg l 1 Draw the object 4 times offsetting in X amp Y screenispace each time 2 increment the stencil buffer each time stencil values meaning 0 no object 1 outline of object 2 silhouette 3 silhouette 4 interior 3 test for cases 2 amp 3 draw only these in line mode Alg 2 l offset the polygon 2 disable color buffer 3 draw the objects fills the depth buffer 4 disable offset 5 make no further changes to the depth buffer mask out 6 toggle stencil bits 7 cull the back faces 8 draw objects in line mode 9 set stencil test 1 zeroing out the stencil buffer 10 enable color buffers ll disable the Z buffer 12 draw objects in line mode with stencil test 13 reset state render silhouette edges using a different algorithm else if mode SILHOUETTEZ render image translated in 4 directions counting each time a pixel pass the depth test glEnableGL7CULL7FACE gEnd eKHLSTENCHJTEST39 glClearGLSTENClL7BUFFERiBlT glColorMask0000 ngepthMask GLiFALSE ngtencilFuncGL7ALWAYS 0 0Xff ngtencilOpGL7KEEP GLiKEEP GLilNCR Xly glVieWportl 0 WinWidthWinHeight DraWObjectsO Xy l glVieWport 0 l WinWidthWinHeight DraWObjectsO X7167 glVieWport 71 0 WinWidthWinHeight DraWObjectsO Xily l glVieWport 0 71 WinWidthWinHeight DraWObjectsO xyy glVieWport 0 0 WinWidthWinHeight glColorMaskl l l 1 ngepthMask l ngisableGL7CULL7FACE color all pixels in the framebuffer With stencil value 1 ngtencilFuncGL7EQUAL Z 0Xff ngtencilOpGL7KEEP GLiKEEP GLiKEEP glColor3fl l l DraWObjectsO ngtencilFuncGL7EQUAL 3 0Xff DraWObjectsO return state to default values ngisab le GLisTENClLiTE ST render silhouette edges only else if mode SILHOUETTEiONLY render the offset depth image glEnableGLiPOLYGONiOFFSETiFILL glPolygonOffset11 glColorMask0000 DrawObjectsO ngisable GLiPOLYGONiO FFSETiFlLL make no further changes to the depth image ngepthMask0 cull all facets of one arbitrary orientation render the remaining facets in outline mode toggling the stencil bit at each pixel glEnableGL78TENCIL7TEST ngtencilFuncGLALWAYS 0 1 ngtencilOpGLKEEP GLiKEEP GLilNVERT glEnableGLCULLFACE glPolygonModeGLiFRONTiANDiBACK GLiLlNE DrawObjectsO color all pixels in the framebuffer with stencil value 1 ngtencilFuncGLEQUAL 1 1 ngtencilOpGLZERO GLZERO GLiZERO glColorMask111l glColor3f111 ngisable GLiDEPTHiTEST DrawObjectsO return state to default values ngisable GL78TENCIL7TEST ngisableGLCULLFACE glPolygonModeGLiFRONTiANDiBACK GLiFlLL ngepthMask1 glEnableGLDEPTHTEST XXX
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'