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

Similar documents
Rasterization. CS4620 Lecture 13

Rasterization. CS 4620 Lecture Kavita Bala w/ prior instructor Steve Marschner. Cornell CS4620 Fall 2015 Lecture 16

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

Pipeline and Rasterization. COMP770 Fall 2011

Rasterization. CS4620/5620: Lecture 12. Announcements. Turn in HW 1. PPA 1 out. Friday lecture. History of graphics PPA 1 in 4621.

Rasterization. Computer Graphics Fabio Pellacini and Steve Marschner

Rasterization. COMP 575/770 Spring 2013

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

Graphics Pipeline 2D Geometric Transformations

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

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

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

CS4620/5620: Lecture 14 Pipeline

CS Rasterization. Junqiao Zhao 赵君峤

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

Pipeline Operations. CS 4620 Lecture 14

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

Rendering approaches. 1.image-oriented. 2.object-oriented. foreach pixel... 3D rendering pipeline. foreach object...

Pipeline Operations. CS 4620 Lecture 10

Einführung in Visual Computing

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

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

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

Line Drawing. Foundations of Computer Graphics Torsten Möller

CS 130 Final. Fall 2015

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

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

Computer Graphics and GPGPU Programming

Deferred Rendering Due: Wednesday November 15 at 10pm

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

Rasterization: Geometric Primitives

Computer Graphics. - Rasterization - Philipp Slusallek

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

Chapter 8: Implementation- Clipping and Rasterization

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

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

CS 543: Computer Graphics. Rasterization

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

