TRIBHUWAN UNIVERSITY
INSTITUTE OF ENGINEERING
PULCHOWK CAMPUS
A
PROJECT REPORT
ON
COMPUTER GRAPHICS
PROJECT TITLE: 3D-MODELING OF TAJ MAHAL
SUBMITTED BY
ABISHA THAPA MAGAR (068/BEX/402)
ANUP SHAKYA (068/BEX/405)
ARJUN KHANAL (068/BEX/406)
SUBMISSION DATE: 2070-12-11
SUBMITTED TO
DEPARTMENT OF ELECTRONICS AND COMPUTER ENGINEERING
Table of Contents
Page No.
Acknowledgment 3
Abstract 4
1. Introduction 5
2. Objectives 6
3. Methodology 7
4. Viewing Pipeline 8
5. Computer Graphics Algorithms Used 9
6. Output 14
7. Limitations 15
8. Conclusion 16
9. Bibliography 16
Acknowledgement
First of all, we would like to express our gratitude towards the Department of Electronics and Computer Engineering for integrating Computer Graphics in our syllabus. We are also grateful to our instructor Dr. Basanta Joshi for providing us a golden opportunity to conduct the project work in Computer Graphics. We became more familiar with this subject while working on this project.
We would also like to give special thanks to Dr. Sukhendu Das, IIT Madras for his excellent lecture videos on Computer Graphics. We must thank our colleagues for providing us their helpful views and ideas while working on this project.
Yours’ Sincerely
Abisha Thapa Magar
Anup Shakya
Arjun Khanal
Abstract
We used different graphical algorithms to realize a 3D complex object in this project. The algorithms are implemented in Open GL integrated in Code Blocks IDE.
To realize the 3D object into 2D plane, we used algorithm for one point perspective projection is purpose. In the same way, other important geometrical transformation such as translations, rotations and reflections are implemented. The whole wireframe model was drawn using Bresenham’s Line Drawing Algorithm.
In order to give more realistic view, light intensity at each pixels were set by intensity calculation. And visible surfaces were detected using depth buffer algorithm.
1. Introduction
Computer Graphics are the graphics created using computers and the representation of image data by a computer specifically from specialized graphic hardware and software. Graphics is a vital part of software era. People are now aware of the looks and appearances of the program. Accordingly, the project 3D modeling of Taj Mahal provides a rendered 3D model with all sorts of transformation and lighting effect. The project is developed in Code Blocks, an open source cross-platform IDE using Open GL, hardware accelerated API.
Taj Mahal is one of the seventh wonder of the world. It is known for its history of construction. Being inspired by it, the project has approached to model Taj Mahal using C++ language.
The main focus of the project is the creation and transformation of 3D prototype of Taj Mahal. The principle behind creating such a huge model is just reflections of points. Taj Mahal can be easily visualized in four symmetrical parts as the real world monument is constructed. The 3D points/vertices of the first part (or say first quadrant as considered in the project) are visualized manually, while 3D points/vertices of other parts are obtained by reflection. The wireframe structure is visualized initially. The model is rotated using 3D transformations, zoomed in/out moving camera and projection plane parallel and rendered with color of calculated light intensity in each seen pixels lying inside the model.
Taking advantage of Object’s symmetry, we modeled it by drawing a quarter of it and reflected it about suitable axis. We considered quadrilateral as the basic unit of 3D model and pixel as the basic unit of each quadrilateral. Similar approach can be attempted to model other real world objects. Thus, 3D modeling is done in Computer Graphics.
1.1 Existing System
3D modeling is usually found in the architectural field. Many 3d rendering softwares like Autodesk Maya, Autodesk 3dsMax, etc are used for realistic modeling of the 3d structures. One of the 3d model of Taj Mahal constructed in Maya was referenced.
2. Objectives
The main objectives of the project are to fulfill the third year course of Computer Graphics and to implement our knowledge practically. Other objectives are:
§ To construct a 3D object.
§ To implement 3D transformations.
§ To implement various 2D & 3D algorithms in high level programming language.
§ To generate virtual reality system by including rendering and lighting effects.
3. Methodology
§ Code blocks IDE and C++ language are used.
§ Some vertices are calculated manually and some are calculated using equations.
§ Consideration of quadrilateral as the basic unit of 3D model and pixel as the basic unit of each quadrilateral.
§ Perspective 2D projection from 3D model.
§ Polyfill Scanline algorithm is used to render each quadrilateral.
§ Z-buffer is attempted for VSD.
§ Phong’s Illumination model is used for lighting.
4. Viewing Pipeline
Modeling World Viewing
Coordinates Coordinates Coordinates
Projection Device
Coordinates Coordinates
Fig 4.1. Three Dimensional transformation Pipeline
Generating a view of a three-dimensional scene is somewhat analogous to the processes involved in taking a photograph but we have more flexibility and many more options for generating views of a scene with a graphics package than with a camera. The figure above shows the general processing steps implemented for 3d modeling of Taj Mahal and converting the world-coordinates to device coordinates. First, the 3d object was modeled by generating coordinates manually. For modeling the structure, ready-made 3d models of Taj Mahal was referenced. Since Taj Mahal is symmetrical about quadrants, the coordinates for only 1st quadrant was modeled and coordinates for remaining quadrants were obtained via reflection about planes. And thus, world coordinates were obtained. Then, the world coordinates were converted to viewing coordinates. Next, perspective projection operations were performed to convert the viewing-coordinate to coordinate positions on the projection plane. Then visible surface were identified using depth buffer and were rendered using Phong’s Shading Model.
5. Computer Graphics Algorithms Used
A. Perspective Projection
Perspective view is the real view as perceived by an eye. For real 3d modeling of any object, perspective projection algorithm is implemented to convert 3d world coordinates to 2d screen coordinates. For simplicity, camera/eye is aligned perpendicular to the XY-plane and the projection plane is parallel to XY-plane. Each vertex of the object in 3d is projected onto the projection plane and 2d projected coordinates is calculated. Then, necessary viewport transformations are applied in order to obtain the 2d screen coordinates. The viewing system used is Right Hand Viewing System.
Fig 5.1. Perspective Projection
B. Depth Buffer
There are various methods for detecting the visible surfaces in a 3d scene. Some methods eliminate hidden surfaces and some identify the visible surfaces to be drawn. Visible Surface Detection methods can broadly be classified into two types namely: Object-Space Method and Image Space Method. Depth Buffer or Z-buffer is an Image Space Method. Depth buffer makes use of two buffer areas namely – Depth buffer and Refresh buffer. These buffers are used to store information of depth and color intensity of each pixel position (x,y) on the screen. The basic algorithm of Depth Buffer is given below:
Algorithm for Depth Buffer
1. Initialize ∀ (x,y) depth (x,y) = Zmin
refresh (x,y) = IB (Background Intensity)
2. For each position on each Polygon surface
i. Calculate the depth Z for each pixel position (x,y) on the polygon surface
ii. If Z > depth (x,y)
depth(x,y) = Z
refresh(x,y) = Is
Is is the projected intensity value of the surface at position (x,y), which has the maximum Z-value (Right Hand Viewing System)
For each polygon, the surface can be expressed in the form of
Ax + By + Cz + D = 0
The coefficients of equation of plane i.e. A, B, C, D is calculated using the following formula
A = y1(z2 - z3) + y2(z3 - z1) + y3(z1 - z2)
B = z1(x2 - x3) + z2(x3 - x1) + z3(x1 - x2)
C = x1(y2 - y3) + x2(y3 - y1) + x3(y1 - y2)
D = -x1(y2z3 - y3z2) – x2(y3z1 - y1z3) – x3(y1z2 - y2z1)
For each pixel on the polygon surface, respective 3d position of the pixel is calculated by projecting the point backwards to the 3d object. After the 3d point is calculated, the depth value of that point is calculated.
C. Scanline Polyfill Algorithm
Scanline Polyfill algorithm is one of the methods to render a polygon. This method renders a polygon by calculating each pixel on the polygon surface by projecting scan lines. A scan line is basically a horizontal line that extends from left side of the screen to the right side. For rendering a quadrilateral, scan lines are projected to calculate the pixels that lie within the region of the quadrilateral. The basic algorithm implemented is as follows:
For each polygon
1. For each edge
For y= y_min to y_max
Calculate the x-coordinate of intersection of Scanline y
2. Sort the x-intersection for each Scanline y in increasing order
3. For Scanline y=y_min to y_max
Compare depth, calculate color intensity and fill Color
Fig 5.2. Polyfill Scanline
D. Phong’s Lighting Model
In Phong’s model, the light reflected off an object is the sum of three components, ambient, diffuse and specular, based on the reflectance properties of its surface. A point light source is considered and light intensity of RGB is calculated for each pixels. Ambient part of the light is scattered equally in all directions from the surface of object. In addition to ambient part of light source, there is presumed to be a global ambient light as well. Diffuse part of the light travels as coherent beam from source towards object and is scattered equally in all directions. The direction of the light source does matter in case of diffuse reflectance. The specular part of the light also travels in a coherent beam from source to object and then again is reflected in a coherent beam. So, both the direction of the light source and viewer matter in case of specular reflectance. Diffuse models soft light with little focus while specular models hard light with a focus.
3*3 light property matrix is:
Lamb, R Lamb, G Lamb, B
Ldif, R Ldif, G Ldif, B
Lspec, R Lspec, G Lspec, B
The global ambient vector:
[globAmb R globAmb G globAmb B]
3*3 material properties matrix is:
Vamb, R Vamb, G Vamb, B These are the reflectance values which represent
Vdif, R Vdif, G Vdif, B the object‘s color.
Vspec, R Vspec, G Vspec, B
Lighting equation that gives the color intensity VX at each pixels, where X may be any of RGB is:
VX = globAmb X * Vamb, X + Lamb, X * Vamb, X + |L . N| * Ldif, X * Vdif, X
+ |S . N| * Lspec, X * Vspec, X
Here, L is the light to pixel vector, N is the outward normal and S is the halfway vector. The dot product of the two vectors gives cosine of angle between them.
Fig 5.3 Figure showing light reflection
E. 3D Rotation
Rotation in 3d is performed about arbitrary axes parallel to coordinate axes passing through the centre of the structure. The whole structure is rotated in three directions by translating the arbitrary axes to the coordinate axes. The formulae used for rotation are:
Rotation about x axis:
y' = y*cos (xangle) - z*sin (xangle)
z' = y*sin (xangle) + z*cos (xangle)
Rotation about y axis:
x' = x*cos (yangle) + z*sin (yangle)
z' = -y*sin (yangle) + z*cos (yangle)
Rotation about z axis:
x' = x*cos (zangle) + y*sin (zangle)
y' = x*sin (zangle) - y*cos (zangle)
6. Output
The output is much like the one which was expected.
Fig 6.1: 3D wireframe of Taj Mahal
Fig 6.2: Rendered 3D model of Taj Mahal
7. Limitations
The project seems to be quite complete but there are many things that can to be improved. Following are some of the limitations of the project:
· The 3D model of Taj Mahal can be modeled with its fine constructional details. Since we lack time and had to cover other portions of the modeling, the model was confined to the shown (Figure 2) details.
· The model could be scaled up and down for zooming effect.
· In the meantime, the model is facing problem with rendering. Since there is not enough time to revise, the rendering problem remains unsolved.
· Because of improper understanding of z-buffer method, we chose z-distance from projection plane to 3D point for comparison.
· Taj Mahal is constructed with its beauty to resemble the environment light. Before dawn, its color is pearly grey, pink at sun rise and yellow at sun set. Even knowing its feature, we could not implement light with different quality.
8. Conclusion
Hence, in this project we gained sufficient amount of knowledge related to Computer Graphics that can also be applied to other graphics related projects. Despite of the limitations, a virtually realistic Taj Mahal is constructed with pixel wise rendering and lighting, and is given movement using 3D transformations. Thus, objectives of the project are met.
9. Bibliography
· Hearn, Donald “Computer Graphics C Version”, 2nd Edition, Singapore: Pearson Education Pte. Ltd., 2004
· Das, Sukhendu Video Lectures on Computer Graphics, Youtube Channel: https://www.youtube.com/playlist?list=PLE4D97E3B8DB8A590
· Gotsman, Elber “Polygon Filling Drawing Geometry on Raster Displays”, 9-12
Page | 2