COSC363-19S1 (C) Computer Graphics 2019
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
Mid-year Examinations, 2019
COSC363-19S1 (C) Computer Graphics
Question 1. [17 marks for the whole question] Transformations
For each of the questions (a)-(c) given below, write a small code segment containing only OpenGL transformation functions for generating the required output.
(a). (3 Marks) Refer to Fig. 1a. In the figure, 'A' refers to the initial display obtained by calling the function glutSolidTeapot(1). Write the code segment required for producing the teapot 'B' located at a point on the xy-plane at an angle 30 from the x-axis. The distance of the point 'B' from the origin is 3 units (radius of the circular section shown in the figure)
(b). (4 Marks) Refer to Fig. 1b. In the figure, 'A' refers to the initial display of an object obtained by calling a user-defined function drawArrow(). Write the code segment required for scaling the object along the x-axis by a factor of 2, and then rotating the scaled object about a pivot point (4, -2, 0) by 30 about the z-axis.
(c) (5 Marks) Refer to Fig. 1c. In the figure, 'A' refers to the initial display of an object obtained by calling a user-defined function drawArrow(). The length of the arrow shaped object is 3 units. Create another copy of the object and reflect it along the x-axis (horizontal flip), and move the objects along the x-axis to produce the display denoted by 'B'. Apply a single rotation by 30 about the z-axis to both objects to get the final output denoted as 'C'. (hint: Use glPushMatrix() and glPopMatrix())
Fig. 1a |
Fig. 1b |
Fig. 1c |
(d) (4 Marks) A point (x, y, z) is transformed using a set of matrices as follows:
Please describe the sequence of transformations (including the types of transformations, parameters,
and the order of transformations) represented by the above matrix expression.
(e) (1 Mark) Based on your answer to the previous question (d), what would be the output if the above transformation was applied to the point (0, 0, 0, 1)? You are not required to perform any numerical computation or matrix multiplication.
Question 2. [10 marks for the whole question] Mathematical Preliminaries
(4, 3, 1)
(3, 0, 6)
Consider the triangle shown in Fig. 2. The vertex coordinates of the triangle are given in the figure.
(a). (5 Marks) Compute the vectors a, b, indicated in the figure, and use them to compute the
components of the normal vector n of the triangle.
(b). (2 Marks) Normalize the vector n to a unit vector.
(c). (3 Marks) Compute the angle between the normal vector n and the x-axis.
Question 3. [10 marks for the whole question] Illumination Models
The following figure (Fig. 3) gives the components of unit vectors used for lighting calculations at a point P on a sphere, and also the ambient, diffuse, specular properties of the light L and the sphere material (l = light source vector, n = normal vector, v = view vector, r = reflection vector). Assume that L is the only light source in the scene.
f (Phong’s constant) = 10.
Fig. 3.
Light’s properties:
La = (0.2, 0.2, 0.2) Ld = (1, 1, 1)
Ls = (1, 1, 1)
Material properties:
Ma = (0, 1, 1)
Md = (0, 1, 1)
Ms = (1, 1, 1)
(a) (2 Marks) Write the colour components of the net reflection from the vertex Q.
(b) (3 Marks) Write the mathematical expression for the colour of the diffuse reflection at vertex P, and compute the numerical values of its components.
(c) (3 Marks) Write the mathematical expression for the colour of specular reflection (including the shininess term) at P along the view direction v, and compute the numerical values of the colour components.
(d) (2 Marks) Write the expression for the half-way vector at P, and also the modified formula for computing the specular reflection using the half-way vector. You are not required to perform any numerical calculation for this question.
Question 4. [12 marks for the whole question] Texture Mapping
The polygonal object shown in Fig.4a is created using a quad-strip {A1, A2, B1, B2, C1, C2, D1, D2 }. The top side consists of two triangles A2B2P, C2D2Q and a quad PB2 C2Q. Consider the texture image of size NxN pixels given in Fig. 4b.
Q
C2
D1
B1
Fig. 4a.
N/4 N/2
|
N
Fig. 4b.
N/2
Fig. 4c.
(a) (8 Marks) Write the texture coordinates (s, t) that must be assigned to the vertices, so that the
quad-strip displays 5 repetitions of the horse image distributed evenly across the three segments; and the quad PB2 C2Q on the top displays the disc (Fig. 4c). Assume that the texture wrap mode is set to GL_REPEAT along s and t. Please provide your answer in the answer-booklet in the following format:
Quad-strip s t
A1
A2
B1
B2
C1
C2
D1
D2
Quad
P
B2
C2
Q
(b) (4 Marks) Briefly describe (in 3 or 4 sentences) what is meant by “mipmapping”, and its usefulness in texture mapping. You are not required to give any equations.
Question 5. [10 marks for the whole question] View Transformation
y
C
30
x
40
Fig. 5a
C
O |
|
T |
Fig. 5b
|
Fig. 5c
|
Fig. 5d
A teapot is placed at position T on the x-axis at a distance of 40 units from the origin, as shown in Fig. 5a. The camera is placed at a fixed position C along the y-axis at a height of 30 units.
(a) (2 Marks) Write the parameter values of the camera function gluLookAt(ex, ey, ez, lx, ly, lz, ux, uy, uz), that places the teapot along the view axis of the camera and generates an output similar to that given in Fig. 5c.
(b) (3 Marks) Redraw the triangle in Fig 5b in your answer booklet and mark the directions of the camera axes xe, ye, ze (eye coordinate frame) at C, where the view axis of the camera is along CT. Indicate an out-of-plane axis with a dashed line.
(c) (2 Marks) The camera is rotated by 180 degrees at position C, keeping the view direction fixed, to generate the output given in Fig. 5d. Write the parameter values of the function gluLookAt(...) for this configuration.
(d) (3 Marks). The teapot is at a distance of 50 units from the camera. Write the coordinates of T and C in both the world coordinate frame and the eye coordinate frame for the camera configuration given in Q.5(a).
Question 6. [10 marks for the whole question] Projection Transformation
A view frustum is specified using the following statement:
glFrustum(-50.0, 50., -30., 30., 50.0, 100.0);
(a) (6 Marks) Draw a sketch of the view frustum, clearly showing what each of the six parameters
of the above function represents. The figure should also show the camera position, camera coordinate axes directions, and the view axis direction.
(b) (4 Marks) Using the parameters of the function, compute the aspect ratio of the near plane, and the field of view along the y-direction.
Question 7. [16 marks for the whole question] Ray Tracing
m
g
h
2
Fig. 6a
P
L
(a) (3 Marks) Fig. 6a shows the refraction of an incident ray d through a sphere. The normal vectors
are indicated by dashed lines. The refractive indices of the two mediums are also shown. You are given the function refract(d, n, eta) that returns the direction of the refracted ray, given the direction of the incoming ray 'd', and the surface normal direction 'n' at the point of intersection directed towards the incident ray's medium. Write the function statements with appropriate parameters required to compute the outgoing ray's direction h. For each refracted ray, give the expression for 'eta' as a ratio of refractive indices.
(b) (3 Marks) Refer to Fig. 6b. A shadow ray is traced from a point P towards a light source L, and
intersects a sphere at Q. Write the conditions to be satisfied by Q in order that the point P is in shadow. Assume that the ray does not intersect any other object.
(c) (6 Marks) The points of intersection of the ray p = P + td and a sphere centered at a point C with radius r is given by
t (s d) (s d)2 (s s) r2 , where s = PC.
If P = (2, 1, 2), C = (10, 7, 2), d = (0.8, 0.6, 0), and r = 4, compute the values of the ray intersection parameter t using the above formula.
(d) (2 Marks) With reference to the previous question Q7(c), write the coordinates of the point of intersection on the sphere that lies closest to P.
(e) (2 Marks). Give a geometrical interpretation of the parameters t, s used in the equation given in
Q7(c).
Question 8. [15 marks for the whole question] OpenGL Shaders
(a) (4 Marks) Briefly describe two important operations performed in a vertex shader and in a
tessellation control shader.
Fig. 7
(b) (6 Marks) A quad domain is tessellated as shown in the figure above (Fig. 7). Write the inner
and outer tessellation levels used in generating the figure, and also give the tessellation
coordinates of the points A, B, C and D.
(c) (5 Marks) A part of a tessellation evaluation shader is shown below.
void main()
{
float u = gl_TessCoord.x;
float v = gl_TessCoord.y;
posn = (1-u)* (1-v) * gl_in[0].gl_Position
+ u * (1-v) * gl_in[1].gl_Position
+ u * v * gl_in[2].gl_Position
+ (1-u) * v * gl_in[3].gl_Position;
gl_Position = mvpMatrix * posn;
}
Give a brief description of each of the four statements in the above code segment, explaining the meanings of the variables gl_TessCoord, gl_in[].gl_Position, posn, and gl_Position.
2022-06-11