Computer Graphics and GPGPU Programming

Similar documents
Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Chapter 8: Implementation- Clipping and Rasterization

CENG 477 Introduction to Computer Graphics. Ray Tracing: Shading

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Topics. From vertices to fragments

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Institutionen för systemteknik

CS5620 Intro to Computer Graphics

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

Illumination and Shading

CEng 477 Introduction to Computer Graphics Fall

Shading. Shading = find color values at pixels of screen (when rendering a virtual 3D scene).

CS452/552; EE465/505. Clipping & Scan Conversion

Topic 9: Lighting & Reflection models 9/10/2016. Spot the differences. Terminology. Two Components of Illumination. Ambient Light Source

Today s class. Simple shadows Shading Lighting in OpenGL. Informationsteknologi. Wednesday, November 21, 2007 Computer Graphics - Class 10 1

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

Topic #1: Rasterization (Scan Conversion)

Topic 9: Lighting & Reflection models. Lighting & reflection The Phong reflection model diffuse component ambient component specular component

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

Introduction to Visualization and Computer Graphics

Computer Graphics. Illumination and Shading

Pipeline Operations. CS 4620 Lecture 10

Computer Graphics. Illumination and Shading

CPSC / Illumination and Shading

Pipeline Operations. CS 4620 Lecture 14

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

Realtime 3D Computer Graphics Virtual Reality

Visualisatie BMT. Rendering. Arjan Kok

Rasterizing triangles

Deferred Rendering Due: Wednesday November 15 at 10pm

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

CS 130 Final. Fall 2015

Illumination & Shading: Part 1

Illumination Models & Shading

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

Rasterization: Geometric Primitives

Shading and Illumination

RASTERISED RENDERING

Illumination and Shading

Lecture 15: Shading-I. CITS3003 Graphics & Animation

CHAPTER 1 Graphics Systems and Models 3

Incremental Form. Idea. More efficient if we look at d k, the value of the decision variable at x = k

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Chapter 7 - Light, Materials, Appearance

OXFORD ENGINEERING COLLEGE (NAAC Accredited with B Grade) DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING LIST OF QUESTIONS

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

From Vertices To Fragments-1

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Rasterization, or What is glbegin(gl_lines) really doing?

CPSC 314 LIGHTING AND SHADING

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

CEng 477 Introduction to Computer Graphics Fall 2007

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

Virtual Reality for Human Computer Interaction

Mach band effect. The Mach band effect increases the visual unpleasant representation of curved surface using flat shading.

From 3D World to 2D Screen. Hendrik Speleers

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

Raytracing CS148 AS3. Due :59pm PDT

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

Course Title: Computer Graphics Course no: CSC209

Computer Graphics (CS 4731) Lecture 16: Lighting, Shading and Materials (Part 1)

Ambient reflection. Jacobs University Visualization and Computer Graphics Lab : Graphics and Visualization 407

Computer Graphics (CS 543) Lecture 7b: Intro to lighting, Shading and Materials + Phong Lighting Model

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

UNIT -8 IMPLEMENTATION

Clipping and Scan Conversion

CS 130 Exam I. Fall 2015

Computer Vision Systems. Viewing Systems Projections Illuminations Rendering Culling and Clipping Implementations

