Scanline Rendering 2 1/42

Similar documents
Spring 2009 Prof. Hyesoon Kim

Rasterization Overview

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Spring 2011 Prof. Hyesoon Kim

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

The Rasterization Pipeline

- Rasterization. Geometry. Scan Conversion. Rasterization

CS4620/5620: Lecture 14 Pipeline

CS451Real-time Rendering Pipeline

E.Order of Operations

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

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

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

Rendering Objects. Need to transform all geometry then

Lecture 2. Shaders, GLSL and GPGPU

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

Pipeline Operations. CS 4620 Lecture 14

The Traditional Graphics Pipeline

CHAPTER 1 Graphics Systems and Models 3

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

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

Graphics Hardware. Instructor Stephen J. Guy

Computer Graphics. - Rasterization - Philipp Slusallek

The Graphics Pipeline

Graphics Pipeline 2D Geometric Transformations

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

CS 130 Final. Fall 2015

Drawing Fast The Graphics Pipeline

Programming Graphics Hardware

lecture 18 - ray tracing - environment mapping - refraction

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

Computer graphics 2: Graduate seminar in computational aesthetics

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

2.11 Particle Systems

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

Shaders. Slide credit to Prof. Zwicker

Evolution of GPUs Chris Seitz

CS427 Multicore Architecture and Parallel Computing

Shadows in the graphics pipeline

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

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

Ciril Bohak. - INTRODUCTION TO WEBGL

3D Graphics and OpenGl. First Steps

3D Rendering Pipeline

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

GPU Architecture and Function. Michael Foster and Ian Frasch

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

Pipeline Operations. CS 4620 Lecture 10

CS 4620 Program 3: Pipeline

3D graphics, raster and colors CS312 Fall 2010

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

GUERRILLA DEVELOP CONFERENCE JULY 07 BRIGHTON

Programmable GPUS. Last Time? Reading for Today. Homework 4. Planar Shadows Projective Texture Shadows Shadow Maps Shadow Volumes

Graphics Processing Unit Architecture (GPU Arch)

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

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 464 Review. Review of Computer Graphics for Final Exam

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

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

Shadow Algorithms. CSE 781 Winter Han-Wei Shen

Project 1, 467. (Note: This is not a graphics class. It is ok if your rendering has some flaws, like those gaps in the teapot image above ;-)

Computer Graphics Shadow Algorithms

Drawing Fast The Graphics Pipeline

Rasterization. COMP 575/770 Spring 2013

CS 130 Exam I. Fall 2015

Getting fancy with texture mapping (Part 2) CS559 Spring Apr 2017

Drawing Fast The Graphics Pipeline

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

Models and Architectures

VTU QUESTION PAPER SOLUTION UNIT -1 INTRODUCTION

Graphics Hardware and Display Devices

Windowing System on a 3D Pipeline. February 2005

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

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

Deferred Rendering Due: Wednesday November 15 at 10pm

Last Time. Why are Shadows Important? Today. Graphics Pipeline. Clipping. Rasterization. Why are Shadows Important?

3D Graphics for Game Programming (J. Han) Chapter II Vertex Processing

frame buffer depth buffer stencil buffer

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

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

CS Exam 1 Review Problems Fall 2017

Advanced Rendering Techniques

PowerVR Hardware. Architecture Overview for Developers

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

CSE4030 Introduction to Computer Graphics

Practical Shadow Mapping

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

For Intuition about Scene Lighting. Today. Limitations of Planar Shadows. Cast Shadows on Planar Surfaces. Shadow/View Duality.

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

Hardware-driven visibility culling

Graphics Hardware. Graphics Processing Unit (GPU) is a Subsidiary hardware. With massively multi-threaded many-core. Dedicated to 2D and 3D graphics

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

CS559 Computer Graphics Fall 2015

The Graphics Pipeline and OpenGL I: Transformations!

Introduction to Shaders.

Hardware Accelerated Volume Visualization. Leonid I. Dimitrov & Milos Sramek GMI Austrian Academy of Sciences

Graphics Performance Optimisation. John Spitzer Director of European Developer Technology

Performance OpenGL Programming (for whatever reason)

Transcription:

Scanline Rendering 2 1/42

Review 1. Set up a Camera the viewing frustum has near and far clipping planes 2. Create some Geometry made out of triangles 3. Place the geometry in the scene using Transforms make sure it s in the camera s viewing frustrum 4. SNAP THE PICTURE internal workings of OpenGL and the GPU triangle vertices are projected onto the film plane projected triangles are rasterized into pixels this all happens in a buffer that is eventually swapped to the display 2/42

