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

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

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

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

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL

Projection and viewing. Computer Graphics CSE 167 Lecture 4

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

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

CSE 167: Introduction to Computer Graphics Lecture #5: Illumination Model

CS4620/5620: Lecture 14 Pipeline

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

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

CSE 167: Introduction to Computer Graphics Lecture #11: Visibility Culling

CSE 167: Introduction to Computer Graphics Lecture #10: View Frustum Culling

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

CS451Real-time Rendering Pipeline

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

The Rasterization Pipeline

Hidden surface removal. Computer Graphics

Models and Architectures

Spring 2009 Prof. Hyesoon Kim

Spring 2011 Prof. Hyesoon Kim

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

- Rasterization. Geometry. Scan Conversion. Rasterization

Rasterization Overview

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

Class of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space.

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

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

Drawing Fast The Graphics Pipeline

Introduction to Computer Graphics with WebGL

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

Pipeline Operations. CS 4620 Lecture 10

The Graphics Pipeline and OpenGL I: Transformations!

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

Rasterization. MIT EECS Frédo Durand and Barb Cutler. MIT EECS 6.837, Cutler and Durand 1

Lecture 4. Viewing, Projection and Viewport Transformations

CS 130 Final. Fall 2015

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

Drawing Fast The Graphics Pipeline

Could you make the XNA functions yourself?

Graphics Processing Unit Architecture (GPU Arch)

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

CSE 167: Introduction to Computer Graphics. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2013

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

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

Graphics Pipeline & APIs

Drawing Fast The Graphics Pipeline

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Lecture 2. Shaders, GLSL and GPGPU

CS GPU and GPGPU Programming Lecture 2: Introduction; GPU Architecture 1. Markus Hadwiger, KAUST

The Rendering Pipeline (1)

CS 130 Exam I. Fall 2015

Hidden Surfaces II. Week 9, Mon Mar 15

Fondamenti di Grafica 3D The Rasterization Pipeline.

Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1

COMS 4160: Problems on Transformations and OpenGL

Topic #1: Rasterization (Scan Conversion)

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

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

CS 130 Exam I. Fall 2015

Computer Graphics. Bing-Yu Chen National Taiwan University

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

Direct Rendering of Trimmed NURBS Surfaces

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

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

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

The Traditional Graphics Pipeline

CSE4030 Introduction to Computer Graphics

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

Graphics Hardware. Instructor Stephen J. Guy

Graphics Pipeline & APIs

3D Graphics Pipeline II Clipping. Instructor Stephen J. Guy

Rasterization. COMP 575/770 Spring 2013

Shaders. Slide credit to Prof. Zwicker

Introduction to Visualization and Computer Graphics

Pipeline Operations. CS 4620 Lecture 14

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

The Traditional Graphics Pipeline

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination (Total: 100 marks)

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

CS 464 Review. Review of Computer Graphics for Final Exam

Culling. Computer Graphics CSE 167 Lecture 12

Lecture 4 of 41. Lab 1a: OpenGL Basics

Scanline Rendering 2 1/42

The Graphics Pipeline and OpenGL I: Transformations!

Motivation. Sampling and Reconstruction of Visual Appearance. Effects needed for Realism. Ray Tracing. Outline

CS 112 The Rendering Pipeline. Slide 1

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

Rendering Objects. Need to transform all geometry then

Triangle Rasterization

2.11 Particle Systems

The Traditional Graphics Pipeline

Final projects. Rasterization. The Graphics Pipeline. Illumination (Shading) (Lighting) Viewing Transformation. Rest of semester. This week, with TAs

Performance OpenGL Programming (for whatever reason)

Visibility: Z Buffering

Graphics Hardware, Graphics APIs, and Computation on GPUs. Mark Segal

Transcription:

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

Announcements Project 2 due tomorrow at 2pm Grading window is 2-3:30pm Upload source code to Ted by 2pm Project 3 discussion next Monday at 3pm 2

Lecture Overview Barycentric Coordinates Rendering Pipeline Rasterization Visibility 3

Color Interpolation What if a triangle s vertex colors are different? Need to interpolate across triangle How to calculate interpolation weights? Source: efg s computer lab 4

Implicit 2D Lines Given two 2D points a, b Define function such that if p lies on the line defined by a, b 5

Implicit 2D Lines Point p lies on the line, if p-a is perpendicular to the normal n of the line n=(a y -b y, b x -a x ) p-a=(p x -a x, p y -a y ) Use dot product to determine on which side of the line p lies. If f(p)>0, p is on same side as normal, if f(p)<0 p is on opposite side. If dot product is 0, p lies on the line. 6

Barycentric Coordinates Coordinates for 2D plane defined by triangle vertices a, b, c Any point p in the plane defined by a, b, c is p = a + β (b - a) + γ (c - a) Solved for a, b, c: p= (1 β γ ) a + β b + γ c We define α = 1 β γ p = α a + β b + γ c α, β, γ are called barycentric coordinates If we imagine masses equal to α, β, γ in the locations of the vertices of the triangle, the center of mass (the Barycenter) is then p. This is the origin of the term barycentric (introduced 1827 by Möbius) 7

Barycentric Interpolation Interpolate values across triangles, e.g., colors Done by linear interpolation on triangle: Works well at common edges of neighboring triangles 8

Barycentric Coordinates Demo: http://adrianboeing.blogspot.com/2010/01/barycentric-coordinates.html 9

Lecture Overview Barycentric Coordinates Rendering Pipeline Rasterization Visibility 10