From Ver(ces to Fragments: Rasteriza(on

Pipeline implementation II

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

CS 4620 Program 4: Ray II

Introduction to Visualization and Computer Graphics

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves

Soft shadows. Steve Marschner Cornell University CS 569 Spring 2008, 21 February

Realtime 3D Computer Graphics Virtual Reality

COMP371 COMPUTER GRAPHICS

CS 465 Program 5: Ray II

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

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

CEng 477 Introduction to Computer Graphics Fall

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Particle systems, collision detection, and ray tracing. Computer Graphics CSE 167 Lecture 17

CHAPTER 1 Graphics Systems and Models 3

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Line Drawing Week 6, Lecture 9

Topic #1: Rasterization (Scan Conversion)

Raytracing CS148 AS3. Due :59pm PDT

Last Time: Acceleration Data Structures for Ray Tracing. Schedule. Today. Shadows & Light Sources. Shadows

Scan Conversion. Drawing Lines Drawing Circles

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

Graphics (Output) Primitives. Chapters 3 & 4

Viewing and Ray Tracing. CS 4620 Lecture 4

Real-Time Graphics Architecture

Topics. From vertices to fragments

Raster Scan Displays. Framebuffer (Black and White)

Virtual Reality for Human Computer Interaction

Graphics Hardware and Display Devices

Computer Graphics I Lecture 11

CMSC427 Shading Intro. Credit: slides from Dr. Zwicker

CS 4620 Final Exam. (a) Is a circle C 0 continuous?

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

CS 130 Exam I. Fall 2015

Viewing and Ray Tracing

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

CPSC GLOBAL ILLUMINATION

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

CS5620 Intro to Computer Graphics

CPSC 314 LIGHTING AND SHADING

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

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

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

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

The Traditional Graphics Pipeline

CS 4620 Program 3: Pipeline

CSE 167: Lecture #7: Color and Shading. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

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

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

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

Computer Graphics 7 - Rasterisation

Illumination Models & Shading

CS 130 Exam I. Fall 2015

The Graphics Pipeline

Institutionen för systemteknik

Lighting and Shading Computer Graphics I Lecture 7. Light Sources Phong Illumination Model Normal Vectors [Angel, Ch

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

Drawing Fast The Graphics Pipeline

Transcription:

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

CSE 167: Computer Graphics Surface shading Materials Lights Rasterization 2

Scene data Rendering pipeline Modeling and viewing transformation Shading Projection Scan conversion, visibility Position object in 3D Determine colors of vertices Per vertex shading Map triangles to 2D Draw triangles Per pixel shading Image 3

Types of light sources At each point on surfaces we need to know Direction of incoming light (the L vector) Intensity of incoming light (the c l values) Three light types: Directional: from a specific direction Point light: from a specific point Spotlight: from a specific point with intensity that depends on direction Based on slides courtesy of Jurgen Schulze 4

Directional light source Light from a distant source Light rays are parallel Direction and intensity are the same everywhere As if the source were infinitely far away Good approximation of sunlight Specified by a unit length direction vector, and a color Light source Receiving surface 5

Point light source Similar to light bulbs An infinitesimally small point that radiates light equally in all directions Light vector varies across receiving surface Intensity drops off proportionally to the inverse square of the distance from the light Reason for inverse square falloff: Surface area of sphere A = 4 r 2 6

Point light source p c src Light source At any point v on the surface: c l v c l Receiving surface v Unitize Attenuation: 7

Point light source, attenuation Adding constant factor to denominator for better control Quadratic attenuation Most computationally expensive, most physically accurate Linear attenuation Less expensive, less accurate Constant attenuation Least expensive, least accurate 8

Spotlight source Like point light source, but intensity depends on direction Parameters Position p: location of light source Cone direction d: center axis of light source Intensity falloff: Beam width (cone angle ) The way the light tapers off at the edges of the beam (cosine exponent f) 9

Spotlight source Light source Unitize Receiving surface 10

Rasterization 11

The graphics pipeline The standard approach to object order graphics Many versions exist Software (e.g., Pixar s REYES architecture) Many options for quality and flexibility Hardware (e.g., graphics cards in PCs) Amazing performance: millions of triangles per frame We ll focus on an abstract version of hardware pipeline Called a pipeline because of the many stages Very parallelizable Leads to remarkable performance of graphics cards (many times the flops of the CPU at ~1/5 the clock speed) Based on slides courtesy of Steve Marschner 12

Pipeline overview You are here APPLICATION COMMAND STREAM 3D transformations, shading VERTEX PROCESSING TRANSFORMED GEOMETRY Conversion of primitives to pixels RASTERIZATION FRAGMENTS blending, compositing, shading FRAGMENT PROCESSING FRAMEBUFFER IMAGE user sees this DISPLAY 13

Primitives Points Line segments (and chains of connected line segments) Triangles And that s all! Curves Approximate them with chains of line segments Polygons Break them up into triangles Curved surfaces Approximate them with triangles Trend over the decades towards minimal primitives Simple, uniform, repetitive = good for parallelism 14

Rasterization First job: enumerate the pixels covered by a primitive Simple, aliased definition: pixels whose centers fall inside Second job: interpolate values across the primitive e.g., colors computed at vertices e.g., normals at vertices e.g., texture coordinates 15

Rasterizing lines Define line as a rectangle Specify by two endpoints Ideal image: black inside, white outside 16

Point sampling Approximate rectangle by drawing all pixels whose centers fall within the line Problem: sometimes turns on adjacent pixels 17

Point sampling in action 18

Bresenham lines (midpoint algorithm) Point sampling unit width rectangle leads to uneven line width Define line width parallel to pixel grid That is, turn on the single nearest pixel in each column 19

Midpoint algorithm in action 20

Algorithms for drawing lines Line equation: y = b + mx Simple algorithm: evaluate line equation per column Without loss of generality, x 0 < x 1 and 0 m 1 for x = ceil(x0) to floor(x1) y = b + m*x output(x, round(y)) y = 1.91 + 0.37 x 21

Optimizing line drawing Multiplying and rounding is slow At each pixel the only options are E and NE d = m(x + 1) + b y d > 0.5 decides between E and NE 22

Optimizing line drawing d = m(x + 1) + b y Only need to update d for integer steps in x and y Do that with addition Known as digital differential analyzer (DDA) 23

Midpoint line algorithm x = ceil(x0) y = round(m*x + b) d = m*(x + 1) + b y while x < floor(x1) if d > 0.5 y += 1 d = 1 x += 1 d += m output(x, y) 24

Linear interpolation We often attach attributes to vertices For example, computed diffuse color of a hair being drawn using lines Desire for color to vary smoothly along a chain of line segments Linear interpolation in 1D f(x) = (1 α) y 0 + α y 1, where α = (x x 0 ) / (x 1 x 0 ) In the 2D case of a line segment, α is just the fraction of the distance from (x 0, y 0 )to (x 1, y 1 ) 25

Linear interpolation Pixels are not exactly on the line Define 2D function by projection on line This is linear in 2D, so DDA can be used to interpolate 26

Alternate interpretation We are updating d and α as we step from pixel to pixel d tells us how far from the line we are α tells us how far along the line we are So d and α are coordinates in a coordinate system oriented to the line 27

Alternate interpretation View loop as visiting all pixels the line passes through Interpolate d and α for each pixel Only output fragment if pixel is in band This makes linear interpolation the primary operation 28

Pixel walk line rasterization x = ceil(x0) y = round(m*x + b) d = m*x + b y while x < floor(x1) if d > 0.5 y += 1; d = 1; else x += 1; d += m; if 0.5 < d 0.5 output(x, y) 29

Rasterizing triangles The most common case in most applications With good antialiasing can be the only case, as some systems render a line as two skinny triangles Triangle represented by three vertices Simple way to think of algorithm follows the pixel walk interpretation of line rasterization Walk from pixel to pixel over (at least) the polygon s area Evaluate linear functions as you go Use those functions to decide which pixels are inside 30

Rasterizing triangles Input: Three 2D points (the triangle s vertices in pixel space) (x0, y0); (x1, y1); (x2, y2) Parameter values at each vertex q00,, q0n; q10,, q1n; q20,, q2n Output: A list of fragments, each with The integer pixel coordinates (x, y) Interpolated parameter values q0,, qn 31

Rasterizing triangles Summary 1.Evaluation of linear functions on pixel grid 2.Functions defined by parameter values at vertices 3.Use of extra parameters to determine fragment set 32

Incremental linear evaluation A linear (affine, really) function on the plane is: Linear functions are efficient to evaluate on a grid: 33

Incremental linear evaluation lineval(xm, xm, ym, ym, cx, cy, ck) { // setup qrow = cx*xm + cy*ym + ck; } // traversal for y = ym to ym { qpix = qrow; for x = xm to xm { output(x, y, qpix); qpix += cx; } qrow += cy; } c x =.005; c y =.005; c k = 0 (image size 100x100) 34

Rasterizing triangles Summary 1.Evaluation of linear functions on pixel grid 2.Functions defined by parameter values at vertices 3.Use of extra parameters to determine fragment set 35

Defining parameter functions To interpolate parameters across a triangle we need to find the cx, cy, and ck that define the (unique) linear function that matches the given values at all 3 vertices 3 constraints on 3 unknown coefficients In matrix form 36

Defining parameter functions More efficient version: shift origin to (x0, y0) Which is a 2x2 linear system (since q 0 falls out): Solve using Cramer s rule 37

Defining parameter functions lininterp(xm, xm, ym, ym, x0, y0, q0, x1, y1, q1, x2, y2, q2) { // setup det = (x1 x0)*(y2 y0) (x2 x0)*(y1 y0); cx = ((q1 q0)*(y2 y0) (q2 q0)*(y1 y0)) / det; cy = ((q2 q0)*(x1 x0) (q1 q0)*(x2 x0)) / det; qrow = cx*(xm x0) + cy*(ym y0) + q0; q = 0 q = 1 } // traversal (same as before) for y = ym to ym { qpix = qrow; for x = xm to xm { output(x, y, qpix); qpix += cx; } qrow += cy; } q = 0 38

Interpolating several parameters lininterp(xm, xm, ym, ym, n, x0, y0, q0[], x1, y1, q1[], x2, y2, q2[]) { // setup for k = 0 to n 1 // compute cx[k], cy[k], qrow[k] // from q0[k], q1[k], q2[k] } // traversal for y = ym to ym { for k = 1 to n, qpix[k] = qrow[k]; for x = xm to xm { output(x, y, qpix); for k = 1 to n, qpix[k] += cx[k]; } for k = 1 to n, qrow[k] += cy[k]; } 39

Rasterizing triangles Summary 1.Evaluation of linear functions on pixel grid 2.Functions defined by parameter values at vertices 3.Use of extra parameters to determine fragment set 40

Barycentric coordinates A coordinate system for triangles Algebraic viewpoint Geometric viewpoint Areas of subtriangles Triangle interior test [Shirley 2000] 41

Barycentric coordinates A coordinate system for triangles Geometric viewpoint Distances Linear viewpoint Basis of edges 42

Barycentric coordinates Linear viewpoint Basis for the plane [Shirley 2000] Triangle interior test 43

Clipping to the triangle Interpolate three barycentric coordinates across the plane Each barycentric coordinate is 1 at one vertex and 0 at the other two Output fragments only when all three are > 0 44

Pixel walk (Pineda) rasterization Conservatively visit a superset of the pixels you want Interpolate linear functions Use those functions to determine when to emit a fragment 45

Rasterizing triangles with shared edge Exercise caution with rounding and arbitrary decisions Need to visit these pixels once But it is important not to visit them twice! 46

Clipping Rasterizer tends to assume entire triangles are on screen After projection transformation (in normalized device coordinate frame) Clip against the planes X, Y, Z= 1, 1 6 planes defining canonical view volume Primitive operation Clip triangle against axis aligned plane 47

Clipping a triangle against a plane 4 cases, based on sidedness of vertices All inside (keep) All outside (discard) One inside, two outside (one clipped triangle) Two inside, one outside (two clipped triangles) 48