Coordinate Frames 3/42

Graphics Coordinate Frames Object Space (model space) Raw values as provided by glbufferdata to a vertex buffer object (e.g. teapot centered at origin) World Space (scene) Object at final location in the environment (e.g. teapot on top of a table on the ground off to the left side of the screen) Screen Space (film plane) Object splatted into pixels onto a two dimensional screen position uniform mat4 modelmatrix, viewmatrix, projectionmatrix; viewmatrix*modelmatrix: object to world transform projectionmatrix: world to screen transform CTM =projectionmatrix*viewmatrix*modelmatrix 4/42

Perspective Projection 5/42

World to Screen Transform film plane (x,y,z) x pinhole h +z world space z x (x,y,h) screen space glm::perspective creates a matrix to perform perspective projection to transform objects from world space to screen space (film plane) 6/42

Perspective Projection Using homogeneous coordinates and setting allows us to have a linear model (4X4 matrix) for a nonlinear function What about the third row? What are a and b? 7/42

Perspective Projection Mapping z=n to z =n and z=f to z =f gives: Two equations, two unknowns. The solution is n and f are still the near and far clipping planes Transforms the 3D frustrum in world space into an orthographic volume in screen space Can use z for occlusion 8/42

Rasterization 9/42

Rasterization Rasterize 2D triangles after transforming the vertices to screen space Color the pixels inside the triangle with the RGB-color of the triangle 10/42

Normal to a Line n = ( y y, x x 1 0 0 1 ) normalize, if desired 11/42

Implicit Equation for a Line for all points p on the line 12/42

Implicit Equation for a Ray ( p p ) o n Outward normal points to the right of the ray Interior points are to the left of the ray, and have negative ( p p ) o n values 13/42

Point Inside Ray Test makeline( vert& v0, vert& v1, line& l ) { l.a = v1.y - v0.y; l.b = v0.x - v1.x; l.c = -(l.a * v0.x + l.b * v0.y); } v1 l v0 14/42

Point Inside Triangle Test Inside a triangle, if inside (to the left of) all 3 rays Back facing triangles are not rendered, since no points are to the left of all three rays v2 v1 v0 v1 v0 v2 Counter Clockwise (Facing Camera) Clockwise (Facing Away from Camera) 15/42

Pixel Center Inside Triangle Test rasterize( vert v[3] ) v0 { l2 l1 line l0, l1, l2; makeline(v[0],v[1],l2); v1 l0 v2 makeline(v[1],v[2],l0); makeline(v[2],v[0],l1); for( y=0; y<yres; y++ ) for( x=0; x<xres; x++ ) { e0 = l0.a * x + l0.b * y + l0.c; e1 = l1.a * x + l1.b * y + l1.c; e2 = l2.a * x + l2.b * y + l2.c; if( e0<=0 && e1<=0 && e2<=0 ) fragment(x,y); } } 16/42

Indeterminate Cases Edges that exactly touch pixels (e = 0) Pixels on a shared edge between two triangles are flagged by both triangles Wasted effort drawing duplicate fragments Problems for transparent objects Not including these pixels (i.e. using e < 0) causes gaps: 17/42

Indeterminate Cases Don t draw edges to the right and above each triangle/polygon (omit bold face segments and hollow points in these figures) int shadow( line l ) { return (l.a>0) (l.a == 0 && l.b > 0); } // normal points right vertical normal pointing up int inside( value e, line l ) { return (e == 0)?!shadow(l) : (e < 0); } // if e=0, don t shade shadow line 18/42

Pixel Center Inside Triangle Test rasterize( vert v[3] ) { l2 v0 l1 line l0, l1, l2; makeline(v[0],v[1],l2); v1 l0 v2 makeline(v[1],v[2],l0); makeline(v[2],v[0],l1); for( y=0; y<yres; y++ ) for( x=0; x<xres; x++ ) { e0 = l0.a * x + l0.b * y + l0.c; e1 = l1.a * x + l1.b * y + l1.c; e2 = l2.a * x + l2.b * y + l2.c; if( inside(e0,l0)&&inside(e1,l1)&&inside(e2,l2)) fragment(x,y); } } 19/42

Bounding Boxes 20/42

Bounding Box (rectangle) Inefficient to check every pixel on the screen Calculate a bounding box around the triangle, and only check pixels inside the box Round coordinates upward (ceil) to the nearest integer Test points with filled circles Don t test hollow circles bound3( vert v[3], bbox& b ) { b.xmin = ceil(min(v[0].x, v[1].x, v[2].x)); b.xmax = ceil(max(v[0].x, v[1].x, v[2].x)); b.ymin = ceil(min(v[0].y, v[1].y, v[2].y)); b.ymax = ceil(max(v[0].y, v[1].y, v[2].y)); } 21/42

