PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science

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

UNIT -8 IMPLEMENTATION

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

Einführung in Visual Computing

GEOMETRIC OBJECTS AND TRANSFORMATIONS I

Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

QUESTION BANK 10CS65 : COMPUTER GRAPHICS AND VISUALIZATION

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

Building Models. Objectives. Introduce simple data structures for building polygonal models. OpenGL vertex arrays. Vertex lists Edge lists

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

CHAPTER 1 Graphics Systems and Models 3

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

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

Topics. From vertices to fragments

Models and Architectures

CS 130 Final. Fall 2015

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

Chapter - 2: Geometry and Line Generations

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

Computer Graphics and GPGPU Programming

Realtime 3D Computer Graphics Virtual Reality

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

UNIT 4 GEOMETRIC OBJECTS AND TRANSFORMATIONS-1

Clipping and Scan Conversion

Display Lists. Conceptually similar to a graphics file. In client-server environment, display list is placed on server

Introduction to Computer Graphics with WebGL

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

Graphics (Output) Primitives. Chapters 3 & 4

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

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

From Ver(ces to Fragments: Rasteriza(on

Rasterization: Geometric Primitives

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

CS Rasterization. Junqiao Zhao 赵君峤

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

Pipeline implementation II

Chapter 8: Implementation- Clipping and Rasterization

Rasterization. Rasterization (scan conversion) Digital Differential Analyzer (DDA) Rasterizing a line. Digital Differential Analyzer (DDA)

CSCI 4620/8626. Coordinate Reference Frames

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

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

Hidden-Surface Removal.

Werner Purgathofer

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

Painter s HSR Algorithm

UNIT 2 GRAPHIC PRIMITIVES

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

Line Drawing. Foundations of Computer Graphics Torsten Möller

CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

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

CS 4620 Midterm, March 21, 2017

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 498 VR. Lecture 18-4/4/18. go.illinois.edu/vrlect18

CS 4620 Program 3: Pipeline

Topics and things to know about them:

Homework #2. Hidden Surfaces, Projections, Shading and Texture, Ray Tracing, and Parametric Curves

2D Drawing Primitives

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

Pipeline Operations. CS 4620 Lecture 10

Graphics Pipeline 2D Geometric Transformations

COMP371 COMPUTER GRAPHICS

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

window World space (Object space)

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by:

Computer Graphics: Line Drawing Algorithms

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

Scan Conversion. Drawing Lines Drawing Circles

The Traditional Graphics Pipeline

Topic #1: Rasterization (Scan Conversion)

Computer Graphics and Visualization. Graphics Systems and Models

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

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

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

5.8.3 Oblique Projections

The Traditional Graphics Pipeline

Pipeline and Rasterization. COMP770 Fall 2011

3D Rasterization II COS 426

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY CS2401 COMPUTER GRAPHICS QUESTION BANK

3D Graphics and OpenGl. First Steps

Institutionen för systemteknik

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

Texture Mapping. Texture (images) lecture 16. Texture mapping Aliasing (and anti-aliasing) Adding texture improves realism.

lecture 16 Texture mapping Aliasing (and anti-aliasing)

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

Rasterization. CS4620 Lecture 13

Course Title: Computer Graphics Course no: CSC209

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm

Reading. 18. Projections and Z-buffers. Required: Watt, Section , 6.3, 6.6 (esp. intro and subsections 1, 4, and 8 10), Further reading:

The Traditional Graphics Pipeline

CS 543: Computer Graphics. Rasterization

Homework #2 and #3 Due Friday, October 12 th and Friday, October 19 th

CS 130 Exam I. Fall 2015

The Rendering Pipeline (1)

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

Drawing Fast The Graphics Pipeline

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

From Vertices To Fragments-1

Transcription:

INTERNAL ASSESSMENT TEST 2 Solution Date : 30.03.15 Max Marks : 50 Subject & Code : Computer Graphics and Visualization/10CS65 Section : A, B and C Name of faculty : Ms. Sarasvathi V/ Ms. Archana Time : 8:30 10:00am Answer All Five Questions 1. Use Liang Barsky line clipping algorithm to clip a line from starting point (30, 15) and ending point (65, 35) against the window having its lower left corner at (40, 10) and upper right corner at (75, 25). P1= 35 q1= 10 P2= 35 q2=45 P3= 20 q3 = 5 P4= 20 q4= 10 t1= 0.285 t2= 1.28 t3= 0.25 t4= 0.5 T1= Max(0.285, 0.25)= 0.285 since for these values p <0 T2= min(1.28,0.5)= 0.5 since for thse values P>0 Xx1,yy1= (40,20.714) Xx2,yy2 =( 47.5,25) 2. Explain the Bresenham s line rasterization algorithm. 10 An accurate, efficient raster line drawing algorithm developed by Bresenham, scan converts lines using only incremental integer calculations that can be adapted to display circles and other curves.efficient compared to DDA algorithm because it avoid round functions. m < 1 Samples a line by incrementing by one either x or y depending on the slope of the line. Starting from the left end point (xk,yk) of a given line. Assuming we have determined that the pixel at (xk,yk) is to be displayed, we next need to decide which pixel to plot in column xk+1.

At sampling position xk+1,we Label the vertical pixel separation from mathematical line path d1 and d2. y coordinate on the math line at pixel column position xk+1 is calculated as y=m(xk+1)+b d1=y yk =m(xk+1)+b yk d2= (yk+1) y = yk+1 m(xk+1) b The difference between these 2 separations is Substitute m= Δy/ Δx in the above equation You will get Δx ( d1 d2) =2Δyxk 2 Δxyk + c We call this Δx ( d1 d2) as decision parametr pk Define Pk = Δx ( d1 d2) = 2Δyxk 2 Δxyk + c The sign of Pk is the same as the sign of d1 d2, since Δx > 0. Parameter c is a constant and has the value 2Δy + Δx(2b 1) (independent of pixel position). If pixel at yk is closer to line path than pixel at yk +1 (i.e, if d1 < d2) then pk is negative. We plot lower pixel in such a case. Otherwise, upper pixel will be plotted. If pk<0 then d1<d2 hence choose xk+1,yk If pk>0 then d1>d2 hence choose xk+1,yk+1 At step k + 1, the decision parameter can be evaluated as, pk+1 = 2Δyxk+1 2Δxyk+1 + c Taking the difference of pk+ 1 and pk we get the following. pk+1 pk = 2Δy(xk+1 xk) 2Δx(yk+1 yk)

But, xk+1 = xk +1, so that pk+1 = pk + 2Δy 2 Δx(yk+1 yk) Where the term yk+1 yk is either 0 or 1, depending on the sign of parameter pk The first parameter p0 is directly computed p0 = 2 Δyxk 2 Δxyk + c = 2 Δyxk 2 Δxyk +2 Δy + Δx (2b 1) Since (x0,y0) satisfies the line equation, we also have y0 = Δy/ Δx * x0 + b Combining the above 2 equations, we will have p0 = 2Δy Δx The constants 2Δy and 2Δy 2Δx are calculated once for each time to be scan converted Algorithm 1.Input the two end points and store the left end point in (x0,y0) 2.Load (x0,y0) into the frame buffer (plot the first point) 3.Calculate the constants Δx, Δy, 2Δy and 2Δy 2Δx and obtain the starting value for the decision parameter as p0 = 2Δy Δx 4.At each xk along the line, starting at k=0, perform the following test: If pk < 0, the next point is (xk+1, yk) and pk+1 = pk + 2Δy Otherwise 5.Point to plot is (xk+1, yk+1) pk+1 = pk + 2Δy 2Δx 6.Repeat step 4 (above step) Δx times 3. With regard to modeling a color cube discuss the following: 10 i) Data structures for object representation. ii) Bilinear interpolation

