[SOLVED] TDT4195-Assignment 1

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Assign1-7tylap.zip (419.5 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (1 vote)

In the computer graphics assignments of this course we’ll be creating an animated, interactive scene. Since this task is quite large to put in a single assignment, it has been split into three separate assignments, which will guide you through its implementation.

Task 0: Preparation

  1. Ensure the following tools are installed:

Git cargo rustc

Please see the simple rust cookbook for how to get started with Rust.

  1. Clone the Gloom repository using the command:

git clone https://github.com/pbsds/gloom-rs

  1. Compile and run the project.

This should be as simple as running cargo run from a terminal.

You should see an empty window if compilation is successful and your GPU supports the OpenGL version required for these labs (4.0 or higher). If not, computers have been made available in room ITS-008 (Cybele) for you to use.

Task 1: Drawing your first triangle

We recommend trying to complete all subtasks of this task at once, instead of one subtask at a time.

  1. a) Create a function which sets up a Vertex Array Object (VAO) containing triangles. You can modify the function signature that is located just above the main function in main.rs.

The function must take a vector of three dimensional vertex coordinates (usually &Vec<f32>) and an array of indices (&Vec<u32>).

The function must return the integer ID of the created OpenGL VAO set up, to draw the input arrays.

The contents of the buffer can be assumed to exclusively contain triangles, specified by floating point coordinates.

Refer to chapter 2 of the OpenGL guide for detailed information on how to accomplish the objectives of this task.

There are at the top of “main.rs” a collection of helper functions to help you write the

VAO generation function. Please use them, as they make your code easier to both read and write.

OpenGL can be extremely “picky” about values and parameters it is given. A single incorrect parameter or input value can cause nothing to be rendered, and no error to be reported. If you experience problems, check your code carefully line by line. It is also recommended to come to the designated lab hours for help.

The project is designed to crash if it recieves any error from OpenGL, so if you get a crash, it should be possible to figure something out from the stack trace.

  1. In the handout code, you’ll find a basic shader pair in the folder “shaders”. Load and link the pair, then activate it.

It is highly recommended you use the provided “ShaderBuilder” in shader.rs .to build a “Shader”. Basic usage of it is outlined in main.rs. Refer to the Rust cookbook on how to return values from unsafe blocks.

For detailed information on using shaders, refer to chapter 3 of the OpenGL guide.

  1. [report] Define and instantiate a VAO containing at least 5 distinct triangles using the function you defined in a). Use the shader pair you loaded in b) to render the VAO.

All triangles must be visible. Put a screenshot of the resulting scene in your report.

Hint: these coordinates will give a visible triangle when you perform the drawing correctly:

                                                    

−0.6                     0.6                      0

v0 = −0.6, v1 = −0.6, v2 = 0.6

                                                    

0                          0                        0

Task 2: Geometry and Theory

For the theory questions in this task, when evaluating the your answers we are looking for whether you have understood the concepts being asked about. If you answer in a short sentence, we are not always able to deduce this. As such we recommend spending some words on your answers wherever applicable.

  1. [report] Draw a single triangle passing through the following vertices:

                                                      

0.6                      0                     −0.8

v0 = −0.8, v1 = 0.4, v2 = −0.2

                                                      

−1.2                     0                      1.2

Put a screenshot of the result in your report.

This shape does not entirely look like a triangle.

Explain in your own words:

  1. What is the name of this phenomenon?
  2. When does it occur? iii) What is its purpose?

Hint: try to move vertex coordinates around and see what happens.

  1. [report] While drawing one or more triangles, try to change the order in which the vertices of a single triangle are drawn by modifying the index buffer. A significant change in the appearance of the triangle(s) should occur. Show a screenshot in your report.
    1. What happens?
    2. Why does it happen? iii) What is the condition under which this effect occurs? Determine a rule.

For the sake of clarity, you don’t need to submit a separate version of your code just for this task alone (as well as any subsequent tasks). Just make the modifications, show the screenshot in your report, and continue modifying your code in the questions ahead. In the end you submit the code you’ve ended up with to blackboard.

  1. [report] Explain the following in your own words:
    1. Why does the depth buffer need to be reset each frame?
    2. In which situation can the Fragment Shader be executed multiple times for the same pixel?
  • What are the two most commonly used types of Shaders? What are the responsibilities of each of them?
  1. Why is it common to use an index buffer to specify which vertices should be connected into triangles, as opposed to relying on the order in which vertices are specified in the vertex buffer(s)?
  2. While the last input of gl::VertexAttribPointer() is a pointer, usually a null pointer is passed in. Describe a situation in which you would pass a non-zero value into this function.
  1. [report] Modify the source code of the shader pair to:
    1. Mirror the whole scene horizontally and vertically at the same time.
    2. Change the colour of the drawn triangle(s) to a different colour.

Put a screenshot of each effect in your report.

Explain briefly how you accomplished each effect.

Task 3: Optional Bonus Challenges

This task is optional. These questions are meant as further challenges or to highlight things you may find interesting.

However, if you successfully complete at least one of these, you will receive a bonus of 0.2 points (although the maximum score of the assignment is still capped at 4%).

Please show us some eye candy if you managed to answer some or all of them! We’ll try our best to put them up in a gallery on blackboard for everyone to see 🙂

  1. The Fragment Shader has access to a predefined variable called gl_FragCoord. It is a variable of type vec4 which contains the x and y-coordinate of the pixel/fragment on the screen.

Use this fragment coordinate to draw a checkerboard on triangles (or something that looks like something along those lines).

  1. Draw a circle.
  2. Draw a spiral.
  3. Draw a shape and have its colour change slowly over time (hint: use a uniform variable).
  4. Draw a square by combining two triangles. Abuse the fragment shader to rasterise a triangle manually.
  5. Implement a function which can read a 3D object from a file (for example an STL or OBJ file), and draw its contents.
  6. Plot a sine function.
  • Assign1-7tylap.zip