Z- Buffer Store the depth for each pixel on the screen and compare stored value with depth of new pixel being drawn.

Similar documents
CHAPTER 1 Graphics Systems and Models 3

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

Clipping and Scan Conversion

Chapter 8: Implementation- Clipping and Rasterization

CS 130 Final. Fall 2015

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

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

Institutionen för systemteknik

COMPUTER GRAPHICS, MULTIMEDIA AND ANIMATION, Second Edition (with CD-ROM) Malay K. Pakhira

Course Title: Computer Graphics Course no: CSC209

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

Topics and things to know about them:

CS2401 COMPUTER GRAPHICS ANNA UNIV QUESTION BANK

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

An introduction to interpolation and splines

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

Realtime 3D Computer Graphics Virtual Reality

COMP3421. Vector geometry, Clipping

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

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

Models and Architectures

End-Term Examination

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

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

Example Examination 2IV

Perspective Mappings. Contents

Overview. By end of the week:

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

3D Polygon Rendering. Many applications use rendering of 3D polygons with direct illumination

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY CS2401 COMPUTER GRAPHICS QUESTION BANK

OXFORD ENGINEERING COLLEGE (NAAC Accredited with B Grade) DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING LIST OF QUESTIONS

COMP3421. Introduction to 3D Graphics

Graphics for VEs. Ruth Aylett

Drawing in 3D (viewing, projection, and the rest of the pipeline)

Midterm Exam Fundamentals of Computer Graphics (COMP 557) Thurs. Feb. 19, 2015 Professor Michael Langer

CS 130 Exam I. Fall 2015

Graphics for VEs. Ruth Aylett

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

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

Two-Dimensional Viewing. Chapter 6

Lecture 4. Viewing, Projection and Viewport Transformations

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

Introduction to Computer Graphics with WebGL

Computer Graphics I Lecture 11

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

Computer Graphics 7: Viewing in 3-D

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

Topics. From vertices to fragments

COMP371 COMPUTER GRAPHICS

CEng 477 Introduction to Computer Graphics Fall 2007

3D Rasterization II COS 426

QUESTION BANK 10CS65 : COMPUTER GRAPHICS AND VISUALIZATION

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

- Rasterization. Geometry. Scan Conversion. Rasterization

RASTERISED RENDERING

Hidden-Surface Removal.

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Computer Graphics CS 543 Lecture 13a Curves, Tesselation/Geometry Shaders & Level of Detail

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

CS 4620 Program 3: Pipeline

CMSC 435/634: Introduction to Graphics

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

Ray tracing. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 3/19/07 1

From 3D World to 2D Screen. Hendrik Speleers

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

Introduction to Visualization and Computer Graphics

Computer Graphics and GPGPU Programming

2D Image Synthesis. 2D image synthesis. Raster graphics systems. Modeling transformation. Vectorization. u x u y 0. o x o y 1

UNIT -8 IMPLEMENTATION

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Today. CS-184: Computer Graphics. Lecture #10: Clipping and Hidden Surfaces. Clipping. Hidden Surface Removal

Werner Purgathofer

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

CSE328 Fundamentals of Computer Graphics

Computer Graphics. The Two-Dimensional Viewing. Somsak Walairacht, Computer Engineering, KMITL

Midterm Exam! CS 184: Foundations of Computer Graphics! page 1 of 13!

COMP3421. Introduction to 3D Graphics

9. Visible-Surface Detection Methods

MET71 COMPUTER AIDED DESIGN

Advanced Lighting Techniques Due: Monday November 2 at 10pm

EF432. Introduction to spagetti and meatballs

CS 464 Review. Review of Computer Graphics for Final Exam

CS 4204 Computer Graphics

Pipeline Operations. CS 4620 Lecture 14

Computer Graphics I. Midterm Examination. October 23, This is a closed-book exam; only one double-sided sheet of notes is permitted.

Figure 1. Lecture 1: Three Dimensional graphics: Projections and Transformations

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

COMP3421. Introduction to 3D Graphics

UNIT 2 GRAPHIC PRIMITIVES

CS475/675: Computer Graphics End-Semester Examination (Solutions), Fall 2016

Visible Surface Detection Methods

CS602 Midterm Subjective Solved with Reference By WELL WISHER (Aqua Leo)