iii) Vertex array Data structures for object representation We could use glbegin(gl_polygon) Six times, each followed by four vertices(via glvertex) and glend. or we could use glbegin(gl_quads) Followed by 24 vertices and a glend. Both they fail to capture the essence of the cube s topology. Instead of this both method we are using vertex list. Cube is composed of six faces.the faces are each quadrilaterals that meet at vertices.each vertex is shared by three faces.each edge is shared by two faces. 1 5 6 4 2 7 0 3 VERTEX LIST REPRESENTATION OF A CUBE Polygon Faces Vertex lists Vertices CUBE A B C D E F 0 3 2 1 3 7 6 2 X0,Y0 X1,Y1 X2,Y2 X3,Y3 X4,Y4 X5,Y5 X6,Y6 X7,Y7 The data specifying the location of the vertices contain the geometry and can be stored as a simple list or array, such as in vertices[8] the vertex list. The top level entity is a cube.it is composed of six faces. Each face consists of four ordered vertices.each vertex can be specified indirectly through its index. Advantage Each geometric location appears only once,instead of being repeated each time it is used for a facet. If location of a vertex is changed,the application needs to change that location only once rather than searching for multiple occurrences of the vertex.

Bilinear interpolation We have specified colors for the vertices of the cube. There are many ways to use the colors of the vertices to fill in,or interpolate, colors across a polygon. interpolation is a method of constructing new data points within the range of a discrete set of known data points. Consider the polygon. The colors c0,c1,c2,c3 are the ones assigned to the vertices in the application program. Interpolation is applied individually to each primary color. First use linear interpolation to interpolate colors,along the edges between vertices 0 and 1,and between 2 and 3,creating RGB colors along the edges through the parametric equation as follows: C 01 (α) C 0 C 4 C 1 C 45 (β) C 3 C 5 C 2 C 23 (β) C01(α)= (1 α)c0 + αc1 C23(α) =(1- α)c2+ αc3 As α goes from 0 to 1,we generate colors, C01(α) and c23(α),along these two edges. For a given value of α,we obtain two colors,c4 and C5,on these edges. C45(β) = (1- β)c4+ βc5 If the four vertices are not all in the same plane,its location on a surface is not clearly defined. Avoid this problem by breaking up the quadrilateral into two triangles, and interpolaing colors across each triangle. Vertex array Vertex arrays provide a method for encapsulating the information in our data structure such that we can draw polyhedral objects with only a few function calls. Three steps We enable the functionality of vertex array We tell OpenGL where and what format the arrays are. We render the object First two steps can be part of the initialization The third is part of the display callback

