Hank Childs, University of Oregon October 3, 2014 CIS 441/541: Intro to Computer Graphics Lecture 2: The Scanline Algorithm.

Slides:



Advertisements
Similar presentations
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Advertisements

Hank Childs, University of Oregon Oct. 22 nd, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 7: Arbitrary Camera Positions.
3D Graphics Rendering and Terrain Modeling
Hank Childs, University of Oregon November 15 th, 2013 Volume Rendering, Part 2.
Bit Depth and Spatial Resolution SIMG-201 Survey of Imaging Science © 2002 CIS/RIT.
CS248 Midterm Review. CS248 Midterm Mon, November 4, 7-9 pm, Terman Aud Mostly “short answer” questions – Keep your answers short and sweet! Covers lectures.
Sep 21, Fall 2005ITCS4010/ Computer Graphics Overview Color Displays Drawing Pipeline.
Graphics Programming: Polygon Filling
CS248 Midterm Review Szymon Rusinkiewicz. CS248 Midterm Monday, November 1, 7-9 pm Gates B01 and B03 Designed to be 1-hour exam Mostly “short answer”
CS248 Midterm Review. CS248 Midterm Mon, November 3, 7-9 pm, Gates B01 Mostly “short answer” questions – Keep your answers short and sweet! Covers lectures.
1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion.
Image representation using arrays Image processing examples
Graphics File Formats. 2 Graphics Data n Vector data –Lines –Polygons –Curves n Bitmap data –Array of pixels –Numerical values corresponding to gray-
CS248 Midterm Review Michael Green and Sean Walker (based on the work of previous TAs)
Sep 21, Fall 2006IAT 4101 Computer Graphics Overview Color Displays Drawing Pipeline.
IAT 3551 Computer Graphics Overview Color Displays Drawing Pipeline.
2.01 Understand Digital Raster Graphics
3-D RENDERING Peter Moore Jackson Cwach. What 3-D Rendering is 3D rendering is the 3D computer graphics process of automatically converting 3D wire frame.
1 Internet Graphics. 2 Representing Images  Raster Image: Images consist of “dots” of color, not lines  Pixel: Picture element-tiny rectangle  Resolution:
1 Ethics of Computing MONT 113G, Spring 2012 Session 11 Graphics on the Web Limits of Computer Science.
Basics of Rendering Pipeline Based Rendering –Objects in the scene are rendered in a sequence of steps that form the Rendering Pipeline. Ray-Tracing –A.
COMP 175: Computer Graphics March 24, 2015
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
Hank Childs, University of Oregon October 1, 2014 CIS 441/541: Introduction to Computer Graphics.
COSC 1P02 Intro. to Computer Science 6.1 Cosc 1P02 Week 6 Lecture slides "To succeed, jump as quickly at opportunities as you do at conclusions." --Benjamin.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 14 Introduction to Computer Graphics.
Higher Computing Computer Systems S. McCrossan 1 Higher Grade Computing Studies 1. Data Representation Data Representation – Why do we use binary? simplicity,
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Computer Graphics An Introduction. What’s this course all about? 06/10/2015 Lecture 1 2 We will cover… Graphics programming and algorithms Graphics data.
© 1999 Rochester Institute of Technology Introduction to Digital Imaging.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
CS 638, Fall 2001 Today Project Stage 0.5 Environment mapping Light Mapping.
Taku KomuraComputer Graphics Local Illumination and Shading Computer Graphics – Lecture 10 Taku Komura Institute for Perception, Action.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
The Rendering Pipeline CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
Hank Childs, University of Oregon Oct. 10, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 4: Interpolating Colors and the Z-buffer.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Graphics An image is made up of tiny dots called pixels (“picture elements”) The resolution determines the.
Hank Childs, University of Oregon Lecture #4 Fields, Meshes, and Interpolation (Part 3)
Hank Childs, University of Oregon Lecture #3 Fields, Meshes, and Interpolation (Part 2)
Lecture 7: Intro to Computer Graphics. Remember…… DIGITAL - Digital means discrete. DIGITAL - Digital means discrete. Digital representation is comprised.
Data Representation The storage of Text Numbers Graphics.
DIGITAL IMAGE. Basic Image Concepts An image is a spatial representation of an object An image can be thought of as a function with resulting values of.
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
Hank Childs, University of Oregon Unstructured Grids.
Hank Childs, University of Oregon Volume Rendering, pt 1.
Local Illumination and Shading
MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Line Clipping & Line Rasterization.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
OpenGL and You I Cast, Therefore I Am. Ray Casting Idea is simple, implementation takes some work –Cast rays as if you were the camera –Determine intersection.
Information in Computers. Remember Computers Execute algorithms Need to be told what to do And to whom to do it.
Graphics Basic Concepts 1.  A graphic is an image or visual representation of an object.  A visual representation such as a photo, illustration or diagram.
Hank Childs, University of Oregon April “29 th”, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / /
Hank Childs, University of Oregon September 26, 2016 CIS 441/541: Introduction to Computer Graphics.
AP CSP: Pixelation – B&W/Color Images
Hank Childs, University of Oregon
Binary Representation in Audio and Images
Week 2 - Friday CS361.
Hank Childs, University of Oregon
Hank Childs, University of Oregon
Hank Childs, University of Oregon
CS451Real-time Rendering Pipeline
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
CSCE 441: Computer Graphics Hidden Surface Removal
Lecture 13 Clipping & Scan Conversion
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
Hank Childs, University of Oregon
Visuals are analog signals...
Presentation transcript:

Hank Childs, University of Oregon October 3, 2014 CIS 441/541: Intro to Computer Graphics Lecture 2: The Scanline Algorithm

Outline Project 1A Scanline Algorithm Project 1B Tips on floating point precision

Outline Project 1A Scanline Algorithm Project 1B Tips on floating point precision

Project #1A Goal: write a specific image Due: 11:59pm, Oct. 4th … in 84 hours (!) % of grade: 2% Q: Why do I only get 3 1/2 days to complete this project? A: We need to need to get multi-platform issues shaken out ASAP. May be a little painful

Project #1A: background Definitions: – Image: 2D array of pixels – Pixel: A minute area of illumination on a display screen, one of many from which an image is composed. Pixels are made up of three colors: Red, Green, Blue (RGB) Amount of each color scored from 0 to 1 – 100% Red + 100% Green + 0% Blue = Yellow – 100% Red + 0% Green %Blue = Purple – 0% Red + 100% Green + 0% Blue = Cyan – 100% Red + 100% Blue + 100% Green = White

Project #1A: background Colors are 0->1, but how much resolution is needed? How many bits should you use to represent the color? – Can your eye tell the difference between 8 bits and 32 bits? –  No. Human eye can distinguish ~10M colors. – 8bits * 3 colors = 24 bits = ~16M colors. Red = (255,0,0) Green = (0,255,0) Blue = (0,0,255)

Project #1A: background An “M by N” 8 bit image consists of MxNx3 bytes. – It is stored as: P0/R, P0/G, P0/B, P1/R, P1/G, P1/B, … P(MxN)/R, P(MxN)/G, P(MxN)/B P0 is the bottom, left pixel P(M-1) is the bottom, right pixel P((MxN)-M+1) is the top, left pixel P(MxN) is the top, right pixel

What is the image I’m supposed to make? R=0 R=128 R=255 (0,0,0) (0,0,128) (0,0,255) (0,128,0) (0,128,128) (0,128,255) (0, 255, 0) (0, 255, 128) (0,255,255) (128, 0, 0) (128,0,128) (255, 0, 0) (255,255,255) (128,255,255)

What do I do again? Install CMake & VTK. Download “project1A.cxx” from class website Download “CMakeLists.txt” from class website Run CMake Modify project1A.cxx to complete the assignment And… Submit the source and image to Blackboard by Saturday midnight.

Outline Project 1A Scanline Algorithm Project 1B

Reminder: ray-tracing vs rasterization Two basic ideas for rendering: rasterization and ray-tracing Ray-tracing: cast a ray for every pixel and see what geometry it intersects. – O(nPixels) (actually, additional computational complexity for geometry searches) – Allows for beautiful rendering effects (reflections, etc) – Will discuss at the end of the quarter

Reminder: ray-tracing vs rasterization Two basic ideas for rendering: rasterization and ray-tracing Rasterization: examine every triangle and see what pixels it covers. – O(nTriangles) (actually, additional computational complexity for painting in pixels) – GPUs do rasterization very quickly – Our focus for the next 5 weeks

What color should we choose for each of these four pixels?

Most dominant triangle What color should we choose for each of these four pixels?

Average What color should we choose for each of these four pixels?

Pixel center What color should we choose for each of these four pixels?

Lower left of pixel What color should we choose for each of these four pixels?

The middle and lower-left variants are half-pixel translations of the other Pixel center Lower left of pixel This is the convention we will use for the projects.)

Where we are… We haven’t talked about how to get triangles in position. – Arbitrary camera positions through linear algebra We haven’t talked about shading Today, we are tackling this problem: How to deposit triangle colors onto an image?

Problem: how to deposit triangle colors onto an image? Let’s take an example: – 12x12 image – Red triangle Vertex 1: (2.5, 1.5) Vertex 2: (2.5, 10.5) Vertex 3: (10.5, 1.5) Vertex coordinates are with respect to pixel locations

(0,0)(12,0) (12,12)(0,12) (2.5,10.5) (2.5,1.5)(10.8,1.5)

Our desired output How do we make this output? Efficiently?

Don’t need to consider any Pixels outside these lines