Rasterization Overview

Shadow Algorithms. CSE 781 Winter Han-Wei Shen

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

Hidden Surfaces II. Week 9, Mon Mar 15

4.5 VISIBLE SURFACE DETECTION METHODES

Transcription:

Andrew Lewis - Graphics Revision Keywords PIXEL FRAME BUFFER memory of the screen VIDEO - SCREEN - WINDOW - POLYGON filled area bound by straight lines SPLINE bit of wood used by draughtsmen to draw curves / wobbly line Clipping Box/ Cube 2D = Viewport 3D = Viewport + near, far clip planes Perspective Field of View Y (vertical camera angle) Aspect (window aspect ration) Near (near clip plane) Far (far clip plane) Hidden Surface Removal Painters algorithm draw what is at the back first and work forward till everything is drawn. i.e. draw the sky then the grass then a tree then a bird on the tree. Problems Inaccurate what if the bird is in the tree what should be drawn first? Slow, how should we sort the order things should be drawn in? Z- Buffer Store the depth for each pixel on the screen and compare stored value with depth of new pixel being drawn. Each pixel is being drawn anyway therefore there is just 1 new check and 1 new store for each pixel. Double Buffering Old graphics programs, single buffer see the individual items appearing. The idea, effectively 2 banks of memory, to simplify this I will say bank A and bank B. First bank A is on screen, so you don t see any drawing occurring you draw into bank B, once you finish drawing you tell the screen to use bank B. Now you draw

into bank A and once you finish drawing that you tell the screen to use bank A again etc. Means there is always a static picture on the screen, prevents flickering as frames change. Colour ADD HERE Line Drawing Vertical Straight forward for loop incrementing/decrementing y Horizontal - Straight forward for loop incrementing/decrementing x Diagonal Has a gradient (M) Has an offset from the origin (b) If the gradient is less than 1 i.e. y = M * x + b Step along x working out the y co-ordinate Can be sped up, points are equally spaced therefore instead of working out the y co-ordinate, after finding the first value adding M will get consecutive points y values. If the gradient is greater than 1 i.e. y = 2 * x + b Step along y working out the x co-ordinate Can be sped up, points are equally spaced therefore instead of working out the x each time can just add 1/M to get consecutive points. Bresenham Line Drawing We have our line y = M * x + b M = change in y / change in x = delta y / delta x = dy/dx

This means our original equation is y = dy/dx * x + b Multiplying out gives us dx y=dy x b dx dy x dx y b dx=0 a line can be represented like this so a x b y c=0 a=dy b= dx c=b dx Let dy = 0 (a horizontal line) dy * x dx * y + b *dx = 0 0 * x dx * y + b * dx = 0 (substitute 0 in) b * dx y * dx = 0 (throw away first term) dx * (b y) = 0 (tidyup) b y = 0 (divide by dx) if (y > b) then its ve and ABOVE the line if (y < b) then its +ve and BELOW the line if (y==b) then its on the line All the cases can be generalised to vertical / horizontal or this To see how this work we start drawing on the gray square. We have 2 choices, to blue or to green. Test roughly where the line will intersect the next square X+1 Y+0.5 d = a * x + b * y + c d = a * (x + 1) + b * (y+ 0.5) + c if (d<0) then X+=1, Y+=1 if (d>0) then X+=1 this can be used to draw the lines BUT

after we move it can be seen that d2 (the new d) x2,y2 x, y after moving if we move east blue x2 = x+1 y2 = y d2 = a * (x + 1 + 1) + b * (y + 0.5) + c d2 = a * x + 2* a + b * y + 0.5 * b + c now if we subtract the old d d = a * (x + 1) + b * (y+ 0.5) + c d = a * x + a + b * y + 0.5 * b + c d2-d = a * x + 2* a + b * y + 0.5 * b + c d2 d = a therefore if we move east we just need to add a to d to get the new d if we move northeast green x2 = x+1 y2 = y+1 d2 = a * (x + 1 + 1) + b * (y + 0.5 + 1) + c d2 = a * x + 2* a + b * y + 1.5 * b + c now if we subtract the old d d = a * (x + 1) + b * (y+ 0.5) + c d = a * x + a + b * y + 0.5 * b + c d2-d = a * x + 2* a + b * y + 1.5 * b + c d2 d = a + b therefore if we move east we just need to add a and b to d to get the new d looking back a = dy b = -dx To get an initial value for d to start this all of we go d = a * (x + 1) + b * (y+ 0.5) + c BUT we know 0 = a * x + b * y + c (as the first point HAS to be on the line) so we can subtract this from the starting point to get d = a + 0.5 * b we can even get rid of the 0.5 * b as all we need to know is d relative to 0 if we just double what we add to it we can do this d = 2 * a + b

