Scan Conversion- Polygons

Similar documents
Lighting/Shading III. Week 7, Wed Mar 3

CPSC 314 LIGHTING AND SHADING

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

- Rasterization. Geometry. Scan Conversion. Rasterization

Pipeline Operations. CS 4620 Lecture 14

CS 130 Final. Fall 2015

Pipeline Operations. CS 4620 Lecture 10

From Graphics to Visualization

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

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

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

Rasterization and Graphics Hardware. Not just about fancy 3D! Rendering/Rasterization. The simplest case: Points. When do we care?

The Traditional Graphics Pipeline

CHAPTER 1 Graphics Systems and Models 3

Interpolation using scanline algorithm

Illumination and Shading

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

How do we draw a picture?

Chapter 7 - Light, Materials, Appearance

CS 130 Exam I. Fall 2015

Illumination and Shading

Shading. Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller/Fuhrmann

3D Rasterization II COS 426

Shading, Advanced Rendering. Week 7, Wed Feb 28

Rendering. Illumination Model. Wireframe rendering simple, ambiguous Color filling flat without any 3D information

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Rasterizing triangles

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Introduction to Visualization and Computer Graphics

Institutionen för systemteknik

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

CS4620/5620: Lecture 14 Pipeline

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

Computer Graphics and GPGPU Programming

Fall CSCI 420: Computer Graphics. 7.1 Rasterization. Hao Li.

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

Graphics Hardware and Display Devices

CS 464 Review. Review of Computer Graphics for Final Exam

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Last Time. Correct Transparent Shadow. Does Ray Tracing Simulate Physics? Does Ray Tracing Simulate Physics? Refraction and the Lifeguard Problem

Shading Techniques Denbigh Starkey

Illumination Models and Shading

Pipeline implementation II

COMP30019 Graphics and Interaction Rendering pipeline & object modelling

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

CS Illumination and Shading. Slide 1

For each question, indicate whether the statement is true or false by circling T or F, respectively.

CS 450: COMPUTER GRAPHICS RASTERIZING LINES SPRING 2016 DR. MICHAEL J. REALE

Graphics and Interaction Rendering pipeline & object modelling

University of British Columbia CPSC 314 Computer Graphics Sep-Dec Tamara Munzner (guest lecturing) Lighting/Shading

Viewing and Modeling

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

Scan line algorithm. Jacobs University Visualization and Computer Graphics Lab : Graphics and Visualization 272

Illumination Models & Shading

CSCI 420 Computer Graphics Lecture 14. Rasterization. Scan Conversion Antialiasing [Angel Ch. 6] Jernej Barbic University of Southern California

Topics. From vertices to fragments

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

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

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

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

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

Topics and things to know about them:

Rasterization. Rasterization (scan conversion) Digital Differential Analyzer (DDA) Rasterizing a line. Digital Differential Analyzer (DDA)

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

CS 543: Computer Graphics. Rasterization

Scan Conversion. Drawing Lines Drawing Circles

RASTERISED RENDERING

PHIGS PLUS For Scientific Graphics

CS5620 Intro to Computer Graphics

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

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

GLOBAL EDITION. Interactive Computer Graphics. A Top-Down Approach with WebGL SEVENTH EDITION. Edward Angel Dave Shreiner

Course Title: Computer Graphics Course no: CSC209

Illumination & Shading: Part 1

CS 4620 Program 3: Pipeline

CPSC / Illumination and Shading

Graphics for VEs. Ruth Aylett

Models and Architectures

Spring 2012 Final. CS184 - Foundations of Computer Graphics. University of California at Berkeley

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

Sung-Eui Yoon ( 윤성의 )

Computer Graphics. Shadows

Computer Graphics I Lecture 11

Implementation III. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Triangle Rasterization

Real-Time Graphics Architecture

Reading. 18. Projections and Z-buffers. Required: Watt, Section , 6.3, 6.6 (esp. intro and subsections 1, 4, and 8 10), Further reading:

COMP371 COMPUTER GRAPHICS

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

Computergrafik. Matthias Zwicker. Herbst 2010

Rasterization Overview

Illumination and Shading

Computer Graphics. Illumination and Shading

CSE528 Computer Graphics: Theory, Algorithms, and Applications

CS451Real-time Rendering Pipeline

Transcription:

Scan Conversion- olgons Flood Fill Algorithm Chapter 9 Scan Conversion (part ) Drawing olgons on Raster Displa Input polgon with rasterized edges = (x,) point inside Goal: Fill interior with specified color on graphics displa Rendering ipeline Flood Fill Geometric Content Scan Conversion Rasterization Model/View Transform. Texturing Lighting Depth Test Geometr rocessing erspective Transform. Blending Fragment rocessing Clipping Framebuffer FloodFill if not ( OnBoundar begin (olgon, int lotixel ( x,, C ); ( x, FloodFill (, x,, C ); FloodFill (, x,, C ); FloodFill (, x,, C ); FloodFill (, x,, C ); end ; x, int, Color C ), ) or Colored ( x,, C )) Triangle/olgon Rasterization Flood Fill - Drawbacks How do we find a point inside? ixels visited up to 4 times to check if alread set Need per-pixel flag indicating if set alread clear for ever polgon! Copright 0. Alla Sheffer, UBC age

Scan Conversion- olgons Modern Rasterization: Implicit Formulation Triangle (convex polgon) = intersection of edge half-spaces Defined b set of implicit line equations - + + - + - Edge Equations Multipl with denominator L(x, ) ( e s )(x x s ) ( s )(x e x s ) 0 Avoids singularit Works with vertical lines What about the sign? Which side is in, which is out? Using Implicit Edge Equations Usage: Go over each pixel in bounding rectangle Check if pixel is inside/outside of triangle Use sign of edge equations Edge Equations Determining the sign Which side is in and which is out depends on order of start/end vertices Convention: specif vertices in counterclockwise order p p p4 p p5 p5 Computing Edge Equations Implicit equation of a triangle edge: ( e s ) L( x, ) ( x xs ) ( s ) 0 ( x x ) e see Bresenham algorithm s L(x,) positive on one side of edge, negative on the other Question: What happens for vertical lines? Edge Equations Counter-Clockwise Triangles The equation L(x,) as specified above is negative inside, positive outside Flip sign: L(x, ) ( e s )(x x s ) ( s )(x e x s ) 0 Clockwise triangles Use original formula L(x, ) ( e s )(x x s ) ( s )(x e x s ) 0 Copright 0. Alla Sheffer, UBC age

Scan Conversion- olgons Scan Conversion of olgons Edge Walking Implicit formulation doesn t work for non-convex polgons Require per pixel, per edge computation Observation: Straight line intersection with polgon = set of segments Alternative: algorithm based on scan-line/edge intersections Works for general polgons Less per pixel computations scantrapezoid( xl, xr, B, T, x, ) L x R for (=B; <=T; ++) { for (x=xl; x<=xr; x++) setixel(x,); xl += DxL; xr += DxR; } T B x L xl xr x R Scan Conversion of olgons Edge Walking Triangles General Algorithm Intersect each scanline with all edges Sort intersections in x Calculate parit to determine in/out Fill the in pixels Efficienc improvement: Exploit row-to-row coherence using edge table m Split triangles into two trapezoids with continuous left and right edges x m m m scantrapezoid(, xm,,,, ) m m scantrapezoid( x, x,,,, ) m m m Edge Walking Special case: Scan-converting a trapezoid Exploit continuous L and R edges redict intersections from one line to next x x x xx scantrapezoid( L, R, B, T,, ) L R Edge Walking Triangles Issues Man applications have small triangles Setup cost is non-trivial Clipping triangles produces non-triangles Can be avoided through re-triangulation T B x L xl xr x R Copright 0. Alla Sheffer, UBC age

Scan Conversion- olgons Discussion Old hardware: Use edge-walking algorithm Scan-convert edges, then fill in scanlines Compute interpolated values b interpolating along edges, then scanlines Requires clipping of polgons against viewing volume Faster if ou have a few, large polgons ossibl faster in software Triangle Rasterization Issues Shared Edge Ordering Need a consistent (if arbitrar) rule Example: draw pixels on left or top edge, but not on right or bottom edge Discussion: Modern GUs: Use edge equations lus plane equations for attribute interpolation No clipping of primitives required Faster with man small triangles Additional advantage: Can control the order in which pixels are processed Allows for more memor-coherent traversal orders E.g. tiles or space-filling curve rather than scanlines Triangle Rasterization Issues Sliver Rasterization Issues (Independent of Algorithm) Exactl which pixels should be lit? Those pixels inside the triangle edge (of course) But what about pixels exactl on the edge? Don t draw them: gaps possible between triangles Draw them: order of triangles matters Triangle Rasterization Issues Moving Slivers Copright 0. Alla Sheffer, UBC age 4 4

