The Rendering Pipeline (1)

Similar documents
CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Rasterization Overview

Graphics Programming

Pipeline Operations. CS 4620 Lecture 14

Rendering Objects. Need to transform all geometry then

CS451Real-time Rendering Pipeline

Spring 2009 Prof. Hyesoon Kim

CSE 167: Introduction to Computer Graphics Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

CSE 167: Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Pipeline Operations. CS 4620 Lecture 10

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

VISIBILITY & CULLING. Don t draw what you can t see. Thomas Larsson, Afshin Ameri DVA338, Spring 2018, MDH

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

COMP30019 Graphics and Interaction Rendering pipeline & object modelling

Lecture outline. COMP30019 Graphics and Interaction Rendering pipeline & object modelling. Introduction to modelling

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

Computer Graphics with OpenGL ES (J. Han) Chapter VII Rasterizer

CS 498 VR. Lecture 18-4/4/18. go.illinois.edu/vrlect18

Spring 2011 Prof. Hyesoon Kim

Hidden surface removal. Computer Graphics

CS4620/5620: Lecture 14 Pipeline

CSE 167: Lecture #4: Vertex Transformation. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Graphics and Interaction Rendering pipeline & object modelling

Computer graphic -- Programming with OpenGL I

Ciril Bohak. - INTRODUCTION TO WEBGL

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

CS130 : Computer Graphics. Tamar Shinar Computer Science & Engineering UC Riverside

4: Polygons and pixels

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Could you make the XNA functions yourself?

Rendering Pipeline and Coordinates Transforms

CS 130 Exam I. Fall 2015

CS 4620 Program 3: Pipeline

Tutorial on GPU Programming #2. Joong-Youn Lee Supercomputing Center, KISTI

The Traditional Graphics Pipeline

CHAPTER 1 Graphics Systems and Models 3

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

CS 428: Fall Introduction to. OpenGL primer. Andrew Nealen, Rutgers, /13/2010 1

The Graphics Pipeline

CS 130 Final. Fall 2015

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

CS130 : Computer Graphics Lecture 2: Graphics Pipeline. Tamar Shinar Computer Science & Engineering UC Riverside

The Traditional Graphics Pipeline

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

Performance OpenGL Programming (for whatever reason)

CMSC427 Transformations II: Viewing. Credit: some slides from Dr. Zwicker

(Refer Slide Time 05:03 min)

TSBK03 Screen-Space Ambient Occlusion

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

WebGL (Web Graphics Library) is the new standard for 3D graphics on the Web, designed for rendering 2D graphics and interactive 3D graphics.

CS 465 Program 4: Modeller

Module 13C: Using The 3D Graphics APIs OpenGL ES

THE AUSTRALIAN NATIONAL UNIVERSITY Final Examinations(Semester 2) COMP4610/COMP6461 (Computer Graphics) Final Exam

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

Geometry Primitives. Computer Science Department University of Malta. Sandro Spina Computer Graphics and Simulation Group. CGSG Geometry Primitives

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

CS 112 The Rendering Pipeline. Slide 1

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

COMP3421 Computer Graphics

Models and Architectures

Drawing Fast The Graphics Pipeline

The Traditional Graphics Pipeline

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

3D Graphics and OpenGl. First Steps

Page 1. Area-Subdivision Algorithms z-buffer Algorithm List Priority Algorithms BSP (Binary Space Partitioning Tree) Scan-line Algorithms

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

Drawing Fast The Graphics Pipeline

Texture Mapping. Texture (images) lecture 16. Texture mapping Aliasing (and anti-aliasing) Adding texture improves realism.

lecture 16 Texture mapping Aliasing (and anti-aliasing)

Institutionen för systemteknik

Motivation. Culling Don t draw what you can t see! What can t we see? Low-level Culling

OpenGL SUPERBIBLE. Fifth Edition. Comprehensive Tutorial and Reference. Richard S. Wright, Jr. Nicholas Haemel Graham Sellers Benjamin Lipchak

Many rendering scenarios, such as battle scenes or urban environments, require rendering of large numbers of autonomous characters.

Graphics Hardware. Instructor Stephen J. Guy

Spatial Data Structures and Speed-Up Techniques. Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

World Coordinate System

Introduction to Visualization and Computer Graphics

The Rasterization Pipeline

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Normalized Device Coordinate System (NDC) World Coordinate System. Example Coordinate Systems. Device Coordinate System

3D Rasterization II COS 426

Adaptive Point Cloud Rendering

CSE328 Fundamentals of Computer Graphics: Concepts, Theory, Algorithms, and Applications

E.Order of Operations

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

6.837 Introduction to Computer Graphics Final Exam Tuesday, December 20, :05-12pm Two hand-written sheet of notes (4 pages) allowed 1 SSD [ /17]

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

Lecture 2. Shaders, GLSL and GPGPU

QUESTION BANK 10CS65 : COMPUTER GRAPHICS AND VISUALIZATION

Surface shading: lights and rasterization. Computer Graphics CSE 167 Lecture 6

Graphics for VEs. Ruth Aylett

The Application Stage. The Game Loop, Resource Management and Renderer Design

Chapter 5. Projections and Rendering

CSE 167: Introduction to Computer Graphics Lecture #9: Visibility. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018

Transcription:

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