SO SUMMARY a = dy b = -dx Start d = 2 * dy dx east = 2 * dy northeast = 2 * dy 2 * dx while not at end { if (d>0) { d+=east x++; } else if (d<0) { d+=northeast x++; y++; } plot x, y } Flood Fill -Recursive easy Edge Coherence Polygon Filling NEED TO FINISH XY Algorithm NEED TO FINISH Converting Polygon to Triangles (See notes) Find left most vertex min(x) min(y) Generate triangle from 2 adjacent verticies if no points inside then cut off as new triangle else make new triangle with left most point and the leftmost of the inside points. Bi-Liner Interpolation Stretches / Skews a texture across a polygon.

How This is just working in X, just do the same for Y we have width of texture T_left, T_right we have width of polygon at this point P_left P_right we have out position on the polygon P_pos get the width Texture_Width = T_right T_left Polygon_Width = P_right P_left calculate the scaling factor Scale_Factor = Texture_Width / Polygon_Width calulate how far we our into the polygon Position_Offset = P_pos - P_left Calulate where this is on the texture Texture_Pos = Scale_Factor * Position_Offset Finally the left hand side Position_in_Image = Texture_Pos + T_Left So putting this togethor Position_in_Image = ((T_right T_left) / (P_right P_left)) * (P_pos P_left) + T_left

Now from that it can be seen as P_pos increments by 1 each time the only change is multiplying the scale_factor by 1 more. Therefore if we calculate the initial Position we can just add the scale_factor each time after that. Illustration 1Bi-Linear Filtering Example with Speedup Clipping Cohen-Sutherland Line-Clipping IMPORTANT HE HAS AN ERROR IN THIS SECTION Compute the outcodes 1001 1000 1010 0001 0000 0010 0101 0100 0110 If OR of the end point outcodes = 0 then line is fully inside if AND of the end point outcodes > 0 then lines is fully outside else calulate an intersection(you know what sides to test) then retest the end NOTE line doesn't have to be inside ATALL (he says it means it has to cross) proof what if a line went from 0100 to 0010 crossing 0110 NOT 0000 Liang-Barsky Algorithm

