Assignment 2 – A Software Rasterizer implementing the Forward Rendering Pipeline

$24.99 $18.99

In this assignment, you are going to implement Modeling Transformation, Viewing Transformation, and Rasterization stages of the Forward Rendering Pipeline. Specifically, given a set of triangles and the position and the color attributes of all of their vertices, your goal is to render the scene as a two-dimensional (2D) image. The parameters of a perspective…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

In this assignment, you are going to implement Modeling Transformation, Viewing Transformation, and Rasterization stages of the Forward Rendering Pipeline. Specifically, given a set of triangles and the position and the color attributes of all of their vertices, your goal is to render the scene as a two-dimensional (2D) image. The parameters of a perspective view camera will be specified similar to the first assignment. You will transform all of the vertices to the viewport and then use line drawing and triangle rasterization algorithms to display the triangles in wireframe or solid modes. You will implement a clipping algorithm of your choice (Cohen-Sutherland or Liang-Barsky) for wireframe mode only. You will also implement the backface culling (for both modes) for correct rendering of the scene. You will write your implementations in C++ language.

Keywords: forward rendering pipeline, modeling transformations, viewing transformations, line drawing, triangle rasterization, interpolation, clipping, backface culling

  • Specifications

    1. Name of the executable will be “rasterizer”.

    1. Your executable will take an input file name from command line. Input file names are not static, they can be anything.

    1. The scene will be composed of instances of meshes. A set of triangles will form a mesh with a sequence of several transformations (translation, rotation, scaling) you will be able to move, rotate, or resize a mesh (i.e., all of the triangles in the mesh). Transformations will be applied to the meshes in the order specified in the input file.

    1. You will not implement any lighting computations in this assignment. The color of each vertex will be provided as input and your goal will be to interpolate color along the edges and the surfaces of the triangles in wireframe and solid modes, respectively.

You will implement two types of projection transformations: orthographic projection and perspective projection.

  1. Use the midpoint algorithm to draw triangle edges and use the barycentric coordinates based algorithm to rasterize triangle faces.

  1. In both wireframe and solid modes, triangles whose backface is facing the viewer will be culled. Backface culling should be enabled/disabled according to the setting in input file. You should calculate normal vectors for backface culling. Default value for backface culling setting is ’disabled’.

  1. You will also implement a clipping algorithm of your choice. For example, you can choose an algorithm among algorithms that you saw on the lectures. You will do clipping for wireframe mode only. For solid mode meshes, you can assume that the mesh is completely visible to the camera.

  1. There can be multiple camera configurations for each given scene.

  1. You will NOT deal with reading input files.Helper functions for reading inputs, helper functions for mathematical operations (e.g. normalization, matrix multiplication) are given to you in “Scene.cpp” and “Helpers.cpp” files. It isSTRONGLY recommended to inspect types in header files and helper functions, which are given to you in homework stub code. You can modify these helper functions as you wish, or you can implement your own helper functions.

  1. Last important note: You will NOT implement depth buffer algorithm in this homework. Meshes will be given to you in back-to-front order. So, when you draw a mesh, you can assume that next mesh is closer to the camera than previous meshes.

Input File

You will not deal with reading input files, however, it is good for you to know what input file contains for testing purposes. Input files are in XML format and their structure is given below:

<Scene>

<BackgroundColor>R G B</BackgroundColor>

<Culling> enabled or disabled </Culling>

<Cameras>

<Camera id=”#” type=”perspective or orthographic”> <Position>X Y Z</Position>

<Gaze>X Y Z</Gaze>

<Up>X Y Z</Up>

<ImagePlane>

Left Right Bottom Top Near Far HorRes VerRes </ImagePlane>

<OutputName> <image_name>.ppm </OutputName> </Camera>

… more cameras …

</Cameras>

<Vertices>

<Vertex id=”1″ position=”X Y Z” color=”R G B” />

… more vertices …

</Vertices>

<Translations>

<Translation id=”1″ value=”tx ty tz” />

… more translations …

</Translations>

<Scalings>

<Scaling id=”1″ value=”sx sy sz” />

… more scalings …

</Scalings>

<Rotations>

<Rotation id=”1″ value=”angle ux uy uz” />

… more rotations …

</Rotations>

<Meshes>

<Mesh id=”#” type=”wireframe or solid”>

<Transformations>

<Transformation> <transformation_type> <transformation_id> </Transformation> … more transformations …

</Transformations>

<Faces>

<vertex_id_1_triangle_1> <vertex_id_2_triangle_1> <vertex_id_3_triangle_1> <vertex_id_1_triangle_2> <vertex_id_2_triangle_2> <vertex_id_3_triangle_2> … more faces (triangles) …

</Faces>

</Mesh>

… more meshes …

</Meshes>

</Scene>

