首页 >
> 详细

1902/159.360

MTUI DISD

EXAMINATION FOR

159.360 Programming for Computer Graphics

Semester Two 2019

Time Allowed: THREE (3) hours

Students are required to answer all questions.

This examination is Open Book - no restrictions on reference material.

Question 1 - Bend it like Beckham

(a) Consider the 2D scene below, where a soccer ball is kicked toward a goal. The ball is spinning

clockwise around its center, so that air friction is causing it to bend in a curve.

Describe how to create an animation of the ball spinning towards the goal in a curve.

[5 marks]

Answer: Using kinematics/dynamics:

1. Specify initial position, rotation angle and velocity vector.

2. Draw frame at current position and angle.

3. Update angle and velocity, then update position using velocity.

4. Repeat 2 & 3.

(b) Construct a matrix that rotates a 2-dimensional soccer ball object centered at the origin

clockwise by θ degrees, and moves it to position (x, y).

[5 marks]

Answer: Use homogeneous coordinates for translation, and −θ for clockwise rotation:

Note that cos(−θ) = cos(θ), sin(−θ) = − sin(θ).

Question 2 – Easy A

(a) Consider the following polygon of a stylized A:

Numbers 1-5 denote the corners of the polygon, in order, while letter a denotes the intersection

point of edges 2-3 and 4-5. For each of the sub-polygons 1-4-3, 2-a-4, 5-3-a and

3-4-a, state whether they lie inside or outside the polygon area, w.r.t. the odd-even

rule and the non-zero winding number rule.

[4 marks]

Answer: 3-4-a lies outside for odd-even rule and inside for non-zero-winding number rule.

All others lie inside for both rules.

(b) To draw complex polygons in WebGL, we must decompose them it into triangle lists, triangle

strips or triangle fans. A disvantage of using triangle lists is that vertex data (e.g. position)

is often repeated. Explain how this issue can be mitigated.

[2 marks]

Answer: Element buffers add a level of indirection that allows us to reuse vertex data without

specifying it multiple times.

(c) Consider another polygon of a stylized A:

(i) Show how the polygon can be represented using a single triangle strip. Do so by

listing the vertices in the order that you would pass them to WebGL.

Answer: 2-3-1-4-5 or 5-4-1-3-2

(ii) Show how the polygon can be represented using a single triangle fan.

[2 marks]

Answer: 1-2-3-4-5 or 1-5-4-3-2

Question 3 – Source Code

Consider the GLSL vertex shader code below:

1: attribute vec3 aPosition, aNormalVector;

2: uniform mat4 uPerspective;

3: uniform vec3 uLightSource;

4: varying float vBrightness;

void main() {

5: gl_Position = uPerspective * vec4(aPosition, 1);

6: vec3 lightVector = normalize(uLightSource - aPosition);

7: vBrightness = dot(lightVector, aNormalVector);

}

Explain what this code does, both on a high level and with details for every line.

[10 marks]

Answer: The vertex shader implements Gouraud shading for diffuse reflection with a point

lightsource. In detail:

1. Input: position and normal vector for a point on the surface.

2. Input: perspective projection matrix (same for all vertices)

3. Input: position of the light source

4. Output: light intensity at the surface point

5. The assignment gl Position = uPerspective * vec4(aPosition, 1) applies the perspective

projection matrix to the vertex position and passes the result to the graphics

engine. vec4(aPosition,1) turns the position into homogenous coordinates.

6. Compute the normalized direction vector from the surface point to the light source.

7. Compute the brightness as scalar product between the surface normal and light source

direction. The result is passed to the fragment shader.

Question 4 - Now you see me

(a) Modern graphics cards offer depth-buffering (aka z-buffering) as a built-in feature. The

following techniques can also aid in visible surface detection:

• Backface detection

• Depth-sorting

• BSP-Trees

Discuss whether or not hardware support for depth-buffering makes them obsolete.

[6 marks]

Answer: None of these techniques is required to render opaque surfaces correctly with depthbuffering

enabled. However:

• The purpose of backface detection is to speed up computation, and that is still helpful.

• Depth-sorting and BSP-trees can aid in rendering transparent surfaces, which depthbuffering

does not handle well.

Thus, backface detection is never obsolete, while dept-sorting and BSP-tree may or may not

be obsolete, depending on application requirements.

(b) Given a triangle T represented by the positions of its corners and normal vector N:

work out whether it is facing towards or away from the camera located at the origin.

Show your working.

[4 marks]

Answer: We compute the scalar product between the vector from some point of the triangle

(which point does not matter) to the camera and the normal vector:

As this scalar product is negative, the triangle is facing away from the camera.

Question 5 - Blinded by the Light

(a) The Phong lightning model has three components: ambient light, diffuse reflection and

specular reflection. For each of them explain how they work and how they relate to

illumination in the real world.

[5 marks]

Answer:

• Ambient light provides basic illumination to surfaces regardless of their position and

orientation. It models light reflected from other surfaces.

• Diffuse reflection provides illumination based on the angle between the surface and

incoming light. It models light reflected by dull surfaces.

• Specular reflection provides illumination based on the angles between the surface, incoming

light and the camera. It models light reflected by shiny surfaces.

(b) Diffuse and specular reflection can be implemented using either Gouraud or Phong shading.

Explain how these approaches differ, and discuss tradeoffs.

[5 marks]

Answer: In both cases, the vertex shader receives a surface normal vector for each vertex.

For Gouraud shading, the brightness value is calculated at each vertex and passed to the

fragment shader, so the brightness values get interpolated. For Phong shading the normal

vector is passed to the fragment shader, where the brightness value gets calculated based

on the interpolated normal vector.

Gouraud shading is faster, as brightness calculations are done only once per vertex instead

of once per pixel, but Phong shading provides more accurate lighting.

Question 6 - Blended

When working with textures, several common techniques for anti-aliasing exist.

(a) Explain how MIP maps work.

[2 marks]

Answer: Multiple resolutions of a texture are stored, and the one closest to screen resolution

is used. This avoids aliasing effects as most texels get sampled.

(b) Explain how RIP maps work.

[2 marks]

Answer: Like MIP maps, but also stores multiple textures for different x:y ratios. This

avoids aliasing effects for surfaces seen at steep angles.

(c) Explain how bi-linear filtering works.

[2 marks]

Answer: Instead of picking the color of the texel closest to the sampling point, the colors of

several closest texels are interpolated. This ensures more texels get sampled.

(d) Explain how tri-linear filtering works.

[2 marks]

Answer: Instead of just using a single MIP/RIP map, the MIP/RIP maps with closest

resolution are used and results interpolated. This avoids visual effects at polygon edges due

to resolution changes.

(e) Which of the following approaches will provide visually better results?

• bi-linear filtering with MIP maps

• tri-linear filtering without MIP maps

Justify your answer.

[2 marks]

Answer: Tri-linear filtering without MIP maps (i.e., just a single texture) is equivalent to

bi-linear filtering. And Bi-linear filtering is better with MIP maps than without.

联系我们

- QQ：99515681
- 邮箱：99515681@qq.com
- 工作时间：8:00-23:00
- 微信：codinghelp

- 代写cmpt 214编程、代做programming语言、代写c/C++程序 2020-11-08
- 代写csci 2122课程、代做program编程实验、C++程序语言代写代 2020-11-08
- Fit5032语言编程代做、代写web程序实验、Web、Html程序语言代做 2020-11-08
- Com3503程序编程代做、Java，C++，Python留学生编程代写代写 2020-11-08
- 代写program程序课程、代写c++编程实验、C/C++编程语言代做 代做 2020-11-08
- Data留学生编程代做、代写python程序、Java，C++程序语言代写 2020-11-08
- 代写secj 1023实验编程、Programming程序代做、代写c++语 2020-11-08
- 代写cmpsc 465编程、代做java程序语言、Python，C++编程设 2020-11-07
- 代做mf 703语言编程、代写programming程序、Sql编程语言调试 2020-11-07
- 954246编程设计调试、代做programming程序、C++编程语言代写 2020-11-07
- Pstat 115程序实验代写、R编程语言调试、Data留学生程序代做 代写 2020-11-07
- Com1005课程编程代做、代写python程序、Java，C++程序语言调 2020-11-07
- Tcp留学生程序代写、Java程序设计调试、Java编程语言代写 帮做r语言 2020-11-07
- 代写program语言编程、代做data留学生程序、Python，Java编 2020-11-07
- 代做cosc2666编程、代写programming程序、C/C++程序语言 2020-11-07
- Digital编程设计代写、代做r程序实验、代写r留学生程序 调试matla 2020-11-07
- 代写programming程序实验、R程序语言调试、Data课程编程代做 代 2020-11-07
- Comp104-17B程序代写、代做c++编程实验、C++程序语言调试 帮做 2020-11-07
- Csc8501课程程序代做、C++编程语言调试、代写program编程课程 2020-11-07
- 代写css3留学生程序、代做html、Css编程语言、Data课程程序代做 2020-11-07