Choose a vertex on the polygon as a start point find out if its inside or outside the rectangle that is being clipped to. Loop around the rest of the polygon looking at each segment 4 things we can do Inside - Add entire line Going out Add start calculate intersection for new end Outside throw away Going in Calculate intersection for new start and add end 2D/3D Transformations Homogeneous Co-ordinates x, y, w proper x = x/w proper y = y/w Why? Introduce the concept of infinity VERY useful for maths stuff i.e. As w approaches 0 proper x,y approach infinity Transformations 2D Translate x, y Scale x,y Rotate phi [1 0 x 0 1 y 0 0 [x 0 0 0 y 0 0 0 [cos sin 0 sin cos 0 0 0 3D Translate x,y,z Scale x,y,z [1 0 0 x 0 1 0 y 0 0 1 z 0 0 0 [x 0 0 0 0 y 0 0 0 0 z 0 0 0 0

Rotate about z Rotate about x [cos sin 0 0 sin cos 0 0 0 0 1 0 0 0 0 [1 0 0 0 0 cos sin 0 0 sin cos 0 0 0 0 [ cos 0 sin 0 0 1 0 0 Rotate about y sin 0 cos 0 0 0 0 Projections Parallel [1 0 0 0 0 1 0 0 Throw away the z keep everything else 0 0 0 0 0 0 0 Orthographic Oblique Perspective Not 100% sure about this Method one [1 0 0 0 0] 0 1 0 0 0 0 1 0 0 0 1/ d then divide though by the w value each time Method two [1 0 0 0 0 1 0 0 0 0 0 0 0 0 1/ d How OPENGL Works 2 Main Matricies Projection Matrix - this says how the world is viewed by the camera Setup using glfrustrum and glortho

Modelview Matrix this says how the current item is transformed To render a point multiply it by the modelview then the projection matrix then x,y will be point pos and z will be depth. BSP Trees Lighting Ambient Diffuse Ray tracing Splines Continuity End of first curve = beginning of next Smoothness Gradient of first curve = gradient of next f1(a) = f2(a) f1 (A) = f2 (A) Cubic sections CANT USE y=ax 3 + bx 2 + cx + d Parametric form X(t) = a x t 3 + b x t 2 + c x t + d x Y(t) = a y t 3 + b y t 2 + c y t + d y Interpolating 3D obvious just have x,y,z a x, a y, b x, b y, c x, c y, d x, d y are the control variables see notes Control points Hermite Curves Ends of curve and the vectors for the gradient at the ends P1,P2 = end points R1,R2 = gradients (vectors from end points) Bezier Curves P1,P4 = end points P2,P3 = control points R1 = 3*(P2-P1)

R2= 3*(P4-P3) Blending Matrix [ 1 3 3 1 0] 3 6 3 0 3 3 0 0 1 0 0 See notes for example of usage Where the blending matrix comes from probably not needed Work out the numbers there will be of each co-efficient M = Blending Matrix G = Control Points X(t) = a x t 3 + b x t 2 + c x t + d x We know the end conditions t=0 X(0) = P1 x = (0, 0, 0, 1) * M * G x t=1 X(0) = P1 x = (1, 1, 1, 1) * M * G x We know the gradients dx/dt = 3a x t 2 + 2b x t + c x dx/dt (0) = R1 x = (0, 0, 1, 0) * M * G x dx/dt (1) = R2 x = (3, 2, 1, 0) * M * G x therefore we know [ P 1 0 0 1 P 4 1 1 1 1 P 2 3 P 2 P 1 0 0 1 0 P 3 3 P 4 P 3 ]=[0 3 2 1 0] M [P1 4] P Same as [ 1 0 0 0 0 0 1 0 0 0 1 P 2 1 1 1 1 P 2 3 3 0 0 P 3 0 0 1 0 P 3 0 0 3 3] [P1 P 4]=[0 3 2 1 0] M [P1 4] P Post multiply both sides by the inverse of the 3 rd one

[0 0 0 1 1 1 1 1 0 0 1 0 3 2 1 0] 1 [ 1 0 0 0 0 0 0 1 P 2 3 3 0 0 P 3 0 0 3 3] [P1 0 0 1 1 1 1 1 0 0 1 0 P 4]=[0 3 2 1 0] 1 observation shows [0 0 0 1Simple 1 1 1 1 0 0 1 0 3 2 1 0] 1 [ 1 0 0 0 0 0 0 0 0 0 1 P 2 0 1 0 0 P 2 3 3 0 0 P 3 0 0 1 0 P 3 0 0 3 3] [P1 P 4]=[1 0 0 0 M [P1 4] P so [0 0 0 1And 1 1 1 1 0 0 1 0 3 2 1 0] 1 [ 1 0 0 0 0 0 0 1 P 2 P 2 3 3 0 0 P 3 P 3 0 0 3 3] [P1 P 4]=M [P1 4] P More calculation shows, then [ 1 3 3 1 3 6 3 0 P 2 P 2 3 3 0 0 P 3 P 3 1 0 0 0] [P1 P 4]=M [P1 4] [ 1 P How to Draw them Bezier curve can easily be split into 2 Original Curve P1,P2,P3,P4 new Curves h = (P2 + P3)/2 L1 = P1 L2 = (P1 + P2) / 2 L3 = (h + L2)/2 L4 = R1 = (L3 + R2) / 2 R2 = (h + R3)/2 R3 = (P3 + P4)/2 R4 = P4 [0 0 0 1 1 1 1 1 0 0 1 0 P 3 3 2 1 0] M [P1 3 3 1 3 6 3 0 3 3 0 0 1 0 0 0]=M Stop when All control points same value ie its a point All control points in a line P 2 4] P

And another??? Bezier surfaces same principals as Bezier Curve but in 3D