For our rotating cube,we need only colors and vertices.we enable corresponding arrays as follows: glenableclientstate(gl_color_array); glenableclientstate(gl_vertex_array); The arrays are same as before: GLfloat vertices[8][3] = {{-1.0,-1.0,-1.0}, {1.0,- 1.0,-1.0}, {1.0,1.0,-1.0},{-1.0,1.0,-1.0},{-1.0,- 1.0,1.0}, {1.0,-1.0,1.0}, {1.0,1.0,1.0},{- 1.0,1.0,1.0}}; GLfloat colors[8][3] ={{0.0,0.0,0.0}, {1.0,0.0,0.0}, {1.0,1.0,0.0}, {0.0,1.0,0.0},{0.0,0.0,1.0},{1.0,0.0,1.0}, {1.0,1.0,1.0},{0.0,1.0,1.0}}; We identify where the arrays are as follows: glvertexpointer(3,gl_float,0,vertices); glcolorpointer(3,gl_float,0,colors); first argument- the elements are 3D color Second argument- vertices are stored as floats Third- the elements are contiguous in the array. Fourth- pointer to the array holding the data. Specify the an array that holds the 24 ordered vertex indices for the six faces: GLUbyte cubeindices[24] ={0,3,2,1,2,3,7,6,0,4,7,3,1,2,6,5,4,5,6,7,0,1,5,4} gldrawelements(glenum type,glsizei n,glenum format,void *pointer) Type is the type of element,such as line or polygon n- no of elements that we wish to draw. Format-form of the data in the index array. Pointer- pointer points to first index to use. For our cube,within the display callback we could make six calls to gldrawelements,one for each of the face for(i=0;i<6;i++) gldrawelements(gl_polygon,4,gl_unsigned_b YTE,&cubeIndices[4*i]); We use GL_QUADS rather than GL_POLYGON,we can draw the cube with the single function call gldrawelements(gl_quad,24,gl_unsigned_byte,cubeindices) 4 a. What are Homogenous co ordinates, how they are represented. 4 Homogeneous coordinates Homogeneous coordinates avoid this difficulty by using a four dimensional representation for both points and vectors in three dimensions. ( x,y,z,p 0 ) v = [a1 a2 a3 0 ] T p = [b1 b2 b3 1 ] T 4b. Explain the Z buffer hidden surface removal algorithm. 6 It is most widely used hidden surface removal algorithm.