3.1 Input File Sections

3.1.1 Background color:

Specifies the R, G, B values of the background.

3.1.2 Backface Culling Setting:

Specifies whether culling is applied or not. If it is ’disabled’, there will be no culling, just draw all triangles. If it is ’enabled’, culling should be done when triangle’s backface is facing to the viewer.

3.1.3 Cameras:

  • Id specifies the camera id.

  • Type specifies which projection transformation is applied. If it is ’orthographic’, that means you need to apply orthographic projection, If it is ’perspective’, you should apply perspective projection.

  • Position specifies the X, Y, Z coordinates of the camera.

  • Gaze specifies the direction that the camera is looking at.

  • Up specifies the up vector of the camera. The up vector is not necessarily given as orthogonal to the gaze vector. Therefore the camera’s x-axis is found by a cross product of the gaze and up vectors, then the up vector is corrected by a cross product of gaze and x-axis vectors of the camera.

  • ImagePlane specifies the coordinates of the image plane in Left, Right, Bottom, Top parameters; distance of the image plane to the camera in Near and distance of the far plane to the camera in Far parameters, and the resolution of the final image in HorRes and VerRes parameters. All values are floats except HorRes and VerRes, which are integers.

  • OutputName is a string which is the name of the output image.

3.1.4 Vertices:

  • Id specifies the vertex id.

  • Position specifies the position of the vertex in X Y Z.

  • Color specifies the color of each vertex in R G B.

3.1.5 Translations:

  • Id specifies the translation id.

  • Value specifies tx, ty, and tz, which are the translation parameters, i.e., translation amounts along the major axes.

3.1.6 Scalings:

  • Id specifies the scaling id.

  • Value specifies sx, sy, and sz, which are the scaling parameters, i.e., scaling level in the corresponding coordinate axes.

3.1.7 Rotations:

  • Id specifies the rotation id.

  • Value specifies α, ux, uy, and uz, which are the rotation parameters, i.e., the object is rotated α degrees around the rotation axis which pass through points (ux, uy, uz) and (0, 0, 0). The positive angle of rotation is given as the counter-clockwise rotation along the direction (ux, uy, uz).

3.1.8 Meshes:

  • Id specifies the mesh id.

  • Type specifies the type of the mesh. ’wireframe’ for wireframe, ’solid’ for solid ren-dering.

  • Each transformation has transformation type and transformation id parameters. The ‘t’ indicates a translation transformation, ‘s’ indicates a scale transformation, and ‘r’ indicates a rotation transformation. The transformation id ranges from [1 . . . translation count] for type ‘t’ transformations, and similarly for the other type of transformations.

  • In Faces section you can find the triangles and each line represents a triangle. Each triangle is given as a list of vertex ids in counter clockwise order when faced from the front side. Vertex ids start from 1.

Sample input/output

A sample camera and a scene file are provided below:

<Scene>

<BackgroundColor>255 255 255</BackgroundColor>

<Culling>enabled</Culling> <——- backface culling is enabled

<Cameras>

<Camera id=”1″ type=”perspective”> <——- perspective projection

<Position>-10 -40 -26</Position>

<Gaze>1 1 -0.2</Gaze>

<Up>0 1 0</Up>

<ImagePlane>-1 1 -1 1 2 1000 700 700</ImagePlane>

<OutputName>filled_box_1.ppm</OutputName>

</Camera>

<Camera id=”2″ type=”perspective”> <——- perspective projection

<Position>-20 -28 -23</Position>

<Gaze>1 0.5 -0.2</Gaze>

<Up>0 1 0</Up>

<ImagePlane>-1 1 -1 1 2 1000 700 700</ImagePlane>

<OutputName>filled_box_2.ppm</OutputName>

</Camera>

</Cameras>

<Vertices>

<Vertex id=”1″ position=”1.0 1.0 -1.0″ color=”100 100 100″ /> <Vertex id=”2″ position=”-1.0 1.0 -1.0″ color=”255 0 0″ /> <Vertex id=”3″ position=”-1.0 1.0 1.0″ color=”0 255 0″ /> <Vertex id=”4″ position=”1.0 1.0 1.0″ color=”0 0 255″ /> <Vertex id=”5″ position=”1.0 -1.0 -1.0″ color=”0 0 255″ /> <Vertex id=”6″ position=”-1.0 -1.0 -1.0″ color=”0 255 0″ /> <Vertex id=”7″ position=”-1.0 -1.0 1.0″ color=”255 0 0″ /> <Vertex id=”8″ position=”1.0 -1.0 1.0″ color=”100 100 100″ />

</Vertices>

<Translations>

<Translation id=”1″ value=”0.0 10.0 0.0″ /> <Translation id=”2″ value=”3.0 -3.0 -6.0″ />

</Translations>

<Scalings>