Scan Conversion- olgons Triangle Rasterization Issues These are ALIASING roblems roblems associated with representing continuous functions (triangles) with finite resolution (pixels) More on this problem when we talk about sampling Shading How can we assign pixel colors using this information? Easiest: flat shading Whole triangle gets one color (color of st vertex) Better: Gouraud shading Linearl interpolate color across triangle Even better: hong shading Linearl interpolate the normal vector Compute lighting for ever pixel Note: not supported b rendering pipeline as discussed so far Flat Shading Simplest approach: calculate illumination at one point per polgon (e.g. center) Shading Assigning colors inside triangle interior Obviousl inaccurate for smooth surfaces Shading Input to Scan Conversion: Vertices of triangles (lines, quadrilaterals ) Color (per vertex) Specified with glcolor Or: computed with lighting World-space normal (per vertex) Left over from lighting stage Flat Shading Approximations If an object reall is faceted, is this accurate? Shading Task: Determine color of ever pixel in the triangle Copright 0. Alla Sheffer, UBC age 5 5

Scan Conversion- olgons Flat Shading Approximations If an object reall is faceted, is this accurate? Gouraud Shading Artifacts Often appears dull, chalk Lacks accurate specular component if included, will be averaged over entire polgon no! For point sources, direction to light varies across the facet C C C C For specular reflectance, direction to ee varies across the facet C this interior shading missed! C this vertex shading spread over too much area Improving Flat Shading What if we evaluate hong lighting model at each pixel of the polgon? Better, but result still clearl faceted Gouraud Shading: For smoother- looking surfaces introduce vertex normals at each vertex Usuall different from facet normal Used onl for shading Think of as a better approximation of the real surface that the polgons approximate Gouraud Shading Artifacts Mach bands Ee enhances discontinuit in first derivative Ver disturbing, especiall for highlights Vertex Normals Vertex normals ma be rovided with the model Computed from first principles Approximated b averaging the normals of the facets that share the vertex hong Shading linearl interpolating surface normal across the facet, appling hong lighting model at ever pixel Same input as Gouraud shading ro: much smoother results Con: considerabl more expensive Not the same as hong lighting Common confusion hong lighting: empirical model to calculate illumination at a point on a surface Copright 0. Alla Sheffer, UBC age 6 6

Scan Conversion- olgons N 4 hong Shading Linearl interpolate the vertex normals Compute lighting equations at each pixel Can use specular component # lights k n hi I total k a I ambient I i k d n l i k s v r i N N i remember: normals used in diffuse and specular terms discontinuit in normal s rate of change harder to detect n shin Interpolation access triangle interior Interpolate between vertices: z r,g,b - colour components u,v - texture coordinates N x, N, N z - surface normals Equivalent Barcentric coordinates Bilinear interpolation lane Interpolation N hong Shading Difficulties Barcentric Coordinates Computationall expensive er-pixel vector normalization and lighting computation! Floating point operations required Lighting after perspective projection Messes up the angles between vectors Have to keep ee-space vectors around No direct support in standard rendering pipeline But can be simulated with texture mapping, procedural shading hardware (see later) Area A Barcentric coordinates a A a A / A, a / A, a a a A / A, Shading Artifacts: Silhouettes Barcentric Coordinates olgonal silhouettes remain weighted combination of vertices Gouraud hong a a a a a a 0 a, a, a (,0,0) a 0 (0,0,) a 0. 5 a (0,,0) Copright 0. Alla Sheffer, UBC age 7 7

Scan Conversion- olgons Alternative formula: Bi-Linear Interpolation Interpolate quantit along L and R edges (as a function of ) Then interpolate quantit as a function of x v vl v (x,) vr v Another Alternative: lane Equation Observation: Values var linearl in image plane E.g.: r = Ax + B + C r= red channel of the color Same for g, b, Nx, N, Nz, z From info at vertices we know: r Ax B C r Ax B C r Ax B C Solve for A, B, C p p One-time set-up cost per triangle & interpolated value p Bi-Linear Interpolation Most common approach, and what OpenGL does erform hong lighting at the vertices Linearl interpolate the resulting colors over faces edge: mix of c, c C Along edges Along scanlines Equivalent to Barcentric Coordinates! interior: mix of c, c, c C edge: mix of c, c C Discussion Which algorithm (formula) to use when? Bi-linear interpolation Together with trapezoid scan conversion lane equations Together with implicit (edge equation) scan conversion Barcentric coordinates Too expensive in current context But: method of choice for ra-tracing Whenever ou onl need to compute the value for a single pixel Bi-Linear interpolation Validation L R c : c Formulation c c c L R d d d b b c L R c c d d d b b b b All formulations should provide same value Can verif barcentric properties a a a 0 a, a, a, c d c c d d d d d c b b c c b b b b Copright 0. Alla Sheffer, UBC age 8 8