# Lecture 1: Introduction and Background

## Presentation on theme: "Lecture 1: Introduction and Background"— Presentation transcript:

Lecture 1: Introduction and Background
Computer Graphics Lecture 1: Introduction and Background

Lecturer Details Dr. Walid Khedr, Ph.D.
Web: Department of Information Technology

Main Topics Introduction Basic principles of two-dimensional graphics
Drawing lines and curves Areas, text and colors Basic principles of three-dimensional graphics Modeling three-dimensional objects Visible surface determination Illumination and shading Special effects and virtual reality

What is Computer Graphics
In general sense, computer graphics is the process of producing a picture or Image using the computer. This includes applications that start form drawing simple graphs or line drawings And ends with programs that involve complex mathematics and physics in the production of highly accurate images. Added to this is the capability to create a series of images that result in an animation. The purpose of this Course is to explore some of the basic ideas of realistic image generation. The goal then is the creation of an image by writing a program instead of taking a picture with a camera. The amount of pages that have been written about this topic in specialized graphics books and technical conference papers is considerable. A book of this size, therefore, cannot expect to give all of the details for the simulation of all the possible natural phenomena that can be included in an image. Rather, the intent of this book is to introduce those concepts that are critical components of realistic image generation or are the foundation on which current efforts are built.

Image Terminology A Pixel: is shorthand for "picture element." and it is one location in an image, whether on the computer screen or in a printout. Gray Scale Pixels: Each pixel takes one value that indicates where in the range from black to white it is. Color Pixels: Each pixel will use three values to store the range of intensities for the red, green, and blue (RGB) components. Each of those values, whether for a gray scale or color image, can be expressed as either: A floating point number values between 0.0 and 1.0 An integer range Most graphics systems use either one or two bytes per value i.e. zero to 255, or zero to 65,535. The alpha-channel: Indicates the transparency of the pixel

Image Terminology, Cont.
The pixels of an image are organized into a two-dimensional grid that is called a frame buffer and is frequently used as a two-dimensional array Graphics hardware has enough memory to store multiple frame buffers, which is useful for animation and game programs (a process called double buffering) The goal of realistic image creation is to calculate a collection of pixel values that when viewed creates the impression of a picture.

Image Terminology: Double Buffering

The Rendering (Graphics) Pipeline
There is a wide range of different applications of computer graphics, but there are common elements in all of these applications. They all begin with data and that data is then used to create (or "render") an image, which is then displayed on a computer screen. The process going from data to image is called the graphics pipeline

3D Rendering Pipeline Transform into 3D world coordinate system
3D Geometric Primitives Modeling Transformation Transform into 3D world coordinate system Viewing Transformation Lighting & Texturing Projection Transformation Clipping Scan Conversion Image

3D Rendering Pipeline Transform into 3D world coordinate system
3D Geometric Primitives Modeling Transformation Transform into 3D world coordinate system Transform into 3D camera coordinate system Done with modeling transformation Viewing Transformation Lighting & Texturing Projection Transformation Clipping Scan Conversion Image

3D Rendering Pipeline Transform into 3D world coordinate system
3D Geometric Primitives Modeling Transformation Transform into 3D world coordinate system Transform into 3D camera coordinate system Done with modeling transformation Viewing Transformation Illuminate according to lighting and reflectance Apply texture maps Lighting & Texturing Projection Transformation Clipping Scan Conversion Image

3D Rendering Pipeline Transform into 3D world coordinate system
3D Geometric Primitives Modeling Transformation Transform into 3D world coordinate system Transform into 3D camera coordinate system Done with modeling transformation Viewing Transformation Illuminate according to lighting and reflectance Apply texture maps Lighting & Texturing Projection Transformation Transform into 2D screen coordinate system Clipping Scan Conversion Image

3D Rendering Pipeline Transform into 3D world coordinate system
3D Geometric Primitives Modeling Transformation Transform into 3D world coordinate system Transform into 3D camera coordinate system Done with modeling transformation Viewing Transformation Illuminate according to lighting and reflectance Apply texture maps Lighting & Texturing Projection Transformation Transform into 2D screen coordinate system Clipping Clip primitives outside camera’s view Scan Conversion Image