<Scaling id=”1″ value=”5.2 5.2 5.2″ /> </Scalings>

<Rotations>

<Rotation id=”1″ value=”45 0.0 1.0 0.0″ /> <Rotation id=”2″ value=”60 0.8 0.6 0.0″ />

<Rotation id=”3″ value=”20 1.0 0.0 0.0″ /> </Rotations>

<Meshes>

<Mesh id=”1″ type=”solid”> <——- mesh is drawn in solid mode

<Transformations>

<Transformation>r 1</Transformation>

<Transformation>t 2</Transformation>

<Transformation>s 1</Transformation>

</Transformations>

<Faces>

7 8 4

7 4 3

8 5 1

8 1 4

6 3 2

6 7 3

3 4 1

3 1 2

6 2 5

2 1 5

5 8 6

7 6 8

</Faces>

</Mesh>

</Meshes>

</Scene>

You can see outputs of this example in the next page.

(a) Solid-culling enabled (b) Solid-culling disabled

(c) Wireframe-culling enabled (d) Wireframe-culling disabled

Figure 1: Same mesh, different modes of rendering

  • Hints & Tips

    1. Start early!

    1. Note that in the wireframe mode only the edges of the triangle will be drawn.

    1. For debugging purposes, consider using simple scenes. Also it may be necessary to debug your code by tracing what happens for a single triangle (always simplify the problem when debugging).

    1. You can reach different inputs in“culling disabled inputs” and “culling enabled inputs” folders and desired images in “culling disabled outputs”, “culling enabled outputs” and “different projection type” folders. You will see that different camera angles, output of different rendering modes are provided to you to understand 3d scene and rendering modes completely.

  • Regulations

    1. Programming Language: C++

Late Submission: You can submit your codes up to 3 days late. Each late day will be deduced from the total 7 credits for the semester. However, if you fail to submit even after 3 days, you will get 0 regardless of how many late credits you may have left. If you submit late and still get zero, you cannot claim back your late days. You must e-mail your assistants if you want your submission to not be evaluated (and therefore preserve your late day credits).

  1. Cheating: We have zero tolerance policy for cheating. People involved in cheating will be punished according to the university regulations and will get 0. You can discuss algorithmic choices, but sharing code between each other or using third party code is strictly forbidden. To prevent cheating in this homework, we also compare your codes with online ray tracers and previous years’ student solutions. In case a match is found, this will also be considered as cheating. Even if you take a “part” of the code from somewhere/somebody else – this is also cheating. Please be aware that there are “very advanced tools” that detect if two codes are similar. So please do not think you can get away with by changing a code obtained from another source.

  1. Newsgroup: You must follow the announcements in OdtuClass (odtuclass.metu.edu.tr) for discussions and possible updates on a daily basis.

  1. Submission: Submission will be done via OdtuClass. You can team-up with another student. Create a .zip file that contains your source files and Makefile. The .zip file should not

include any subdirectories. Please make sure that your .zip file contains only the source files and Makefile, otherwise you may get a penalty. The .zip file name will be:

  • If a student works with a partner student:

<partner_1_student_id>_<partner_2_student_id>_rasterizer.zip

  • If a student works alone: <student_id>_rasterizer.zip

  • For example:

e1234567_e2345678_rasterizer.zip

e1234567_rasterizer.zip

Make sure that when below command is executed, your executable file is ready to use:

>_ make rasterizer

>_ ./rasterizer <input_file_name>

Therefore you HAVE TO provide a Makefile in your submissions.

  1. Evaluation: Your codes will be evaluated based on several input files including, but not limited to the test cases given to you as example. Rendering all scenes correctly will get you 100 points.

Last note: Your output format will be .ppm file as in the first homework. You will naturally want to view your outputs after running. You may face issues when you want to view your output file. You can open .ppm files in Ubuntu; however, you can not open .ppm files in Windows directly. You need a converter to do that. ImageMagick is a tool for displaying various image formats. It can also do conversion between formats. See the steps below:

    • If you are working with our department’s inek machines, you don’t need additional installation. ImageMagick is installed on ineks.

    • If you are using Ubuntu and running command “convert -version” on terminal gives version information, that means ImageMagick is installed on your system.

    • If you are using Windows and running command “magick convert -version” on terminal gives version information, that means ImageMagick is installed on your system.

    • Otherwise, you need to install it from here. After installation, use following lines according to your operating system:

For conversion on Ubuntu:

convertPPMToPNG(scene->cameras[i]->outputFileName, 1);

For conversion on Windows:

convertPPMToPNG(scene->cameras[i]->outputFileName, 2);

Now you can view your outputs on Ubuntu and Windows, in PNG format.

10

Assignment 2 - A Software Rasterizer implementing the Forward Rendering Pipeline
$24.99 $18.99