Scanline algorithm: consider all rows that can possibly overlap Don’t need to consider any Pixels outside these lines

Scanline algorithm: consider all rows that can possibly overlap Don’t need to consider any Pixels outside these lines We will extract a “scanline”, i.e. calculate the intersections for one row of pixels X X X X X Y=5

– Red triangle Vertex 1: (2.5, 1.5) Vertex 2: (2.5, 10.5) Vertex 3: (10.5, 1.5)

– Red triangle Vertex 1: (2.5, 1.5) Vertex 2: (2.5, 10.5) Vertex 3: (10.5, 1.5) Y=5

– Red triangle Vertex 1: (2.5, 1.5) Vertex 2: (2.5, 10.5) Vertex 3: (10.5, 1.5) Y=5 What are the end points?

– Red triangle Vertex 1: (2.5, 1.5) Vertex 2: (2.5, 10.5) Vertex 3: (10.5, 1.5) Y=5 What are the end points? (2.5, 5)

– Red triangle Vertex 1: (2.5, 1.5) Vertex 2: (2.5, 10.5) Vertex 3: (10.5, 1.5) Y=5 What are the end points? (2.5, 5) Algebra!

– Red triangle Vertex 1: (2.5, 1.5) Vertex 2: (2.5, 10.5) Vertex 3: (10.5, 1.5) – Y = mx+b – 10.5=m*2.5+b – 1.5 = m*10.5+b –  – 9 = -8m – m = – b = – 5 = *x – x = Y=5 What are the end points? (2.5, 5) Algebra!

Scanline algorithm: consider all rows that can possibly overlap Don’t need to consider any Pixels outside these lines X X X X X Y=

Scanline algorithm: consider all rows that can possibly overlap Don’t need to consider any Pixels outside these lines X X X X X Y= Color is deposited at (3,5), (4,5), (5,5), (6,5), (7,5)

Scanline algorithm Determine rows of pixels triangles can possibly intersect – Call them rowMin to rowMax rowMin: ceiling of smallest Y value rowMax: floor of biggest Y value For r in [rowMin  rowMax] ; do – Find end points of r intersected with triangle Call them leftEnd and rightEnd – For c in [ceiling(leftEnd)  floor(rightEnd) ] ; do ImageColor(r, c)  triangle color

Scanline algorithm Determine rows of pixels triangles can possibly intersect For r in [rowMin  rowMax] ; do – Find end points of r intersected with triangle Call them leftEnd and rightEnd – For c in [ceiling(leftEnd)  floor(rightEnd) ] ; do ImageColor(r, c)  triangle color Y values from 1.5 to 10.5 mean rows 2 through 10 For r = 5, leftEnd = 2.5, rightEnd = For r = 5, we call ImageColor with (5,3), (5,4), (5,5), (5,6), (5,7)

Arbitrary Triangles The description of the scanline algorithm in the preceding slides is general. But the implementation for these three triangles vary:

Supersamping: use the scanline algorithm a bunch of times to converge on the “average” picture.

Where we are… We haven’t talked about how to get triangles into position. – Arbitrary camera positions through linear algebra We haven’t talked about shading Today, we tackled this problem: How to deposit triangle colors onto an image? Still don’t know how to: 1)Vary colors (easy) 2)Deal with triangles that overlap

Outline Project 1A Scanline Algorithm Project 1B Tips on floating point precision

Arbitrary Triangles You will implement the scanline algorithm for triangles with “flat bottoms”

Project #1B Goal: apply the scanline algorithm to “flat bottom” triangles and output an image. File “project1B.cxx” has triangles defined in it. Due: Weds, Oct. 8th % of grade: 6%

Project #1C You will implement the scanline algorithm for arbitrary triangles … plan ahead

Outline Project 1A Scanline Algorithm Project 1B Tips on floating point precision

Project 1B  Cout/cerr can be misleading:

Project 1B  The limited accuracy of cerr/cout can cause other functions to be appear to be wrong:

Project 1B  Floating point precision is an approximation of the problem you are trying to solve  Tiny errors are introduced in nearly every operation you perform  Exceptions for integers and denominators that are a power of two  Fundamental problem:  Changing the sequence of these operations leads to *different* errors.  Example: (A+B)+C ≠ A+(B+C)

Project 1B  For project 1B, we are making a binary decision for each pixel: should it be colored or not?  Consider when a triangle vertex coincides with the bottom left of a pixel:  We all do different variations on how to solve for the endpoints of a line, so we all get slightly different errors.

Project 1B  Our algorithm incorporates floor and ceiling functions.  This is the right place to bypass the precision problem.  I have included “floor441” and “ceil441” in project prompt. You need to use them, or you will get one pixel differences.

Project 1B: other thoughts  You will be building on this project …  think about magic numbers (e.g. screen size of 1000)  add safeguards against cases that haven’t shown up yet  Assume nothing!