Rendering Pipeline Scene data Rendering pipeline Hardware and software which draws 3D scenes on the screen Consists of several stages Simplified version here Most operations performed by specialized hardware (GPU) Access to hardware through low-level 3D API (OpenGL, DirectX) All scene data flows through the pipeline at least once for each frame 11 Image

Rendering Pipeline Scene data Modeling and viewing transformation Shading Textures, lights, etc. Geometry Vertices and how they are connected Triangles, lines, points, triangle strips Attributes such as color Projection 12 Rasterization, visibility Image Specified in object coordinates Processed by the rendering pipeline one-by-one

Rendering Pipeline Scene data Modeling and viewing transformation Shading Projection Transform object to camera coordinates Specified by GL_MODELVIEW matrix in OpenGL User computes GL_MODELVIEW matrix as discussed Rasterization, visibility MODELVIEW matrix 13 Image

Rendering Pipeline Scene data Modeling and viewing transformation Shading Look up light sources Compute color for each vertex Projection Rasterization, visibility 14 Image

Rendering Pipeline Scene data Modeling and viewing transformation Shading Projection Rasterization, visibility Project 3D vertices to 2D image positions GL_PROJECTION matrix 15 Image

Rendering Pipeline Scene data Modeling and viewing transformation Shading Projection Draw primitives (triangles, lines, etc.) Determine what is visible Rasterization, visibility 16 Image

Rendering Pipeline Scene data Modeling and viewing transformation Shading Projection Rasterization, visibility 17 Image Pixel colors

Rendering Engine Scene data Rendering pipeline Rendering Engine: Additional software layer encapsulating low-level API Higher level functionality than OpenGL Platform independent Layered software architecture common in industry Game engines Graphics middleware 18 Image

Lecture Overview Barycentric Coordinates Rendering Pipeline Rasterization Visibility 19

Rendering Pipeline Primitives 20 Modeling and Viewing Transformation Shading Projection Rasteriztion, Visibility Image Scan conversion and rasterization are synonyms One of the main operations performed by GPU Draw triangles, lines, points (squares) Focus on triangles in this lecture

Rasterization 21

Rasterization Given vertices in pixel coordinates World space Camera space Clip space Image space Pixel coordinates 22

Rasterization How many pixels can a modern graphics processor draw per second? 23

Rasterization How many pixels can a modern graphics processor draw per second? NVidia GeForce GTX 980 144 billion pixels per second Multiple of what the fastest CPU could do 24

Rasterization Many different algorithms Old style Rasterize edges first 25

Rasterization Many different algorithms Example: Rasterize edges first Fill the spans (scan lines) Disadvantage: Requires clipping 26 Source: http://www.arcsynthesis.org

Rasterization Given vertices in pixel coordinates World space Camera space Clip space Image space Pixel coordinates 27

Rasterization Simple algorithm compute bbox clip bbox to screen limits for all pixels [x,y] in bbox compute barycentric coordinates alpha, beta, gamma if 0<alpha,beta,gamma<1 //pixel in triangle image[x,y]=trianglecolor Bounding box clipping trivial 28

Rasterization So far, we compute barycentric coordinates of many useless pixels How can this be improved? 29

Rasterization Hierarchy If block of pixels is outside triangle, no need to test individual pixels Can have several levels, usually two-level Find right granularity and size of blocks for optimal performance 30

2D Triangle-Rectangle Intersection If one of the following tests returns true, the triangle intersects the rectangle: Test if any of the triangle s vertices are inside the rectangle (e.g., by comparing the x/y coordinates to the min/max x/y coordinates of the rectangle) Test if one of the quad s vertices is inside the triangle (e.g., using barycentric coordinates) Intersect all edges of the triangle with all edges of the rectangle 31

Lecture Overview Barycentric Coordinates Rendering Pipeline Rasterization Visibility 32

Visibility At each pixel, we need to determine which triangle is visible 33

Painter s Algorithm Paint from back to front Every new pixel always paints over previous pixel in frame buffer Need to sort geometry according to depth May need to split triangles if they intersect Outdated algorithm, created when memory was expensive 34

Z-Buffering Store z-value for each pixel Depth test During rasterization, compare stored value to new value Update pixel only if new value is smaller setpixel(int x, int y, color c, float z) if(z<zbuffer(x,y)) then zbuffer(x,y) = z color(x,y) = c z-buffer is dedicated memory reserved for GPU (graphics memory) Depth test is performed by GPU 35

Z-Buffering in OpenGL In your application: Ask for a depth buffer when you create your window. Place a call to glenable (GL_DEPTH_TEST) in your program's initialization routine. Ensure that your znear and zfar clipping planes are set correctly (in glortho, glfrustum or gluperspective) and in a way that provides adequate depth buffer precision. Pass GL_DEPTH_BUFFER_BIT as a parameter to glclear. Note that the z buffer is non-linear: it uses smaller depth bins in the foreground, larger ones further from the camera. 36

Z-Buffer Fighting Problem: polygons which are close together don t get rendered correctly. Errors change with camera perspective flicker Cause: differently colored fragments from different polygons are being rasterized to same pixel and depth not clear which is in front of which Solutions: move surfaces farther apart, so that fragments rasterize into different depth bins bring near and far planes closer together use a higher precision depth buffer. Note that GLUT often defaults to 16 bit even if your graphics card supports 24 bit or 32 bit depth buffers 37

Translucent Geometry Need to depth sort translucent geometry and render with Painter s Algorithm (back to front) Problem: incorrect blending with cyclically overlapping geometry Solutions: Storage of multiple depth and color values per pixel (not practical in real-time graphics) Or back to front rendering of translucent geometry, after rendering opaque geometry Does not always work correctly: programmer has to weight rendering correctness against computational effort 38