Geometr try: objects, surfaces, light sources… Modeling Modelin Transformati tions Lighti ting/shading model Camera Camera: viewpoint, direction, field-of-view Illuminati tion (frustum) (Shadin (S ading) ) Window (viewport) t): pixel grid where the Viewing Transformati tion picture is displayed (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion (to to Screen Space) Scan Sc n Co Conve nversi sion (Raste terizati tion) Colors, inte tensiti ties ta tailored for dis display play (ex : 24 bits, RVB) Visibility ty / Di Display 2
� From each object’s local local Modeling Modelin coordinate te syste tem (object space) Transformati tions to a global coordinate te syste tem Illuminati tion (world space) (Shadin (S ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) z y Clip Clipping ing x Projecti tion Object space World space (to to Screen Space) Sc Scan n Co Conve nversi sion (Raste terizati tion) Visibility ty / Di Display 3
� Each primitive is shaded Modelin Modeling depending on its material and Transformati tions the light sources. Illuminati tion � Local illumination only (no (S (Shadin ading) ) shadows), independent Viewing Transformati tion computation for each primitive (Perspecti tive / Orth thographic) Clipping Clip ing Projecti tion (to to Screen Space) Scan Sc n Co Conve nversi sion (Raste terizati tion) Visibility ty / Di Display 4
� From world coordinate system to Modelin Modeling view point (eye space). Transformati tions Illuminati tion v (S (Shadin ading) ) u Viewing Transformati tion p eye (Perspecti tive / Orth thographic) near Eye space Clipping Clip ing far z y Projecti tion (to to Screen Space) x Sc Scan n Co Conve nversi sion World space (Raste terizati tion) Visibility ty / Di Display 5
� Normalized coordinate tes: Modelin Modeling Transformati tions y x Illuminati tion eye z (Shadin (S ading) ) near far Viewing Transformati tion NDC Eye space (Perspecti tive / Orth thographic) � Anything outside the viewing frustu tum is Clipping Clip ing clipped: Projecti tion (to to Screen Space) Scan Sc n Co Conve nversi sion (Raste terizati tion) Visibility ty / Di Display 6
� 3D primitives are projected onto a Modelin Modeling 2D picture (screen space) Transformati tions y x y Illuminati tion x (S (Shadin ading) ) z Viewing Transformati tion z (Perspecti tive / Orth thographic) NDC Screen Space Clipping Clip ing Projecti tion (to to Screen Space) Sc Scan n Co Conve nversi sion (Raste terizati tion) Visibility ty / Di Display 7
� Convert the 2D primitive in pixels Modelin Modeling Transformati tions � Interpolate values known at the vertices (color, depth...) Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion (to to Screen Space) Scan Sc n Co Conve nversi sion (Raste terizati tion) Visibility ty / Di Display 8
� Hidden surface removal Modelin Modeling Transformati tions � Filling the frame buffer with the right color format Illuminati tion (S (Shadin ading) ) Viewing Transformati tion (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion (to to Screen Space) Scan Sc n Co Conve nversi sion (Raste terizati tion) Visibility ty / Di Display 9
� “Graphics Processing Unit” � Specialized processor for graphics rendering � Spécificities: � Highly parallel (SIMD) � Fast local memory � Large throughput 10
� Highly efficient parallel processor: o GPGPU : “General-Purpose computation on GPU” 11
Before Modelin Modeling Transformati tions graphics Illuminati tion hardware (S (Shadin ading) ) (1970s) Viewing Transformati tion (Perspecti tive / Orth thographic) Softw tware Clipping Clip ing config con igurable rable Projecti tion (to to Screen Space) Sc Scan n Co Conve nversi sion (Raste terizati tion) Visibility ty / Di Display 12
1 st generation Modelin Modeling Transformati tions graphics Illuminati tion hardware (S (Shadin ading) ) (1980s) Softw tware Viewing Transformati tion config con igurable rable (Perspecti tive / Orth thographic) Clip Clipping ing Projecti tion (to to Screen Space) Scan Sc n Co Conve nversi sion (Raste terizati tion) Hardware Hard ware (G (GPU) U) Visibility ty / Di Display 13
2 nd generation Modelin Modeling Transformati tions graphics Illuminati tion hardware (S (Shadin ading) ) (1990s) Viewing Transformati tion (Perspecti tive / Orth thographic) Hardware Hard ware Clip Clipping ing config con igurable rable Projecti tion (to to Screen Space) Scan Sc n Co Conve nversi sion (Raste terizati tion) Visibility ty / Di Display 14
� API API ( Application Programming Interface ) for graphics hardware � Mostly 2 different graphics APIs: � Direct3D (Microsoft) � Op OpenGL enGL (Khronos Group) 15
3 rd generation Modelin Modeling Transformati tions graphics Illuminati tion hardware (S (Shadin ading) ) (2000s) Viewing Transformati tion (Perspecti tive / Orth thographic) Hardware Hard ware prog program rammable able Clipping Clip ing (shaders) (sh aders) Projecti tion (to to Screen Space) Scan Sc n Co Conve nversi sion (Raste terizati tion) Visibility ty / Di Display 16
� Sha Shaders: : � Short programs, that the GPU runs at specific steps in the pipeline � Different languages (C-like), depending on the API: � NVIDIA ➭ Cg (2002) � Direct3D ➭ HLSL (2003) � OpenGL ➭ GLSL (2004) � For GPGPU : � CUDA (NVIDIA) � ATI Stream � OpenCL (Khronos Group) 17
fixed programmable memory Verte tex � 3 types of shaders Verte tex Da Data ta shader shad er 1. Verte 1. tex shader 2. Geometr 2. try shader Primiti tive Assemb Assembly ly 3. 3. Pix Pixel el shader Geometr try shad shader er � Local effect Textu tures Raste terizer 1. one vertex 2. one primitive (& neighbors) Fragment 3. one pixel shader shad er Per-fragment t Fram Framebu ebuffer ffer operati tions 18
( x’, y’, z’, w’ ) ( x, y, z, w ) ( nx’, ny’, nz’ ) ( nx, ny, nz ) ( s’, t’, r’, q’ ) ( s, t, r, q ) ( r’, g’, b’, a’ ) ( r, g, b, a ) Verte tex shader shad er ( x, y ) Geometr try s shader ader ( r’, g’, b’, a’ ) ( depth’ ) Fragment shad shader er ( x, y ) ( r, g, b, a ) ( depth ) 19
� What you can do: � Geometric transformations, changing position � Lighting, shading, computing a color per vertex � Computing texture coordinates ( x, y, z, w ) ( x’, y’, z’, w’ ) ( nx, ny, nz ) ( nx’, ny’, nz’ ) ( s, t, r, q ) ( s’, t’, r’, q’ ) ( r, g, b, a ) ( r’, g’, b’, a’ ) Verte tex shad shader er 20
� What you can do: � Add/remove vertices � Change the primitives � Get the actual geometry, before rasterization Geometr try shad shader er 21
� What you can do: � Lighting, shading, computing a color... per pixel � Use the textures as input for computations � Change pixel depth Fragment shad shader er 22
uniform mat4 modelViewProjectionMatrix; Input in vec4 vertex; Output out vec3 color; Function vec4 UneFonction( vec4 Entree ) { Swizzle return Entree.zxyw; } Main program Matrix-vector multiplication void main() Local variable { vec4 pos = modelViewProjectionMatrix * vertex; gl_Position = pos + UneFonction( vertex ); color = vec3(1.0,0.0,0.0); } OpenGL Output 23
� Code slowly, step by step, and te test t ofte ten! � Debugging is really difficult � Opti timizati tion � Best place for each computation: � Vertex shader : 1x per vertex � Fragment shader : 1x per fragment: much more frequent! � Use textures to tabulate complicated functions � Use the functions in the language, rather than coding them yourself (sin, sqrt,…) 24
4 th generation Model generati tion & tr transformati tion (te tessellati tion / tr transformati tions) graphics Illuminati tion hardware (Shadin (S ading) ) (2010s) Viewing Transformati tion (Perspecti tive / Orth thographic) Hard Hardware ware prog program rammable able Clipping Clip ing (shaders) (sh aders) Projecti tion (to to Screen Space) Sc Scan n Co Conve nversi sion (Raste terizati tion) Visibility ty / Di Display 25
� Another step, between vertex and geometry shaders Primiti tive Assemb Assembly ly Fragment Verte tex Geometr try Raste terizer shader shad er shad shader er shad shader er Per-fragment t operati tions Before Bef ore Fram Framebu ebuffer ffer fixed programmable 26
� Between vertex and geometry shaders Verte tex shad shader er Primiti tive Assemb Assembly ly Tesselati tion Tesselati tion Tesselati tion Geometr try Raste terizer Primiti tive Contr trol Evaluati Ev tion shad shader er Generato tor Fragment shad shader er fixed programmable Afte ter Per-fragment t operati tions Framebu Fram ebuffer ffer 27
Recommend
More recommend