Pixel Center Inside Triangle Test rasterize( vert v[3] ) { bbox b; bound3(v, b); line l0, l1, l2; makeline(v[0],v[1],l2); makeline(v[1],v[2],l0); makeline(v[2],v[0],l1); for( y=b.ymin; y<b.ymax, y++ ) for( x=b.xmin; x<b.xmax, x++ ){ e0 = l0.a * x + l0.b * y + l0.c; e1 = l1.a * x + l1.b * y + l1.c; e2 = l2.a * x + l2.b * y + l2.c; if( inside(e0,l0)&&inside(e1,l1)&&inside(e2,l2) ) fragment(x,y); } } 22/42

Lighting and Shading 23/42

Lighting & Shading We ignored lights and reflective properties of objects for now We ll cover this the week after next This means that you d get a 2D splatted cartoon view of your objects For example: a sphere turns into a 2D circle: So you will need a very simple light and a shader for the homework 24/42

OpenGL 25/42

OpenGL has more than triangles Images Bitmaps 26/42

OpenGl Pipeline Individual Vertices Transformed Vertices Commands Processor Per-vertex ops Primitive assembly triangles, lines, points, images Primitives Fragments Rasterization Texturing Per-fragment ops Shaded Fragments Framebuffer ops pixels in the framebuffer Display 27/42

Frame Buffering 28/42

Framebuffer Example Framebuffer: 1440 x 900 Viewport (256x256) The viewport is the portion of the window that can be drawn in, no pixels will appear outside the viewport Window (512 x 512) All coordinates are integers; they refer to pixel locations in the framebuffer 29/42

Frame Buffer Operations Operation Test window ownership Test scissor and stencil mask Test alpha (transparency) Test depth (z-buffer) Blending or compositing Textured Fragments Framebuffer Pixels 30/42

Depth Buffer (Z-Buffer) Initialize z-buffer to z max Interpolate z across the triangle Draw fragment, if it s closer if(frag.z<z[frag.x][frag.y]){ Z[frag.X][frag.Y]=frag.Z; C[frag.X][frag.Y]=frag.C; } http://en.wikipedia.org/wiki/file:z_buffer.svg 31/42

Frame Buffering Store image in a buffer to separate display refresh rate from drawing rate: Single-buffer Draw into display buffer directly May see picture being drawn Double-buffer Display front buffer Draw into back buffer (can t see drawing) Swap front and back (idle while waiting for vertical sync) Triple-buffer Avoid waiting for vertical sync 32/42

GPU (Machine Learning Too!) 33/42

Graphics Processing Unit OpenGL commands communicate with the GPU The GPU is designed to rapidly manipulate and alter memory to accelerate the building of images in a framebuffer In contrast, our ray tracer will be implemented on the CPU (although there are ray tracers that utilize the GPU, e.g. Nvidia Optix) NVIDIA s GeForce GTX 690 VisionTek Radeon 7970 34/42

What s in a GPU? Shader Core Shader Core Tex Primitive Assembly Rasterizer Shader Core Shader Core Tex Framebuffer Ops Shader Core Shader Core Tex Work Distributor Shader Core Shader Core Tex 35/42

PC 3.0 Ghz Intel Core2 Duo Core 1 Core 2 4MB L2 Cache 12.8 GB/sec 2GB main memory (DDR2) PCIe Bus (v1 = 4 GB/sec) System board (Intel D975) NVIDIA GeForce 8800 GTX (575 MHz) (16 cores) 84 GB/sec 512MB video Memory (GDDR3) NVIDIA 8800GTX 36/42

Xbox 360 controllers/ethernet/ audio/dvd/etc. 3.2 Ghz PowerPC CPU Core 1 Core 2 Core 3 IO Chip L2 Cache 500 Mhz ATI GPU 512 MB memory 48 3D Cores Frame buffer Video out Display (TV) 37/42

PS3 controllers/ethernet/ audio/dvd/etc. 3.2 Ghz Cell IO Chip PPC Core SPU0 SPU1 SPU2 SPU3 SPU4 SPU5 SPU6 SPU7 256 MB Memory L2 Cache (XDR) 550 Mhz NVIDIA RSX GPU Multiple 3D cores Video out 256 MB video Memory (GDDR3) Display (TV) 38/42

Hybrid CPU-GPUs Intel Sandybridge Apple A5 39/42

Question 1 Who is your partner? If you don t yet have one, let s take care of that now 40/42