3D Rendering Pipeline Transform into 3D world coordinate system
3D Geometric Primitives Modeling Transformation Transform into 3D world coordinate system Transform into 3D camera coordinate system Done with modeling transformation Viewing Transformation Illuminate according to lighting and reflectance Apply texture maps Lighting & Texturing Projection Transformation Transform into 2D screen coordinate system Clipping Clip primitives outside camera’s view Scan Conversion Draw pixels (includes texturing, hidden surface, ...) Image

3D Rendering Pipeline 3D 2D 3D Geometric Primitives Modeling
Transformation Viewing Transformation Lighting & Texturing 3D Projection Transformation Clipping 2D Scan Conversion Image

The Rendering Pipeline: A Tour
Modeling Transform Illuminate Viewing Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display

The Parts You Know Modeling Transform Illuminate Viewing Transform
Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display

The Rendering Pipeline
Modeling Transform Illuminate Viewing Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display

2-D Rendering: Rasterization
Modeling Transform Illuminate Viewing Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display We’ll talk about this soon…

The Rendering Pipeline: 3-D
Modeling Transform Illuminate Viewing Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display

The Graphics Pipeline, Cont.
In the case of realistic image generation, the three main stages for computer generated image are modeling, rendering, and display

Modeling Before an image can be created, a model of the scene is developed. The model needs to give the details of each of the objects Shape Simple Complex Parameters specifying the object's materials The object color What the object is made Of Whether the object is shiny, transparent, etc.

Rendering Rendering is the process of generating an image from a model, by means of computer programs. The rendering process includes: Geometric Transformations (Affine Transformations) Clipping Scan Conversion Illumination Shading

Image Display One issue with the display of an Image is differences with output capability/ Each company that manufactures a computer monitor or a color printer uses unique components. CRT Monitors LCD Monitors Plasma Monitors Those components differ in how they produce their output, which means that one image can appear differently when displayed on two different monitors This issue is called "color reproduction." This topic is complex and well beyond the scope of this course

Real Scene → Image Real scene whose details/objects have to be modelled.

Real Scene → Image Model of the scene: in which the objects of the real scene are represented by the available modelling techniques. The true geometry might only be approximated by the model. the bowl in the real scene can only be approximated by a semisphere.

Real Scene → Image Choice of a view/part of the virtual world to be displayed. Clipping: Computation which objects are within the chosen view. Visibility considerations: Which objects in the clipping region are visible for the viewer, i.e. are not hidden from view by other objects?

Real Scene → Image Result: pixel image

Background Math Review Java Review

Math Review

Matrices Applications in many areas Rectangular array – 2D array Size
Colour small medium large Xlarge Black 60 100 150 120 White 25 48 10 Gray 93 140 170 Navy 75 94 Red 80

Definitions A matrix is a rectangular array of elements (usually numbers) arranged in rows and columns enclosed in brackets. Order of the matrix is the number of rows and columns. A is a 3×2 matrix, B is a 3×3 matrix C is a 4×1 matrix . Matrices are denoted by capital letters while their elements are written as lower case letters as in example C above. We refer to a particular element by using notation that refers to the row and column containing the element, i.e. a21=-1, b32 = 1, c21 = b. Two matrices A and B are said to be equal, written A = B, if they have the same order and aij = bij for every i and j.

Type of Matrices Square matrix – a matrix with an equal number of rows and columns. Diagonal matrix – a square matrix with zeros everywhere except down the leading diagonal. Unit matrix (identity matrix) – a diagonal matrix with ones down the leading diagonal. The identity matrix is denoted with the letter I.

Type of Matrices (continue)
Zero matrix – a matrix with zeros everywhere, denoted by O. Symmetric matrix – a square matrix whose (ij)th element is the same as the (ji)th element for all i and j. Row matrix (row vector) – a matrix with only one row, i.e. its order is 1×m. Column matrix (column vector) – a matrix with only one column, i.e. an n×1 matrix.

If A and B are two n×m matrices then their sum C = A + B is the n×m matrix with cij = aij + bij their difference C = A - B is the n×m matrix with cij = aij - bij Examples:

Scalar Multiplication of Matrices
If A is an n×m matrix and k is a real number, then the scalar multiple C = kA is the n×m matrix where cij = kaij .

The Transpose of a Matrix
If A is a matrix then the transpose of A is the matrix At where atij = aji.

Matrix Multiplication
If A is an n×m matrix and B is an m×p matrix then the product of A and B, C = AB, is an n×p matrix Cij = (row i of A) × (column j of B) = ai1b1j + ai2b2j + ai3b3j + … ainbjp

Properties If a, b are scalars and A, B, C are matrices of the same dimension (order) then A + B = B + A A + (B + C) = (A + B) + C a(bA) = (ab)A (a + b)A = aA + bA a(A + B) = aA + aB a(A - B) = aA - aB A + OA = A, and aO = O (A + B)t = At + Bt (A - B)t = At - Bt

Properties If a, b are scalars and A, B, C are matrices of the same dimension (order) then assuming that the matrix dimensions are such that the products in each of the following are defined, then we have: AB ≠ BA A(BC) = (AB)C (A + B)C = AC + BC A(B + C) = AB + AC OA = O, AO = O (aA)(bB) = abAB IA = AI = A (AB)T = BTAT

Inverse of a 2×2 Matrix Not all Matrices have an inverse.
The Determinant – determines if a matrix has an inverse or not. If the determinant of a matrix A is zero then the matrix has no inverse. Example:

Inverse of a 2×2 Matrix If A is a matrix then it is possible to find another matrix, called A-1, such that AA-1 = I or A-1A = I . Example:

Solution of Systems of Simultaneous Equations
A x = b Ax = b  A-1Ax = A-1b  x = A-1b

A x = b

Inverse of a 3×3 matrix

Inverse of a 3×3 matrix (example)

Dimension of a Space is the amount of freedom of movement that objects within the space have. 0D 1D x 2D y x 3D y x z

3D Coordinate Systems y x z y x z Right-handed system (z comes out)
Left-handed system (z goes in)

Distance 1D P1 P2 y 2D P2 P1 x y 3D P2 P1 x z

Trigonometry 3 5 ? ? 10 20º

Equation of the Line y (x1,y1) (x2,y2) c x

Equation of a circle at (0,0)
(0, 0) r (x,y) Polar form Cartesian form

Equation of a circle at (xc ,yc)
(x,y) Polar form Cartesian form

Positions (points) & Directions (vectors)
y v=(x,y,z)=(2,2,-1) P1=(2,1,2) P2=(4,3,1) x z A vector is the difference between two points, i.e. vector = point2 – point1 v = P2 – P1 = (4, 3, 1) – (2, 1, 2) = (2, 2,-1) point2 = point1 + vector P2 = P1 + v = (2, 1, 2) + (2, 2,-1) = (4,3,1)

Addition of Vectors v1 = (x1, y1, z1) v2 = (x2, y2, z2)
v1 + v2 = (x1 + x2 , y1 + y2 , z1 + z2) (x1+x2, y1+y2, z1+z2) (x2, y2, z2) (x1, y1, z1) (0, 0, 0)

Length of a vector Norm of a vector
Only interested on the direction and not in its length. So norm(v) has the same direction but length 1.

Inner (dot) product of two vectors
The dot-product, denoted by v1 · v2 , is the angular relationship between two vectors: Normalizing each of the vectors v1 and v2 and then take the dot-product of the normalized vectors we find  which is the angle between the two vectors. The dot product of a unit length vector with itself is 1. Vectors that are perpendicular to one another (called orthogonal) have a zero dot product.

Exercise Find the angle between vectors (3,7) and (-4,5). y x (-4,5)

Vector cross-product Properties:
The cross-product, denoted by v1 × v2 , is the vector: v1×v2 is orthogonal to both v1 and v2, i.e. v1 and v2 form a plane and their cross product is normal to that plane. How to remember the formula: v1 v2 -v1×v2 = v2×v1 v1 v2 v1×v2 Properties:

Next Lecture Chapter 2: Basic principles of two-dimensional graphics