1. Usage of VM
To complete the programming assignment in COSC 471 course, students are required to install
and use virtual machine (VM).
1.1 Installing virtual machine
You can choose any VM you prefer or follow CIS department suggestions. Please search in
department website and look for student resources about VMware.
If you would like to use Oracle VM VirtualBox, here is some information:
• For windows users, you can download VirtualBox here:
https://download.virtualbo x.org/virtualbox/6.1.4/VirtualBox-6.1.4-
136177-Win.exe
• For Mac OS users, you can download from here:
https://download.virtualbo x.org/virtualbox/6.1.4/VirtualBox-6.1.4-
136177-OSX.dmg
• For Linux kernel OS users, please check the link below and find the corresponding
downloads for your OS:
https://www.virtualbox.org/wiki/Linux_Downloads
After downloading, please install it as directed.
1.2 Download virtual OS HD
After VM software is ready, please download a virtual Ubuntu. You should be able to find
Ubuntu on CIS department resources for students. We need version at least Ubuntu 18.04.0
and 64 bit is preferred. It is suggested you set the VM’s memory to be more than 2GB.
1.3 Install Guest Additions
After getting into the Ubuntu system, click “Devices” and then click “install Guest
Additions”
You can also refer to link below for more details:
https://docs.oracle.com/cd/E36500_01/E36502/html/qs-guest-additions.html
If the installing above is not successful, please open terminal using ctrl+alt+t, and then
install using the following commands:
sudo mkdir –p /media/cdrom
sudo mount -t auto /dev/cdrom /media/cdrom/ cd /media/cdrom/
sudo sh VBoxLinuxAdditions.run
After installing is completed, please restart the virtual machine.
1.4 Assignment editing and importing/exporting
Assignment 1 skeleton is named as pa1, a compressed file. Download your assignment
skeleton through Blackboard to your hosting machine. Then drag it to your virtual machine.
Here, you may need to set the “drag and drop” to be “bidirectional”.
You can also refer to the following link for more details:
https://docs.oracle.com/en/virtualization/virtualbox/6.1/user/guestadd-dnd.html
After you import the assignment to virtual machine, you can use Visual Studio Code to view
and edit the assignment. Right click the assignment folder and then “open with other
Application”. Then choose “Visual Studio Code”.
If you don’t have VSC installed, please download and install it. You may need to check CIS
department resource for students.
2. Assignment skeleton and programming environment
2.1 Vcpkg and Eigen3
You may need to download and install Vcpkg to help you manage C and C++ library on
VSC. Please refer to the links below:
https://github.com/microsoft/vcpkg
https://docs.microsoft.com/en-us/cpp/build/vcpkg?view=vs-2019
Eigen is a library which help you manage Linear Algebra related works. You can find Eigen
library information here:
https://eigen.tuxfamily.org/index.php?title=Main_Page
Specifically, you can find Vector and Matrix related topics here:
https://eigen.tuxfamily.org/dox/groupTutorialMatrixArithmetic.html
// Example of vector
std::cout << “Example of vector
”;
// vector definition
Eigen::Vector3f v(1.0f,2.0f,3.0f);
Eigen::Vector3f w(1.0f,0.0f,0.0f);
// vector output
std::cout << “Example of output
”; std::cout << v << std::endl;
// vector add
std::cout << “Example of add
”; std::cout << v + w << std::endl;
// vector scalar multiply
std::cout << “Example of scalar multiply
”; std::cout << v * 3.0f << std::endl;
std::cout << 2.0f * v << std::endl;
Example 1 above shows how to define a floating point vector with 3 dimensions output it
and then apply addition and multiplication.
Example 2 above shows how to define and output a matrix.
For our assignment, you need to download the Eigen library and leave it the same location as
your assignment. Eigen library may need to be included in your project.
// Example of matrix
std::cout << “Example of matrix
”;
// matrix definition
Eigen::Matrix3f i,j;
i << 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0;
j << 2.0, 3.0, 1.0, 4.0, 6.0, 5.0, 9.0, 7.0, 8.0;
// matrix output
std::cout << “Example of output
”; std::
cout << i << std::endl;
// matrix add i + j
// matrix scalar multiply i * 2.0
// matrix multiply i * j
// matrix multiply vector i * v
2.2 Assignment 1 skeleton
Assignment 1’s skeleton is included in the pa1 file. You need to focus on main.cpp file and
edit it to get your solutions.
Before modifying the provided skeleton file, please note that the files provided are already
compliable and runnable. So please first compile and run the code following the compiling
suggestions in section 3 later.
One of the most common errors is “undefined reference to xxx”. When you get this error,
please check the environment setting and linkage of your VSC.
3. Assignment programming and submission
3.1 Programming assignment description
In this assignment, you are required to fine a point P=(2,1), and then rotate it according to
original point counter-clock wise 45◦
Output the original coordinates of P and coordinates after rotation.
3.2 Compile
This assignment and all future assignments are required to be compiled using cmake.
First, editing the main.cpp file as the requirement of assignment description. Then at the
same directory of main.cpp, open Terminal and then type in following commands:
◼ mkdir build (this is to build a folder called “build”)
◼ cd build (this is to move to the build folder)
◼ cmake .. (note that the .. implies the one level up, if its current level, use .)
◼ make (compile the code and check if there are any errors)
◼ .Transformation (if there is no errors from last step, Transformation is a execute file
and you can run it now. file name “Transformation” may be changed, please refer to the
CMakeList.txt file).
You can also refer to the following links about how to use cmake to compile codes:
https://terryoy.github.io/2018/01/learn-to-use-cmake.html
https://tuannguyen68.gitbooks.io/learning-cmake-a-beginner-s-guide/content/index.html
3.3 Submission
Compile your solutions and generate screenshots of your output, then write your
understanding of output in a file. Compress source codes output and your explanation into
one compressed file named FirstnameLastnamePA1.zip (or any format you prefer).
Submit the compressed file through Blackboard before deadline.
3.4 Evaluation
Assignment 1 is for you to get familiar with programming environment and make sure
settings are ready. This assignment will be graded based on the following aspects:
• Get both team members environment setting ready and all libraries ready (25%)
• Define point and rotated point and output them correctly (50%)
• Compile and run codes correctly and can see the output points (25%)
1. Overview We have learned in the class how to using transformation to move an object in 2D and 3D. Now let us implement the concepts we learned into coding. In the next few assignments, you are required to implement a simplified version of CPU based Rasterization. The main tasks of this programming assignment include implementing a transformation matrix and a view/projection matrix. Giving three 3D points v0(2.0, 0.0, −2.0), v1(0.0, 2.0, −2.0), v2(−2.0, 0.0, −2.0), you are required to transform these points to the camera/view/monitor coordinates system, and draw a lined triangle based on them (in the skeleton program provided, I have provided a draw_triangle function, and you are required to add in codes to transformation matrix). In general, you are required to build model, view, projection transformation matrix, so that we can display the lined triangle on the screen. If there is any question, please refer to the class slides and videos. The functions you need to modify in file main.cpp include (Do NOT change function names and other predefined function to ensure the code is compliable): • get_model_matrix(float rotation_angle): build the model transformation matrix’s each element, and then return the matrix. In this function, you only need to implement 3D rotation along z axis in this transformation matrix, and ignore translation and scaling. • get_projection_matrix(float eye_fov, float aspect_ratio, float zNear, float zFar): using the giving parameter, build a projection matrix and return it. • [Optional] main(): any other functions if you think necessary. When you build your transformation matrix correctly, rasterization will generate a window and display the lined triangle. Because rasterization works frame by frame, so you should be able to use A and D keys to rotate the triangle along z axis, and when you press Esc key, window will be closed and program is terminated. Bonus part: implement triangle rotate along any axis which go through the original point. Besides, you can also run the program using command line and pass the rotation angle as a parameter to the program (as shown below). In this way, there will be no window and results will be saved into a file, normally an image here (if not specified, by default it is saved in the file output.png). The image file is located in the same place as your executable file. For example, if your executable file is in the build folder, the image file will be the same location. // loop running program, build a display window, you can control using A and D keys to rotate ./Rasterizer // Run the program the rotate the triangle by 20 degree, then save the output in file output.png ./Rasterizer -r 20 // Run the program the rotate the triangle by 20 degree, then save the output in file image.png ./Rasterizer -r 20 image.png 2. Assignment skeleton In this programming assignment, you don’t need to use triangle files. But focus on understanding and modify files rasterizer.hpp and main.cpp. The file rasterizer.hpp is used for generating rasterization and completing rendering. Rasterization in this program plays a very important role. Its variable and functions are explained as below: Variables: • Matrix4f model, view, projection: three transformation matrixes. • vector frame_buf: frame buffer, which is used to store the color data rendered on the screen. Functions: • set_model(const Eigen::Matrix4f& m): set the internal model matrix as the parameters and pass to rasterization. • set_view(const Eigen::Matrix4f& v): set view transformation matrix as internal view matrix. • set_projection(const Eigen::Matrix4f& p): set internal projection matrix as given matrix p, and pass to rasterization. • set_pixel(Vector2f point, Vector3f color): set the pixel (x, y) as the color of (r, g, b), and write them into frame buffer. In file main.cpp, we have simulated the graphic pipeline. First, we define the example of rasterization, and set the variables for it. Then we get a hard-coded triangle with three points (do NOT change it). In the main function, we have defined three functions to calculate model, view, and projection matrixes, and each function has a corresponding return matrix. These return values will be pass to rasterization through three functions namely set_model(), set_view(), and set_projection(). Finally, the rasterization will show the transformation results on screen. After model, view, and projection transformation, we should have these three points (of the triangle) in canonical space coordinate. Canonical space coordinate consists of three x, y, z in the range of [-1,1]. Next, we need to change viewpoint and display on the screen, which has been completed in rasterization and we do not need to worry about it. But you need to understand this important step in graphic pipeline. 3. Compiling This programming assignment requires of using two library: Eigen and OpenCV. Please make sure download and set them correctly. If you work on virtual machine and compile using CMake, please use the commands line below in the terminal: If you have not set the core numbers for virtual machine, click “setting” and choose “” to set the core numbers. // build a folder called “build” Mkdir build // move to the build folder Cd build // based on the directory provided in CMakeLists.txt to run CMake cmake .. // compile using make, -j4 uses 4 cores to optimize compile make -j4 // run ./Rasterizatier 4. Assignment submission and evaluation 4.1 Submission Read the assignment description carefully to make sure you understand the programing assignment correctly. Modify the skeleton codes as required. Compile your solutions and generate screenshots of your output, then write your understanding of output in a file. Compress source codes output and your explanation into one compressed file named FirstnameLastnamePA2.zip (or any format you prefer). Submit the compressed file through Blackboard before deadline. When you complete the assignment, please check your project clearly and make sure your submission folder includes CMakeLists.txt file and all the source files no matter you changed them or not. In addition, please include a README.md file to explain if you complete the bonus question, or explain this in the result analysis and screenshot file. 4.2 Evaluation This programming assignment has two parts: basic parts and bonus part. Here is the grading details: • Build model matrix correctly (25%) • Build view and projection matrix correctly (25%) • Compile and run codes correctly and can see the transformed triangle (20%) • When press A and D keys, triangle can rotate; or using command line to get the rotation results (20%) • Screens shot and result analysis (10%) • Bonus part: in the main.cpp file, build a function to let allow rotation along any give axis which go through original point. This function can look like this: Eigen::Matrix4f get_rotation(Vector3f axis, float angle)
1. Overview
In the last assignment, although we drew a wireframe (lined) triangle on the screen, it did not
seem very interesting. So this time we continue to take one step further: draw a solid triangle on
the screen, in other words, rasterize a triangle. In the last assignment, after the viewport changed,
we called the function rasterize_wireframe(const Triangle& t).But this time, you
need to fill in and call the function rasterize_triangle(const Triangle& t) yourself.
The internal workflow of this function is as follows:
• Create a 2-dimensional bounding box for this triangle.
• Traverse all the pixels in this bounding box (using their integer index). Then, use the
screen space coordinates of the pixel center to check whether the center point is inside
the triangle.
• If it is inside the triangle, compare the interpolated depth value at its location with the
corresponding value in the depth buffer.
• If the current pixel point is closer to the camera, set the pixel color and update the depth
buffer.
The functions you need to modify are as follows:
• rasterize_triangle(): execute the triangle rasterization algorithm
• static bool insideTriangle(): Check whether the point is inside the triangle.
You can modify the definition of this function, which means that you can update the
return type or function parameters in your own way.
Because we only know the depth values at the three vertices of the triangle, for the pixels inside
the triangle, we need to use interpolation to get the depth value. We have already taken care of
this part for you, because it uses some topics not been discussed yet. The interpolated depth
value is stored in the variable z_interpolated.
Please note how we initialize the depth buffer and pay attention to the sign of z values.
In order to make it easier for you to write code, we have reversed z to ensure that they
are all positive numbers, and the larger the value, the further away from the viewpoint.
In this assignment, you do not need to deal with the rotation transformation, just return an
identity matrix for the model transformation. Finally, we provide two hard-coded triangles to
test your implementation. If the program is implemented correctly, you should be able to see the
output image very similar to what is shown below:
2. Compiling
Download and use our updated skeleton code coming with this assignment on your own
computer or virtual machine. Notice that the get_projection_matrix()in the main.cpp
empty. Please copy and paste your implementation in the first assignment (assignment 1) to fill
in this function.
Compile and run the code as previous assignments.
3. Assignment submission and evaluation
3.1 Submission
Read the assignment description carefully to make sure you understand the programing
assignment correctly. Modify the skeleton codes as required. Compile your solutions and
generate screenshots of your output, then write your understanding of output in a file.
Compress source codes output and your explanation into one compressed file named
FirstnameLastnamePA2.zip (or any format you prefer). Submit the compressed file
through Blackboard before deadline.
When you complete the assignment, please check your project clearly and make sure your
submission folder includes CMakeLists.txt file and all the source files no matter you changed
them or not. In addition, please include a README.md file to explain if you complete the
bonus question (if you complete bonus question, please include screenshot of it too), or
explain this in the result analysis and screenshot file.
3.2 Evaluation
This programming assignment has two parts: basic parts and bonus part. Here is the grading
details:
• Correctly implement triangle rasterization algorithm (40%)
• Correctly test whether the point is within the triangle (20%)
• Correctly implement the z-buffer algorithm and draw the triangles on the screen in
order (20%)
• Compile and run codes correctly and submit all files correctly (10%)
• Screens shot and result analysis (10%)
• Bonus part: implement any Anti-aliasing algorithm to improve the display of triangle
so that when we enlarge the display, there will be aliasing on triangle edges. (10%)
Overview In this programming assignment we continue to further simulate modern graphics technology. We add Object Loader (used for load the 3D model), Vertex Loader and Fragment Loader, and support texture mapping too. In this assignment, you need to complete the following tasks and modify the following functions: • Modify function rasterize_triangle()in rasterizer.cpp: here you need to implement similar interpolation as last assignment 2, which interpolate normal, color and texture values. • Modify function get_projection_matrix() in main.cpp: fill in the previous projection matrix implemented in the previous assignment here, and you can run ./Rasterizer output.png normal to check the results of normal. • Modify function phong_fragment_shader() in main.cpp: implement Blinn-Phong reflection model here to calculate Fragment Color. • Modify function texture_fragment_shader() in main.cpp: based on the implementation of Blinn-Phong model, treat texture color as the kd in the formula to implement Texture Shading Fragment Shader. • Modify function bump_fragment_shader() in main.cpp: based on the implementation of Blinn-Phong model, read the comments of this function carefully and implement Bump mapping. • Modify function displacement_fragment_shader() in main.cpp: based on the Bump mapping, implement displacement mapping. 2. Compiling 2.1 Compiling and Run After downloading the skeleton codes provided with this assignment, compile it as previous assignments: Mkdir build cd ./build cmake .. make This will generate an executable file named Rasterizer. When run this executable file, you can pass the image name as first parameter, and for the second parameter you can pass like this: • texture: this will run the code with texture shader. For example: ./Rasterizer output.png texture • normal: this will run the code with normal shader. For example: ./Rasterizer output.png normal • phong: this will run the code with Blinn-Phong shader. For example: ./Rasterizer output.png phong • bump: this will run the code with bump shader. For example: ./Rasterizer output.png bump • displacement: this will run the code with displacement shader. For example: ./Rasterizer output.png displacement Note: After you modify the codes, you need to re-compile using make to see the new results. 2.2 Skeleton codes Compared with last assignment, we have made some modifications for the skeleton codes: 1. We have introduced a third-party .obj file loader to read in complicated models, and this library file is in OBJ_Loader.h file. You don’t need to fully understand how it works, but just know it is a library which will pass us a Vector named TriangleList, in which each triangle has corresponding normal and texture coordinates. Besides, the texture related to the model will also be loaded. Note: if you try to load in other model, you have to change model directory and path manually. 2. We have introduced a new Texture class to generate textures from images, and provided an interface to check texture colors: Vector3f getColor(float u, float v). 3. We have built a header file Shader.hpp and defined fragment_shader_payload, which includes parameters for Fragment Shader. Now main.cpp has three Fragment Shaders, which are fragment_shader (shader using normal) and two shaders you need to implement. 4. The main rendering pipeline starts with rasterizer::draw(std::vector &TriangleList). We then again make some transformations, which is completed normally by Vertex Shader. After that, we then call function rasterize_triangle. 5. Function rasterize_triangle() is similar to the one in your assignment 2. The difference is that the set value is not longer a constant but set normal, color, texture and shading colors using interpolation based on Barycentric Coordinates. Recall last time we use [alpha, beta, gamma] to compute z value, this time you will use it to other interpolations. All you need to do is compute the color after interpolation, and write the color got from Fragment Shader to framebuffer. This requires you to first set the Fragment shader payload with the result of the interpolation, and call the fragment shader to get the results. 2.3 Run and Results When you copy the code from last assignment as explained before and complete the modification required (please read the descriptions carefully), you should be able to run using the default normal shader and get the result like this: When you have implemented Blinn-Phone reflection model correctly, the result will be like this: If the texture is implemented correctly, your result will be like this: When Bump Mapping is implemented, you should be able to see visualized bump vector like this: When Displacement Mapping is implemented correctly, you should be able to see output like this: 3. Assignment submission and evaluation 3.1 Submission Read the assignment description carefully to make sure you understand the programing assignment correctly. Modify the skeleton codes as required. Compile your solutions and generate screenshots of your output, then write your understanding of output in a file. Please create an image folder and save all your images in this folder. Compress source codes output, images and your explanation into one compressed file named FirstnameLastnamePA3.zip (or any format you prefer). Submit the compressed file through Blackboard before deadline. When you complete the assignment, please check your project clearly and make sure your submission folder includes CMakeLists.txt file and all the source files no matter you changed them or not. In addition, please include a README.md file to explain if you complete the bonus question (if you complete bonus question, please include screenshot of it too), or explain this in the result analysis and screenshot file. 3.2 Evaluation This programming assignment has two parts: basic parts and bonus part. Here is the grading details: • Correctly implement interpolations for color, normal, texture and shading position and pass them to fragment_shader_payload (20%) • Correctly implement Blinn-Phong reflection model (20%) • Correctly implement Texture Mapping (20%) • Correctly implement Bump Mapping and Displacement Mapping (20%) • Compile and run codes correctly and submit all files correctly (10%) • Screens shot and result analysis (10%) • Bonus part: try other models, you can find them in the models folder. (10%)

![[SOLVED] Cosc 471 assignments 1 to 4 solution](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[SOLVED] Cs 1656 assignments #1 to 5 solution](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.