The Rendering Pipeline (1) Alessandro Martinelli alessandro.martinelli@unipv.it 30 settembre 2014 The Rendering Pipeline (1) Rendering Architecture First Rendering Pipeline Second Pipeline: Illumination and Shading Third Pipeline: Coordinates Transforms Fourth Pipeline: Texturing Fifth Pipeline: Memory Structures Programmable Graphics Hardware
Rendering Architecture The Rendering Pipeline (1) Rendering Architecture First Rendering Pipeline Rendering Primitives Unit Volume, Clipping and Viewport Transform Scan-Line and Z-Buffer Algorithms A Simplified Rendering Pipeline Second Pipeline: Illumination and Shading Third Pipeline: Coordinates Transforms Fourth Pipeline: Texturing Fifth Pipeline: Memory Structures Programmable Graphics Hardware A. Martinelli Pipeline 30 settembre 2014 2 / 42
Rendering Architecture Rendering Architecture CPU side Driver Buffer Istruzione 1 Istruzione 2 Istruzione 3... Bus GPU side GPU Graphics Memory API Application A. Martinelli Pipeline 30 settembre 2014 3 / 42
Rendering Architecture Graphics API Low-Level Library Open GL (Open Graphics Library) Direct3D (DirectX, microsoft library) High-Level Library Java 3D Open Scenegraph others... A. Martinelli Pipeline 30 settembre 2014 4 / 42
Rendering Architecture Graphics API: Open GL Open Graphics Library: C and C++ software library, available in Java with JOGL Binding. A. Martinelli Pipeline 30 settembre 2014 5 / 42
Rendering Architecture Graphics API: Open GL Open Graphics Library: C and C++ software library, available in Java with JOGL Binding. At the moment, a well defined standard from Khronos Group A. Martinelli Pipeline 30 settembre 2014 5 / 42
Rendering Architecture Graphics API: Open GL Open Graphics Library: C and C++ software library, available in Java with JOGL Binding. At the moment, a well defined standard from Khronos Group Different Versions: Open GL 1.x: fixed rendering pipeline. Open GL 2.x/3.x/4.x: programmable-customizable rendering pipeline Open GL 1.0/1.1 ES: simplified OpenGL 1.x version for Embedded Systems missing a programmable graphics chipset. Open GL 2.0/3.0 ES: simplified OpenGL 2.x/3.x version for Embedded Systems having a programmable graphics chipset. A. Martinelli Pipeline 30 settembre 2014 5 / 42
Rendering Architecture Graphics API: Open GL Open Graphics Library: C and C++ software library, available in Java with JOGL Binding. At the moment, a well defined standard from Khronos Group Different Versions: Open GL 1.x: fixed rendering pipeline. Open GL 2.x/3.x/4.x: programmable-customizable rendering pipeline Open GL 1.0/1.1 ES: simplified OpenGL 1.x version for Embedded Systems missing a programmable graphics chipset. Open GL 2.0/3.0 ES: simplified OpenGL 2.x/3.x version for Embedded Systems having a programmable graphics chipset. Defining the Graphical Context : XGL, GLUT: Linux Systems WGL: Windows EGL: Embedded Systems A. Martinelli Pipeline 30 settembre 2014 5 / 42
Rendering Architecture GPU: a Gray Box the Graphics API will control a GPU Model A. Martinelli Pipeline 30 settembre 2014 6 / 42
Rendering Architecture GPU: a Gray Box the Graphics API will control a GPU Model the real GPU implements the Model A. Martinelli Pipeline 30 settembre 2014 6 / 42
Rendering Architecture GPU: a Gray Box the Graphics API will control a GPU Model the real GPU implements the Model the effective structure must respect the behavioural model of the API... A. Martinelli Pipeline 30 settembre 2014 6 / 42
Rendering Architecture GPU: a Gray Box the Graphics API will control a GPU Model the real GPU implements the Model the effective structure must respect the behavioural model of the API..... but the effective structure of the GPU is encapsulated behind the API and is not known A. Martinelli Pipeline 30 settembre 2014 6 / 42
Rendering Architecture GPU: a Gray Box the Graphics API will control a GPU Model the real GPU implements the Model the effective structure must respect the behavioural model of the API..... but the effective structure of the GPU is encapsulated behind the API and is not known OpenGL Model The GPU Model is a Pipeline A. Martinelli Pipeline 30 settembre 2014 6 / 42
Rendering Architecture GPU: a Gray Box the Graphics API will control a GPU Model the real GPU implements the Model the effective structure must respect the behavioural model of the API..... but the effective structure of the GPU is encapsulated behind the API and is not known OpenGL Model The GPU Model is a Pipeline The Rendering Pipeline is a chain of blocks implementing different graphics algorithms. A. Martinelli Pipeline 30 settembre 2014 6 / 42
Rendering Architecture About Performance Rendering Architecture: a Serial System A. Martinelli Pipeline 30 settembre 2014 7 / 42
Rendering Architecture About Performance Rendering Architecture: a Serial System As in every Serial System, we will have a bottleneck. A. Martinelli Pipeline 30 settembre 2014 7 / 42
Rendering Architecture About Performance Rendering Architecture: a Serial System As in every Serial System, we will have a bottleneck. The Bottleneck depends upon: Time of command elaboration from the CPU Time of command transfer on the Communication BUS Time of command execution on the GPU A. Martinelli Pipeline 30 settembre 2014 7 / 42
Rendering Architecture GPU: Tecnical Notes GPUs are based on parallel processing units A. Martinelli Pipeline 30 settembre 2014 8 / 42
Rendering Architecture GPU: Tecnical Notes GPUs are based on parallel processing units Common Graphics Tasks which can be executed as parallel processes: Colour management on each pixel Evaluation of vertices properties A. Martinelli Pipeline 30 settembre 2014 8 / 42
Rendering Architecture GPU: Tecnical Notes GPUs are based on parallel processing units Common Graphics Tasks which can be executed as parallel processes: Colour management on each pixel Evaluation of vertices properties From 1995 to 2005, during the time required for a CPU to speed up with a factor 2x, a GPU speeded up with a factor 10x A. Martinelli Pipeline 30 settembre 2014 8 / 42
Rendering Architecture GPU: Tecnical Notes GPUs are based on parallel processing units Common Graphics Tasks which can be executed as parallel processes: Colour management on each pixel Evaluation of vertices properties From 1995 to 2005, during the time required for a CPU to speed up with a factor 2x, a GPU speeded up with a factor 10x Main Goal: whatever it happens, try to make the GPU the Bottleneck of the system A. Martinelli Pipeline 30 settembre 2014 8 / 42
Rendering Architecture GPU: Tecnical Notes GPUs are based on parallel processing units Common Graphics Tasks which can be executed as parallel processes: Colour management on each pixel Evaluation of vertices properties From 1995 to 2005, during the time required for a CPU to speed up with a factor 2x, a GPU speeded up with a factor 10x Main Goal: whatever it happens, try to make the GPU the Bottleneck of the system... because the CPU and the Communication Bus may be involved in other processes not related to graphics A. Martinelli Pipeline 30 settembre 2014 8 / 42
Rendering Primitives The Rendering Pipeline (1) Rendering Architecture First Rendering Pipeline Rendering Primitives Unit Volume, Clipping and Viewport Transform Scan-Line and Z-Buffer Algorithms A Simplified Rendering Pipeline Second Pipeline: Illumination and Shading Third Pipeline: Coordinates Transforms Fourth Pipeline: Texturing Fifth Pipeline: Memory Structures Programmable Graphics Hardware A. Martinelli Pipeline 30 settembre 2014 9 / 42
Rendering Primitives Geometric-Rendering Primitives Geometric Primitive A simple geometric element for which our Rendering Pipeline has a rasterization algorithm A. Martinelli Pipeline 30 settembre 2014 10 / 42
Rendering Primitives Geometric-Rendering Primitives Geometric Primitive A simple geometric element for which our Rendering Pipeline has a rasterization algorithm Rasterization Algorithm Algorithm used to draw a geometry on a digital image Digital Image A matrix of pixels. Each pixel can be assigned only one RGB/RGBA colour value A. Martinelli Pipeline 30 settembre 2014 10 / 42
Rendering Primitives Geometric-Rendering Primitives Geometric Primitive A simple geometric element for which our Rendering Pipeline has a rasterization algorithm Rasterization Algorithm Algorithm used to draw a geometry on a digital image Digital Image A matrix of pixels. Each pixel can be assigned only one RGB/RGBA colour value Geometric Primitives Properties Vertices (Shape) Rendering Properties (its Rasterization Algorithm Parameters) A. Martinelli Pipeline 30 settembre 2014 10 / 42
Rendering Primitives Point Geometric Properties Vertex V Rendering Properties Colour (RGB) Dimension (diameter/edge in pixel) Anti-Aliasing (yes-no) glcolor3f(1,0,0); glpointsize(4); glbegin(gl POINTS); glvertex3f(v x,v y,v z); glend(); A. Martinelli Pipeline 30 settembre 2014 11 / 42
Rendering Primitives A. Martinelli Pipeline 30 settembre 2014 11 / 42
Rendering Primitives Line Geometric Properties Vertices {A, B} Rendering Properties Colours of each Vertex (RGB), Colour Interpolation (yes-no) Width (extension of the rectangle in direction orthogonal to AB) Anti-Aliasing (yes-no) glbegin(gl LINES); glcolor3f(1,0,0); glvertex3f(a x,a y,a z); glcolor3f(1,1,0); glvertex3f(b x,b y,b z); glend(); A. Martinelli Pipeline 30 settembre 2014 12 / 42
Rendering Primitives Drawing More Lines: Lines, Line Strip and Line Loop Primitive Lines Behaviour: Each 2 Vertices, draws a line In the example: {V 1,V 2,V 2,V 3,V 3,V 4,V 4,V 1 } V 2 V 3 V 1 V 4 A. Martinelli Pipeline 30 settembre 2014 13 / 42
Rendering Primitives Drawing More Lines: Lines, Line Strip and Line Loop Primitive Lines Behaviour: Each 2 Vertices, draws a line In the example: {V 1,V 2,V 2,V 3,V 3,V 4,V 4,V 1 } Primitive Line Strip Behaviour: for each new Vertex, create a Line with the previous one Nell esempio: {V 1,V 2,V 3,V 4,V 1 } V 2 V 3 V 1 V 4 A. Martinelli Pipeline 30 settembre 2014 13 / 42
Rendering Primitives Drawing More Lines: Lines, Line Strip and Line Loop Primitive Lines Behaviour: Each 2 Vertices, draws a line In the example: {V 1,V 2,V 2,V 3,V 3,V 4,V 4,V 1 } Primitive Line Strip Behaviour: for each new Vertex, create a Line with the previous one Nell esempio: {V 1,V 2,V 3,V 4,V 1 } Primitive Line Loop V 2 V 3 Behaviour: Closed Polyline Nell esempio: {V 1,V 2,V 3,V 4 } V 1 V 4 A. Martinelli Pipeline 30 settembre 2014 13 / 42
Rendering Primitives Triangle Geometric Properties Vertices {A,B,C} Rendering Properties Vertex Colour: Front and Back, Colour Interpolation Render Mode ( Fill-Line ) Front-Face (Counter-Clock-Wise or Clock-Wise),Face Culling (yes-no) Anti-Aliasing (yes-no) A. Martinelli Pipeline 30 settembre 2014 14 / 42
Rendering Primitives A. Martinelli Pipeline 30 settembre 2014 14 / 42
Rendering Primitives Drawing More Triangles: Triangles, Triangle Strip PrimitivePrimitiva Triangles Triangles Behaviour: Each 3 Vertices, builds a triangle Example: {V 1,V 2,V 3,V 2,V 3,V 4,V 3,V 4,V 5,V 4,V 5,V 6 } V 2 V 4 V 6 V 1 V 3 V 5 A. Martinelli Pipeline 30 settembre 2014 15 / 42
Rendering Primitives Drawing More Triangles: Triangles, Triangle Strip PrimitivePrimitiva Triangles Triangles Behaviour: Each 3 Vertices, builds a triangle Example: {V 1,V 2,V 3,V 2,V 3,V 4,V 3,V 4,V 5,V 4,V 5,V 6 } Primitive Triangle Strip Behaviour: for each new Vertex, builds a Triangle with the last 2 in the sequence Example: {V 1,V 2,V 3,V 4,V 5,V 6 } V 2 V 4 V 6 V 1 V 3 V 5 A. Martinelli Pipeline 30 settembre 2014 15 / 42
Rendering Primitives Drawing More Triangles: Triangle Fan V 2 V 4 V 5 V 1 V 3 V 6 A. Martinelli Pipeline 30 settembre 2014 16 / 42
Rendering Primitives Drawing More Triangles: Triangle Fan Primitive Triangle Fan Behaviour: for each new Vertex, builds a Triangle using the FIRST vertex in the list and the Previous one Example: {V 3,V 1,V 2,V 4,V 5,V 6 } V 2 V 4 V 5 V 1 V 3 V 6 A. Martinelli Pipeline 30 settembre 2014 16 / 42
Rendering Primitives Triangle Strip and Triangle Fan An example: Sphere Model The sphere is represented with Strips aligned with parallels The caps are represented with Triangle Fan The other strips are Triangle Strip Triangle Fan Triangle Strip Triangle Fan A. Martinelli Pipeline 30 settembre 2014 17 / 42
Rendering Primitives Triangle Property: Render Mode Render Mode: Fill Draws a filled triangles, drawing each pixel in its area glpolygonmode(gl FRONT AND BACK,GL FILL); A Fill A Line B C B C A. Martinelli Pipeline 30 settembre 2014 18 / 42
Rendering Primitives Triangle Property: Render Mode Render Mode: Fill Draws a filled triangles, drawing each pixel in its area glpolygonmode(gl FRONT AND BACK,GL FILL); Render Mode: Line Draws the layout of the triangle, drawing each edge as a line. A Fill A Line B C B C A. Martinelli Pipeline 30 settembre 2014 18 / 42
Rendering Primitives Triangle Property: Render Mode Render Mode: Fill Draws a filled triangles, drawing each pixel in its area glpolygonmode(gl FRONT AND BACK,GL FILL); Render Mode: Line Draws the layout of the triangle, drawing each edge as a line. The rendering properties of Lines are used. A Fill A Line B C B C A. Martinelli Pipeline 30 settembre 2014 18 / 42
Rendering Primitives Triangle Property: Render Mode Render Mode: Fill Draws a filled triangles, drawing each pixel in its area glpolygonmode(gl FRONT AND BACK,GL FILL); Render Mode: Line Draws the layout of the triangle, drawing each edge as a line. The rendering properties of Lines are used. glpolygonmode(gl FRONT AND BACK,GL LINE); A Fill A Line B C B C A. Martinelli Pipeline 30 settembre 2014 18 / 42
Rendering Primitives Triangle Property: Front-Face a Front Face a Back Face A. Martinelli Pipeline 30 settembre 2014 19 / 42
Rendering Primitives Triangle Property: Front-Face a Front Face a Back Face GL FRONT AND BACK : assign the property to both the face GL FRONT : assign the property to the front face GL BACK : assign the property to the back face GL NONE : stay for no faces (used for some special situations) A. Martinelli Pipeline 30 settembre 2014 19 / 42
Rendering Primitives Triangle Properties: Winding-Rule(1/2) Vertices Order Clock-Wise Counter-Clock-Wise A. Martinelli Pipeline 30 settembre 2014 20 / 42
Rendering Primitives Triangle Properties: Winding-Rule(1/2) Vertices Order Clock-Wise Counter-Clock-Wise The order of vertices after the rotation... they are ClockWise if they were CounterClockWise before the rotation they are CounterClockWise if they were ClockWise before the rotation A Counter-ClockWise A C B C ClockWise B A. Martinelli Pipeline 30 settembre 2014 20 / 42
Rendering Primitives Triangle Properties: Winding-Rule(2/2) Counter-ClockWise If vertices are Counter-ClockWise, then the triangle is seen on its Front face Otherwise. the triangle is seen on its Back face ClockWise If vertices are ClockWise, then the triangle is seen on its Front face Otherwise. the triangle is seen on its Back face glfrontface(gl CCW) : use the Counter-ClockWise winding rule (often default) glfrontface(gl CW) : use the ClockWise winding rule A. Martinelli Pipeline 30 settembre 2014 21 / 42
Rendering Primitives Triangle Property: Face Culling The Face Culling is the operation cutting all the face belonging to some face class (Back or Front) before drawing them. Why? We suppose an object is Closed, and that its Front Faces are all outside. Then, whenever we see a face from its Back Side, that face is internal and will be indeed hidden from some other Front Face. glcullface(gl BACK) : set the class of faces which must be Culled glenable/gldisable(gl CULL FACE) : enable/disable Face Culling Not Visible = visual result Front Face Direction Front Face Direction A. Martinelli Pipeline 30 settembre 2014 22 / 42
Rendering Primitives Triangle and Line Properties : Colour Interpolation Colour Interpolation: No (Flat) The triangle is drawn using the colour of given on its last vertex. A. Martinelli Pipeline 30 settembre 2014 23 / 42
Rendering Primitives Triangle and Line Properties : Colour Interpolation Colour Interpolation: No (Flat) The triangle is drawn using the colour of given on its last vertex. Interpolazione del Colore: Yes (Smooth) The colour of each pixel inside the triangle area is evaluated with a linear interpolations model based on the colour of each vertex. glshademode(gl FLAT): disable interpolation glshademode(gl SMOOTH) : enable interpolation A. Martinelli Pipeline 30 settembre 2014 23 / 42
Rendering Primitives Primitive Quad/Quad Strip A quadrilateral is always split into 2 triangles. The 2 triangles are found with an algorithm looking for the best diagonal between the 2 possible available. V 2 V 2 V 3 V3 V 1 V 1 V 4 Geometric Properties V 4 4 Vertices {V 1,V 2,V 3,V 4 } IT IS NOT necessary for such vertices to be on the same plane!! Rendering Properties Same as triangles. Quad Strip Each 2 vertices, create a quad using the 2 previous ones. A. Martinelli Pipeline 30 settembre 2014 24 / 42
Rendering Primitives Polygon Geometric Properties N Vertices {V 1,V 2,V 3,V 4,...,V N } IT IS NOT necessary for such vertices to be on the same plane!! Rendering Properties Same as triangles. A. Martinelli Pipeline 30 settembre 2014 25 / 42
Unit Volume, Clipping and Viewport Transform The Rendering Pipeline (1) Rendering Architecture First Rendering Pipeline Rendering Primitives Unit Volume, Clipping and Viewport Transform Scan-Line and Z-Buffer Algorithms A Simplified Rendering Pipeline Second Pipeline: Illumination and Shading Third Pipeline: Coordinates Transforms Fourth Pipeline: Texturing Fifth Pipeline: Memory Structures Programmable Graphics Hardware A. Martinelli Pipeline 30 settembre 2014 26 / 42
Unit Volume, Clipping and Viewport Transform Unit Volume Unit Volume The Unit Volume is the space, usually a Cube, which contains what can be seen Whatever is put inside the cube, is not visible Our Rendering Engine will project all the primitives to the Frontal Face of the Cube In OpenGL the Unit Volume is the Cube with extremes [-1,1]x[-1,1]x[-1,1] A. Martinelli Pipeline 30 settembre 2014 27 / 42
Unit Volume, Clipping and Viewport Transform Clipping Clipping is the operation cutting or eliminating all the geometries not being entirely inside the Unit Volume. Discarded Tessellated Kept A. Martinelli Pipeline 30 settembre 2014 28 / 42
Unit Volume, Clipping and Viewport Transform Viewport Transform(1/2) From the Unit Volume to the Final Image Clipping: each geometry not being entirely contained into the Unit Volume, is tasselleted or thrown away. Projection: 3D primitives are projected through the z axis to the frontal face, and they become 2D Primitives. Viewport Transform: converts Unit Volume Coordinates into Image Coordinates Clipping Projection Viewport Note Before Viewport Transform, we have 3D vertices (which may have a colour property associated) After Viewport Transform, we have 2D vertices which have a z-properties associated (and may also have a colour property) A. Martinelli Pipeline 30 settembre 2014 29 / 42
Unit Volume, Clipping and Viewport Transform Viewport Transform(2/2) Viewport Transform width,height: width and height of the image area to be drawn x VP,y VP : position of the area X im = x VP + (1+x) width 2 Y im = y VP + (1 y) height 2 a+b place the viewport. place the viewport. Note The Front Face of the Unit Volume is a square, but the viewport may not be squared. So, our geometries may seems stretched. This effect must be balanced applying proper coordinates transforms, as we will see in a following lectures. A. Martinelli Pipeline 30 settembre 2014 30 / 42
Unit Volume, Clipping and Viewport Transform The Rendering Pipeline (1) Rendering Architecture First Rendering Pipeline Rendering Primitives Unit Volume, Clipping and Viewport Transform Scan-Line and Z-Buffer Algorithms A Simplified Rendering Pipeline Second Pipeline: Illumination and Shading Third Pipeline: Coordinates Transforms Fourth Pipeline: Texturing Fifth Pipeline: Memory Structures Programmable Graphics Hardware A. Martinelli Pipeline 30 settembre 2014 31 / 42
Unit Volume, Clipping and Viewport Transform Scan-Line Algorithm (1/3) Rasterization We are going to see only one Rasterization Algorithm: the scan-line algorithm, which draws geometries like triangles. This algorithm works in a 2D space. A. Martinelli Pipeline 30 settembre 2014 32 / 42
Unit Volume, Clipping and Viewport Transform Scan-Line Algorithm (1/3) Rasterization We are going to see only one Rasterization Algorithm: the scan-line algorithm, which draws geometries like triangles. This algorithm works in a 2D space. Input given 3 vertices A.xy,B.xy,C.xy in the image-space given a z property of each vertex given a colour property of each vertex (with an active colour interpolation) A. Martinelli Pipeline 30 settembre 2014 32 / 42
Unit Volume, Clipping and Viewport Transform Scan-Line Algorithm (1/3) Rasterization We are going to see only one Rasterization Algorithm: the scan-line algorithm, which draws geometries like triangles. This algorithm works in a 2D space. Input given 3 vertices A.xy,B.xy,C.xy in the image-space given a z property of each vertex given a colour property of each vertex (with an active colour interpolation) NOTE The one presented here is a very simplified model, whose aim is to understand some of the most important aspects of the Rendering Process. A. Martinelli Pipeline 30 settembre 2014 32 / 42
Unit Volume, Clipping and Viewport Transform Scan-Line Algorithm (2/3) Algorithm They are evaluated the maximum and minimum values for y y Max y Max y Max x Min,CZ min x Max,CZ max x Min,CZ min y K x Max,CZ max y K y Min y Min y Min A. Martinelli Pipeline 30 settembre 2014 33 / 42
Unit Volume, Clipping and Viewport Transform Scan-Line Algorithm (2/3) Algorithm They are evaluated the maximum and minimum values for y For each value y within the range, with step 1 px, they are evaluated the maximum and minimum values for x y Max y Max y Max x Min,CZ min x Max,CZ max x Min,CZ min y K x Max,CZ max y K y Min y Min y Min A. Martinelli Pipeline 30 settembre 2014 33 / 42
Unit Volume, Clipping and Viewport Transform Scan-Line Algorithm (2/3) Algorithm They are evaluated the maximum and minimum values for y For each value y within the range, with step 1 px, they are evaluated the maximum and minimum values for x y Max y Max y Max x Min,CZ min x Max,CZ max x Min,CZ min y K x Max,CZ max y K y Min y Min y Min A. Martinelli Pipeline 30 settembre 2014 33 / 42
Unit Volume, Clipping and Viewport Transform Scan-Line Algorithm (2/3) Algorithm They are evaluated the maximum and minimum values for y For each value y within the range, with step 1 px, they are evaluated the maximum and minimum values for x For each pixel in the y direaction, from the minumum to the maximum of x, a line is generated. And the each pixel on that line, another linear interpolation process evaluates a depth-z and a colour value y Max y Max y Max x Min,CZ min x Max,CZ max x Min,CZ min y K x Max,CZ max y K y Min y Min y Min A. Martinelli Pipeline 30 settembre 2014 33 / 42
Unit Volume, Clipping and Viewport Transform Scan-Line Algorithm (3/3) Output (x,y): coordinates of a pixel in the image c: colour for that pixel z: a depth value related to that coordinates. ATTENTION!! For each triangle a lot of Fragments got generated. A. Martinelli Pipeline 30 settembre 2014 34 / 42
Unit Volume, Clipping and Viewport Transform Scan-Line: More Triangles Big Issue If we have 2 fragments from 2 different triangles on the same pixel (x,y), what colour should i use? Painter Algorithm Order all triangles from the farthest to the nearest and i draw all triangles in that order If a new triangle is drawing other already drawn pixels, the get overwritten Problems: Its not easy to keep an ordered list of all the triangles It Treats depth at triangles granularity, so only one depth value per triangle should be used A. Martinelli Pipeline 30 settembre 2014 35 / 42
Unit Volume, Clipping and Viewport Transform Z-Buffer (Depth-Buffer) Algorithm(1/3) A Z-Buffer is a matrix with same dimensions as the image used to store depth values. A. Martinelli Pipeline 30 settembre 2014 36 / 42
Unit Volume, Clipping and Viewport Transform Z-Buffer (Depth-Buffer) Algorithm(1/3) A Z-Buffer is a matrix with same dimensions as the image used to store depth values. The matrix is initialized in each position with a value meaning far far away A. Martinelli Pipeline 30 settembre 2014 36 / 42
Unit Volume, Clipping and Viewport Transform Z-Buffer (Depth-Buffer) Algorithm(1/3) A Z-Buffer is a matrix with same dimensions as the image used to store depth values. The matrix is initialized in each position with a value meaning far far away each Fragment will be affected by the Depth Test. Depth Test Positive Test : if the z/depth value in the Fragment is lesser (nearest) to the value in the same position of the Z-Buffer, than the Fragment is accepted A. Martinelli Pipeline 30 settembre 2014 36 / 42
Unit Volume, Clipping and Viewport Transform Z-Buffer (Depth-Buffer) Algorithm(1/3) A Z-Buffer is a matrix with same dimensions as the image used to store depth values. The matrix is initialized in each position with a value meaning far far away each Fragment will be affected by the Depth Test. Depth Test Positive Test : if the z/depth value in the Fragment is lesser (nearest) to the value in the same position of the Z-Buffer, than the Fragment is accepted Negative Test : if the z/depth value in the Fragment is greater (farther) to the value in the same position of the Z-Buffer, than the Fragment is discarded. A. Martinelli Pipeline 30 settembre 2014 36 / 42
Unit Volume, Clipping and Viewport Transform Z-Buffer (Depth-Buffer) Algorithm(2/3) (x,y) Fragments (x,y+1) (x,y) (x,y+1) (x,y) (x,y+1) A. Martinelli Pipeline 30 settembre 2014 37 / 42
Unit Volume, Clipping and Viewport Transform Z-Buffer (Depth-Buffer) Algorithm(3/3) The Z-Buffer Algorithm allows a depths management having the precision of the pixel. This allows the rendering of intersections between triangles. The Z-Buffer precision is related to the number of bits used to represent depth values in the buffer, usually 16 bits. glenable(gl DEPTH TEST): enables the Depth-Test gldisable(gl DEPTH TEST) : disable the Depth-Test (that does not exactly means we are using the Painter Algorithm) A. Martinelli Pipeline 30 settembre 2014 38 / 42
Unit Volume, Clipping and Viewport Transform The Rendering Pipeline (1) Rendering Architecture First Rendering Pipeline Rendering Primitives Unit Volume, Clipping and Viewport Transform Scan-Line and Z-Buffer Algorithms A Simplified Rendering Pipeline Second Pipeline: Illumination and Shading Third Pipeline: Coordinates Transforms Fourth Pipeline: Texturing Fifth Pipeline: Memory Structures Programmable Graphics Hardware A. Martinelli Pipeline 30 settembre 2014 39 / 42
Unit Volume, Clipping and Viewport Transform A Simplified Rendering Pipeline (1/2) Pipeline A machine built of serial operative stages Each stage make its own task on a set of data The operative stages will work parallelly on different data sets A. Martinelli Pipeline 30 settembre 2014 40 / 42
Unit Volume, Clipping and Viewport Transform A Simplified Rendering Pipeline (1/2) Pipeline A machine built of serial operative stages Each stage make its own task on a set of data The operative stages will work parallelly on different data sets A. Martinelli Pipeline 30 settembre 2014 40 / 42
Unit Volume, Clipping and Viewport Transform A Simplified Rendering Pipeline (2/2) Pipeline State State Variable: a Rendering Property setted with the API. Its value is kept through different executions of the same stage. State Variables work on different stages Geometry: a set of Primitives built from a list of ordered vertices. In the former OpenGL the list was delimited by Begin/End instructions. A. Martinelli Pipeline 30 settembre 2014 41 / 42
Unit Volume, Clipping and Viewport Transform A Simplified Rendering Pipeline (2/2) Pipeline State State Variable: a Rendering Property setted with the API. Its value is kept through different executions of the same stage. State Variables work on different stages Geometry: a set of Primitives built from a list of ordered vertices. In the former OpenGL the list was delimited by Begin/End instructions. A. Martinelli Pipeline 30 settembre 2014 41 / 42
Unit Volume, Clipping and Viewport Transform A Simplified Rendering Pipeline (2/2) Pipeline State State Variable: a Rendering Property setted with the API. Its value is kept through different executions of the same stage. State Variables work on different stages Geometry: a set of Primitives built from a list of ordered vertices. In the former OpenGL the list was delimited by Begin/End instructions. Pipeline Instructions Vertex: Most important command, asking the pipeline to manage a new vertex. Vertex-Properties: like colour, in the Former OpenGL they were managed as special State Variable State Variable: the Rendering Properties should be constant during the drawing process of each single geometry. A. Martinelli Pipeline 30 settembre 2014 41 / 42
Unit Volume, Clipping and Viewport Transform Simplified Rendering Pipeline Structure Vertex Stream (x,c,z)min ymax (x,c,z)max y Primitives Manager Rastering Module ymin Fragments( (x,y),(c,z) ) Clipping, Viewport Transform Z-Buffering Module write read(z-test) Color Buffer Z-Buffer A. Martinelli Pipeline 30 settembre 2014 42 / 42