From Ver(ces to Fragments: Rasteriza(on

INFOGR Computer Graphics. J. Bikker - April-July Lecture 10: Shading Models. Welcome!

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

Last class. A vertex (w x, w y, w z, w) - clipping is in the - windowing and viewport normalized view volume if: - scan conversion/ rasterization

Rendering Light Reflection Models

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

CS 130 Exam I. Fall 2015

Reflection and Shading

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

Rasterization. COMP 575/770 Spring 2013

CSE 167: Lecture #8: Lighting. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

3D Rasterization II COS 426

The Traditional Graphics Pipeline

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

CS770/870 Spring 2017 Color and Shading

Introduction to Computer Graphics. Farhana Bandukwala, PhD Lecture 14: Light Interacting with Surfaces

CS 325 Computer Graphics

Models and Architectures

Problem Set 4 Part 1 CMSC 427 Distributed: Thursday, November 1, 2007 Due: Tuesday, November 20, 2007

From Graphics to Visualization

Lecture 17: Recursive Ray Tracing. Where is the way where light dwelleth? Job 38:19

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

Real-Time Graphics Architecture

9. Illumination and Shading

Interactive Real-Time Raycasting

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

Transcription:

Computer Graphics and GPGPU Programming Donato D Ambrosio Department of Mathematics and Computer Science and Center of Excellence for High Performace Computing Cubo 22B, University of Calabria, Rende 87036, Italy mailto: donato.dambrosio@unical.it homepage: http://www.mat.unical.it/~donato Academic Year 2018/19 Donato D Ambrosio (University of Calabria) Academic Year 2018/19 1 / 51

Table of contents 1 Algorithms Clipping Rasterization Hidden surface removal 2 Light The Phong Model Shading Donato D Ambrosio (University of Calabria) Academic Year 2018/19 2 / 51

Algorithms Algorithms Donato D Ambrosio (University of Calabria) Academic Year 2018/19 3 / 51

Stages of the OpenGL s Graphics Process The graphics process can be split in the following stages: Modeling (the 3D scene is conceptually defined by means of vertices in a vectorial context) Vertex Processing Primitives (e.g. triangles) are defined Primitives laying outside the clip space are discarded (clipping) Hidden primitives are discarded (hidden surface removal) Rasterization The scene is converted into a raster image (image s elements are called fragments) Fragment processing (a color is assigned to each fragment) Output merging (combine the fragments of all primitives into color pixels for the display) Donato D Ambrosio (University of Calabria) Academic Year 2018/19 4 / 51

Clipping Clipping Clipping is the process that discards (entirely or partially) the primitives that are outside the clip space The primitives within the clip space are accepted, while the other are eliminated or rejected The primitives that are partially within the clip space are cut and new vertices added in order to obtain a new primitive that is entirely within the clip space Donato D Ambrosio (University of Calabria) Academic Year 2018/19 5 / 51

Clipping Algorithms Clipping Evaluating the intersections with the clip planes is the most important computational effort in clipping algorithm Accordingly, it is important to minimize the number of intersections (since they require floating point operations) Donato D Ambrosio (University of Calabria) Academic Year 2018/19 6 / 51

Clipping Cohen-Sutherland s clipping algorithm Let consider the two-dimensional case (it is conceptually equivalent to the three-dimensional one) The edges of the clipping plane are ideally extended to the infinitive by forming 9 regions A 4 bit code O = b 0 b 1 b 2 b 3, called outcode, is assigned to each region Donato D Ambrosio (University of Calabria) Academic Year 2018/19 7 / 51

Clipping Cohen-Sutherland s clipping algorithm Outcodes are defined by the following rule: { 1 if y > ymax b 0 = 0 if y y max Similarly, b 1 = 1 if y < y min b 2 and b 3 are defined by relations between x and the left and right edges of the clip region Note that the clip region has outcode O = 0000 Donato D Ambrosio (University of Calabria) Academic Year 2018/19 8 / 51

Clipping Cohen-Sutherland s clipping algorithm Case 1: O 1 = O 2 = 0000 Both outcode are 0000. The segment is INTERNAL Case 2: O 1 &O 2 0000 The extremes are both up, down, to the left or to the right of the clip window. The segment is EXTERNAL Case 3: O 1 &O 2 = 0000 The extremes are external but the line can not be rejected since it could intersect the window. Intersections with the clip window s edges must be computed and if the line actually intersects the clip region new vertces evaluated Case 4: O 1 0000; O 2 = 0000, or viceversa The line is partially outside the clip window. In this case, the vertex outside the window is replaced by a ne vertex resulting from the intersection between the line and the clip window s edge Donato D Ambrosio (University of Calabria) Academic Year 2018/19 9 / 51

Rasterization Scan conversion of segments Starting from the vertices of the primitive projected into the two-dimensional plane, the rasterization or scan conversion builds the primitive as a set of fragments Let us suppose the vertices composing the geometric primitives have already been projected on a n m matrix with the origin located at the bottom-left pixel Let us suppose that each pixel is a square with the center at the pixel coordinates and side equal to the distance between two adjacent pixels Donato D Ambrosio (University of Calabria) Academic Year 2018/19 10 / 51

The DDA line algorithm Algorithms Rasterization Let us suppose to have a segment defined by its extremes (x 1, y 1 ) and (x 2, y 2 ) The slope of the segment is defined as: m = y/ x The most simple scan conversion algorithm evaluates m, increments x (starting from the left extreme), and computes y i = mx i + h, where h is the ordinata of the intersection between the y axis and the line, for each x i Donato D Ambrosio (University of Calabria) Academic Year 2018/19 11 / 51

Rasterization The DDA line algorithm The above strategy is inefficient since each iteration requires one floating point multiplication and one floating point addition It is possible to avoid the multiplication by adopting an incremental strategy so that one pixel can be computed based on the previous one This algorithm is called DDA 1 Each time x is incremented of x, the corresponding variation ofy must be y = m x Ranging form x 1 to x 2, x is incremented by 1 (i.e. the distance between two pixels) and then y is incremented by y = m 1 The name comes from the Digital Differential Analyzer, a mechanical device able to solve differential equations by applying a numerical methods Donato D Ambrosio (University of Calabria) Academic Year 2018/19 12 / 51

The DDA line algorithm Algorithms Rasterization Let us assume that 0 m 1 (the other values can be treated equivalently) i n t x ; f l o a t dy, dx, y, m; dy = y2 y1 ; dx = x2 x1 ; m = dy / dx ; y = y1 ; for ( x = x1, x <= x2, x++) { w r i t e P i x e l ( x, round ( y ), l i n e _ c o l o r ) ; y += m; } Donato D Ambrosio (University of Calabria) Academic Year 2018/19 13 / 51

Rasterization Bresenham s line algorithm The DDA line algorithm is straightforward and easy to implement but execs a floating point operation for each line s pixel At the contrary, the Bresenham s line algorithm only performs integer operations Bresenham s algorithm is faster than DDA and, for this reason, it has become the most used line algorithm in Computer Graphics *** Let us suppose to have a segment defined by its extremes (x 1, y 1 ) and (x 2, y 2 ) Donato D Ambrosio (University of Calabria) Academic Year 2018/19 14 / 51

Rasterization Bresenham s line algorithm Let us suppose we are at an intermediate step of the algorithm and the pixel (i, j) was the last to be switched on As a consequence, when x = i the line y = mx + h intersects the pixel (i, j) When x = i + 1, the condition 0 m 1 implies that only one of the pixels (i + 1, j) and (i + 1, j + 1) can be switched on The choice can be expressed by means of a decision variable d = b a where a and b are the measures of lines starting from the centers of pixels (i + 1, j + 1) and (i + 1, j), respectively (as shown in the next figure), to the line y = mx + h and parallel to the y axis Donato D Ambrosio (University of Calabria) Academic Year 2018/19 15 / 51

Rasterization Bresenham s line algorithm Definition of the decision variable d = b a If d > 0 then the line y = mx + h is closest to the pixel (i + 1, j + 1) If d 0 then the line y = mx + h is closest to the pixel (i + 1, j) d can be computed without the need of floating point operations by means of a recurrence formula where d i+1 is a function of d i Donato D Ambrosio (University of Calabria) Academic Year 2018/19 16 / 51

Bresenham s line algorithm Rasterization Case d i > 0 1 + b i+1 = b i + m b i+1 = b i + m 1 a i+1 = 1 b i+1 = 1 (b i + m 1) = 1 (1 a i + m 1) = a i m + 1 d i+1 = b i+1 a i+1 = b i a i + 2m 2 = d i + 2m 2 = d i + 2(m 1) Donato D Ambrosio (University of Calabria) Academic Year 2018/19 17 / 51

Bresenham s line algorithm Rasterization Case d i 0 b i+1 = b i + m a i+1 = a i m d i+1 = b i+1 a i+1 = b i a i + 2m = d i + 2m Donato D Ambrosio (University of Calabria) Academic Year 2018/19 18 / 51

Rasterization Bresenham s line algorithm So, we have d i+1 = { di + 2(m 1) if d > 0 d i + 2m if d 0 Since we are interested in the sign of d, we can multiply by x = x 2 x 1 (that is a positive quantity) d i+1 x = { di x + 2(m 1) x = d i x + 2( y x) if d > 0 d i x + 2m x = d i x + 2 y if d 0 Eventually, we can impose d i = d i x (since both of them have the same sign) { 2( y x) if d > 0 d i+1 = d i + 2 y if d 0 Donato D Ambrosio (University of Calabria) Academic Year 2018/19 19 / 51

Rasterization Bresenham s line algorithm As regard the initial value, d can be set as follows: d = 2(y 2 y 1 ) (x 2 x 1 ) In this manner d > 0 when the angle is > 22.5 degs (and the North-East pixel is switched on) d 0 when the angle is 22.5 degs (and the East pixel si switched on) Donato D Ambrosio (University of Calabria) Academic Year 2018/19 20 / 51

Bresenham s line algorithm Rasterization dx = x2 x1 ; dy = y2 y1 ; d = dy 2 dx ; incre = 2 dy ; incrne = 2 ( dy dx ) ; x = x1 ; y = y1 ; w r i t e P i x e l ( x, y, value ) ; while ( x < x2 ) { i f ( d <= 0) { d += incre ; x ++; } else { d += incrne ; x ++; y ++; } w r i t e P i x e l ( x, y, value ) ; } Donato D Ambrosio (University of Calabria) Academic Year 2018/19 21 / 51

Rasterization Scanline polygon algorithm The scanline algorithm is the reference algorithm for the scan conversion of polygons The algorithm uses scanlines to detect which pixels belong to the polygon Donato D Ambrosio (University of Calabria) Academic Year 2018/19 22 / 51

Rasterization Scanline polygon algorithm For each scanline, the intesections with the polygon s edges are evaluated and labeled with integer numbers (starting from 1) The pixels between odd-even couples (1-2, 3-4, ecc.) are switched on Note that the scanline y a intersects the edges 5 times: In such a case, the intersections 2 and 3 are considered as a single intersection since they are obtained on monotone edges At the contrary, the intersections 2 and 3 of the scanline y b are valid since the common vertex represent a local minimum (or maximum) Donato D Ambrosio (University of Calabria) Academic Year 2018/19 23 / 51

Scanline polygon algorithm Rasterization The rasterization process starts from the bottom and from left to right Acoordingly, each next scanline differs by 1 along y The edge s slope is thus and therefore m = y i+1 y i x b x a = x b = x a + 1 m 1 x b x a Donato D Ambrosio (University of Calabria) Academic Year 2018/19 24 / 51

Rasterization Scanline polygon algorithm As a consequence, after the firt intesection (x a, y a ), the subsequent ones can be evaluated as (x b, y b ) = (x a + 1/m, y a + 1) The algorithm uses an edge table (ET), which is an array of pointers with as many entries as the framebuffer s scanlines Donato D Ambrosio (University of Calabria) Academic Year 2018/19 25 / 51

Rasterization Scanline polygon algorithm If non-null, the j th ET entry points to the list of edges that have minimum y equal to j The edges of each ET entry are ordered per minimum abscissa (x min ) in increasing order The inverse of the edge s slope (1/m) is also stored Donato D Ambrosio (University of Calabria) Academic Year 2018/19 26 / 51

Rasterization Scanline polygon algorithm An active edge table (AET) is also considered, which stores information about the edges intersected by the current scanline Differently from ET data, the second edge s information stores the current abscissa (of the scanline-edge intesection), inspite of the minimun one The figure below shows the AET content at two different stages of the algorithm, corresponding to the scanlines y = 11 and y = 18 Donato D Ambrosio (University of Calabria) Academic Year 2018/19 27 / 51

Rasterization Scanline polygon algorithm Once the ET has been defined, the algorithm processes the polygon as follows: 1 set the ordinate of the current scanline to the ordinate of the firt edge of the first entry of the ET (y = 5 in the example); 2 initialize AET to null (empty) 3 repeat the following steps until ET and AET are non empty: move the edges with ordinate y to the AET swhitch on the pixels between the odd-even intersections (1-2, 3-4, etc) remove the edges for which y = y max from AET (since they will not be interesected by the next scanline) increments y by 1 and x by 1/m (this latter only if the edge is not vertical) Donato D Ambrosio (University of Calabria) Academic Year 2018/19 28 / 51

Hidden surface removal Hidden surface removal OpenGL rasterizes the primitives (e.g. triangles) in the order they appear into the vertex buffer object (VBO) In the case an object that is far from the observer is rasterized after another object that is nearer, the former can be erroneously overwriten (since it was first rasterized) An hidden surface removal algorithm can be used in this case (OpenGL adopts the z-buffer algorithm) Donato D Ambrosio (University of Calabria) Academic Year 2018/19 29 / 51

Surface Culling Algorithms Hidden surface removal In order to minimize the amount of work required by the hidden surface removal algorithm, it is possible to remove one specific face of the primitives from the rasterization process (e.g. the back one, the face where the normal vector is applied or the face where the vertices are enumerated in clockwise order) If α denotes the angle between the normal vector and the observer direction, the cos α > 0 condition (i.e. 90 < α < 90 ) defines the primitive s front face The elimination of one or both primitive s faces can be enabled by means of the glcullface. The following example enables the cull face algorithm for the back faces glenable ( GL_CULL_FACE) ; glcullface (GL_BACK) ; Donato D Ambrosio (University of Calabria) Academic Year 2018/19 30 / 51

Hidden surface removal The z-buffer algorithm The z-buffer works together with the scan conversion and needs a further buffer called z-buffer to store depth information for each pixel The z-buffer is initialized to the distance between the observer and the far clipping plane During the scan conversion the distance of the pixel being rendered and the observer can be computed If this distance is lower than the distance stored into the z-buffer, then the pixel is visible and the z-buffer is updated with the pixel s depth Donato D Ambrosio (University of Calabria) Academic Year 2018/19 31 / 51

Hidden surface removal The z-buffer algorithm When the scan conversion of the polygon B is executed, its color will appear on the screen since its distance z 1 is less than the distance z 2 of the polygon A At the contrary, when the scan conversion of the polygon A the pixel corresponding to the intersection point will not appear on the screen Donato D Ambrosio (University of Calabria) Academic Year 2018/19 32 / 51

Light Table of contents 1 Algorithms Clipping Rasterization Hidden surface removal 2 Light The Phong Model Shading Donato D Ambrosio (University of Calabria) Academic Year 2018/19 33 / 51

Light Light Light Donato D Ambrosio (University of Calabria) Academic Year 2018/19 34 / 51

Light Light-Matter Interaction Light-Matter Interaction Lighting Model Is a mathematical formulation of the Light Equation It is fundamental for photo realistic rendering It defines how a point is lit as a function of: position into the three-dimensional space position of the (direct and indirect) sources position of the observer characteristics of the material The following terms are used in the context of the light equation: lighting, which refers to the amount of incident light radiation shading, which refers to the evaluation of the resulting color Donato D Ambrosio (University of Calabria) Academic Year 2018/19 35 / 51

Radiance Equation Light Light-Matter Interaction L o (ω, ω r ) = L e (ω, ω r ) + L r (x, Ω) From a position x and direction ω r, the amount of outgoing light L o is the sum of the emitted light L e and of the reflected light L r Donato D Ambrosio (University of Calabria) Academic Year 2018/19 36 / 51

Radiance Equation Light Light-Matter Interaction L r is the sum of the lights rays L i incoming from any direction ω i times cosθ by the surface s reflection formula f r L r = L i (x, ω i )( ω i n )f r (x, ω r, ω r )d ω i Ω Donato D Ambrosio (University of Calabria) Academic Year 2018/19 37 / 51

Light The Phong Model The Phong Model The radiance equation is impossible to be evaluated in real time with current hardware OpenGL, which is a real time API for 3D Computer Graphics, adopts the simplified Phong Model where: Only directional and point light sources are considered No inter-reflections are taken into account The light equation is evaluated locally, thus possible occluders are ignored f r is approximated with three constants (that are used to characterize the material of the reflecting surface) As a consequence, the only simulated phenomenon is the (specular and diffuse) reflection Donato D Ambrosio (University of Calabria) Academic Year 2018/19 38 / 51

Light The Phong Model The Phong Model: diffuse reflection The incoming rays are uniformly reflected in any direction The amount of light does not depend on the position of the observer and is proportional to the cosine of the angle between the incoming light and the surface normal (Lambert s law) Donato D Ambrosio (University of Calabria) Academic Year 2018/19 39 / 51

Light The Phong Model The Phong Model: diffuse reflection Phong s diffuse equation I diff = I p k d cosθ = I p k d ( N L ) Depends on: Surface orientation, N Light direction, L The surface s reflection function, which is approximated by the constant k d Donato D Ambrosio (University of Calabria) Academic Year 2018/19 40 / 51

Light The Phong Model The Phong Model: specular reflection The angle between the reflected light and the surface normal is equal to the angle between the incoming light and the normal (θ i = θ r ) As a consequence, the amount of light depends on the position of the observer Donato D Ambrosio (University of Calabria) Academic Year 2018/19 41 / 51

Light Phong s specular equation The Phong Model Specular Equation I spec = I p k s cos n α = I p k s ( R V ) n where k s is the constant used to approximate the surface s specular reflection function Donato D Ambrosio (University of Calabria) Academic Year 2018/19 42 / 51

Light The Phong Model The Phong Model: specular reflection The specular reflection is perceived as a spot highlight that depends on the position of the observer The highest highlight is obtained when α = 0 and decreases rapidly according to the law (cosα) n, where n [1, 128] is called specular reflection exponent Donato D Ambrosio (University of Calabria) Academic Year 2018/19 43 / 51

Phong ambient equation Light The Phong Model It is used to model the inter-reflections Phong s ambient equation I amb = I a k a where k a is a material dependent constant Donato D Ambrosio (University of Calabria) Academic Year 2018/19 44 / 51

Light The Phong Model Complete formulation of the Phong Model Complete formulation of the Phong Mode I = I a k a + p I p ( k d ( N L ) + k s ( R V ) n) The model can also account for the attenuation due to the distance by means of an attenuation factor Donato D Ambrosio (University of Calabria) Academic Year 2018/19 45 / 51

Light Shading Shading The color of a fragment is evaluated by applying a shading model The best shading model would consist in calculating the light equation for each pixel of the final image However, approximate solutions have to be adopted to obtain real time applications, especially on old hw Donato D Ambrosio (University of Calabria) Academic Year 2018/19 46 / 51

Light Shading Flat Shading The flat shading, is the simplest shading model consisting into evaluating the light equation once for the whole geometric primitive The same color is thus considered for each fragment of the primitive Donato D Ambrosio (University of Calabria) Academic Year 2018/19 47 / 51

Gouraud shading Light Shading Exploits the linearity of the RGB color space: the color of an inner fragment is obtained by linearly interpolating the colors of the vertices The light equation is thus evaluated for the vertices only Both the surface s normal (if known) or the average of the normal vectors evaluated for the vertex (since it is shared by more than one geometric primitive) can be considered Donato D Ambrosio (University of Calabria) Academic Year 2018/19 48 / 51

Gouraud shading Light Shading Donato D Ambrosio (University of Calabria) Academic Year 2018/19 49 / 51

Light Shading Phong shading It is the more sophisticated shading model and is the most used in the case of surfaces with a high specular reflection In spite of interpolating colors, the Phong shading interpolates the normals The lighting equation is evaluated for all the inner fragments of the geometric primitive by considering the interpolated normal vectors Donato D Ambrosio (University of Calabria) Academic Year 2018/19 50 / 51

Light Shading Comparison of different shading models Donato D Ambrosio (University of Calabria) Academic Year 2018/19 51 / 51