Easy to implement in either hardware or software. Algorithm works in image space approaches. Suppose we are in process of rasterizing one of the two polygons. We can compute a color for each point of intersection. we must check whether this point is visible. It will be visible if it is closest point of intersection along the ray. Initially each element in the depth buffer is initialized to a depth corresponding to the maximum distance away from the center of projection. During rasterization, store closest intersection point in z buffer Calculation For each fragment on the polygon,we compute the depth from cop. Compare this depth to the value in the z buffer. If this depth is greater than the depth in the z buffer,then we have already processed a polygon with corresponding polygon this fragment is not visible. If the depth is less than the depth in the z buffer then we have found a fragment closer to the viewer We Update the depth in the z buffer and place the shade computed for this fragment at the corresponding location in the framebuffer. The polygon is part of a plane that can be represented as ax+by+cz+d=0 suppose that(x1,y1,z1) and (x2,y2,z2) are two points on the polygon if Δx=x2 x1; Δy=y2 y1 Δz=z2 z1 If we work scan line by scan line as we move across a scan line, the depth changes satisfy aδx+bδy+cδz=0 Along scan line

Δy = 0 Δz = a Δx/c In screen space Δx = 1 This value is contant that needs to be computed only once for each polygon. 5. Write a short note on: 1) Aliasing and Antialiasing techniques. 5 Rasterized line segments and edges of polygons often look like jagged. In low resolution screen the line appears like a stair case appearance. This effect is known as aliasing. To minimize the effect of aliasing and improve the appearance of displayed raster lines. Antialising by area averaging spatial domain aliasing we shade each box by the percentage of the ideal line that crosses it. we get smoother appearing image. Suppose a pixel shared by three polygons. If each polygon has a different color, the color assigned to the pixel is the one associated with polygon closest to the viewer. Time domain aliasing object is moving in front of the projection plane. Pass more than one ray per pixel. 2) Affine transformation 5 A transformation is a function that takes a point (or vector) and maps that point into another points and/or vectors to other vectors. For points Q=T(P) For vectors v=r(u) we can define the transformation with a single function, q=f(p)

v=f(u) We could carry out the transformation on every point on a curve. For example, if we transform a line segment, a general transformation might require us to carry out the transformation for every point between the two endpoints. Affine transformation include translation,rotation and scaling. Linear function A function f is a linear function if and only if, for any scalars α and β and any two vertices p and q, f(αp+ βq)= αf(p)+ βf(q) If we know the transformation of p and q,we can obtain the transformations of linear combinations of p and q by taking linear combinations of their transformation A linear transformation then transforms the representation of a given point(or vector) into another representation of that point. It can always be written in terms of the two representations u and v as a matrix multiplication, v=cu Where C is a square matrix. when we work with homogeneous coordinates, A is a 4 x 4 matrix that leaves the unchanged fourth(w) component of a representation. α11 α12 α13 α14 α21 α22 α23 α24 C= α31 α32 α33 α35 0 0 0 1 The 12 values can be set arbitrarily. and we say that this transformation has 12 degrees of freedom. Points and vectors have slightly different representations in our affine space. Any vector is represented as α1 β1 α2 β2 u = α3 any point can be written as p = β3 0 1 If we apply an arbitrary C to vector, v=cu Only nine elements of a C affect u,and thus only nine degrees of freedom in the transformation of vectors. Affine transformation of points have the full 12 degrees of freedom. * * * * * * * *