Professional Documents
Culture Documents
2013-09-30 11:27
LOSUNG
Technische Universit
at M
unchen Institut f
ur Informatik
Lehrstuhl f
ur Computer Graphik & Visualisierung
Prof. R. Westermann
First name:
Course of study:
Matriculation number:
Room:
Date:
Row:
Seat:
Signature:
Notes:
Working time is 90 minutes.
This exam consists of two parts: Part I refers to content from the practical course, whereas Part II refers to content
from the lecture. In Part I you can gain a maximum of 42 points. In Part II you can gain a maximum of 64 points.
Please note: To pass the lecture Game Engine Design you need to gain a minimum of 40% of the points in each
part. If you fail to obtain the required amount of points in either part, the exam will be graded as failed.
Use a blue or black pen, do not use pencils, whiteouts or similar products.
No utilities are allowed. Use only the provided sheets of paper.
Write your name and matriculation number onto all sheets used for your solution before you start working on the
exam. We will not grade sheets without those details!
Write your solution onto the free space below each exercise or on the back of the respective sheet. Ask for additional
sheets if the space should not be sufficient!
Do not seperate the stapled sheets.
To exclude an exercise from grading, clearly cross out the entire page.
Write readable! Unclear parts of your exam will not be rated.
Do not give multiple or ambigous answers. If this is the case, only your last answer will be evaluated.
Check if you received all 21 pages and 9 exercises!
..................................
Erstkorrektur
..................................
Zweitkorrektur
Part I
Practical Course
42 Points, approx. 40 Minutes
13 Points needed to pass
Name:
Matriculation number:
(24 Points)
In this exercise, a number of meshes should be transformed and rendered with the Direct3D 11 API. In
each subtask, a part of this procedure should be implemented. All given information is valid throughout
all following subtasks, however all subtasks can be solved independently.
1.1 Transformations
8 Points
The object meshes are layed out wrong in object space as the example depicted in the left image in
figure 1 below. They should be transformed into the desired object space coordinate system given by
the right image.
Object Space
2
1
-3
-2
-1
-1
View
along
+Z
-3
-2
1
-1
-1
-2
-2
-1
-2
-3
3 x
View
along
-Y
-3
-2
-1
-2
-2
Figure 1: Transformation
Additionally, after object space correction for the world transformation each object should be rotated
around the y axis and translated by a given vector. It also should be transformed into view space using
the given matrix g view. Fill out the C++ function CorrectAndTransform() that receives the translation
components x, y, z and a rotation angle around the y axis in radians rotY. It should return a matrix
which performs these transformations.
Page 4 of 21
Name:
Matriculation number:
D3DXMatrixScaling
( D3DXMATRIX
D3DX Matr ixTra nsla tion ( D3DXMATRIX
D3DXMatrixRotationX ( D3DXMATRIX
D3DXMatrixRotationY ( D3DXMATRIX
D3DXMatrixRotationZ ( D3DXMATRIX
D3DXMATRIX * D3DXMatrixTranspose
D3DXMATRIX * D3DXMatrixInverse
D3DXMATRIX g_view ;
* pOut ,
* pOut ,
* pOut ,
* pOut ,
* pOut ,
float
float
float
float
float
sx , float sy , float sz );
x , float y , float z );
Angle ); // Angle in radians
Angle ); // Angle in radians
Angle ); // Angle in radians
// 2 P order
Page 5 of 21
Name:
Matriculation number:
1.2 std::vector
4 Points
Given is the following struct that defines an object state and a vector of ObjectState instances:
struct ObjectState
{
// Position
float x ;
float y ;
float z ;
// Rotation
float rotY ;
// Output matrix
D3DXMATRIX transform ;
D3DXMATRIX transformNormals ;
};
std :: vector < ObjectState > g_objects ;
Page 6 of 21
Name:
Matriculation number:
5 Points
Each of the objects is rendered with the following input layout bound:
const D 3 D 1 1 _ I N PU T _ E LE M E N T_ D E S C layout [] =
{
{ " POSITION " ,
0 , DXGI_FORMAT_R32G32B32_FLOAT , 0 ,
D3D11_APPEND_ALIGNED_ELEMENT , D3D11_INPUT_PER_VERTEX_DATA , 0 } ,
{ " TEXCOORD " ,
0 , DXGI_FORMAT_R32G32_FLOAT ,
0,
D3D11_APPEND_ALIGNED_ELEMENT , D3D11_INPUT_PER_VERTEX_DATA , 0 } ,
{ " NORMAL " ,
0 , DXGI_FORMAT_R32G32B32_FLOAT , 0 ,
D3D11_APPEND_ALIGNED_ELEMENT , D3D11_INPUT_PER_VERTEX_DATA , 0 }
};
Complete the given input struct VSIn and write a vertex shader that receives vertices of this type as
an input. It should transform the vertex positions to clip space and the normals to view space and
output them to be used in a pixel shader. All other attributes should be passed through without any
modifications.
cbuffer M y F irs tCon stan tBuff er
{
// Contains a matrix that transforms normals from object space to view space
matrix g_WorldViewNormals ;
// Contains a matrix that transforms positions from object space to clip space
matrix g_WorldViewProj ;
};
struct PSIn {
float4 pos
float2 uv
float3 normal
};
struct VSIn {
// Your code here :
float3 position : POSITION ;
float2 uv : TEXCOORD ;
float3 normal : NORMAL ;
};
// 1 P correct
// Your code here :
void VSOfDoom ( in VSIn input , out PSIn output )
// 1 P
{
output . pos = mul ( float4 ( input . position . xyz , 1) , g_WorldViewProj );
output . uv = input . uv ;
// 1 P
output . normal = normalize ( mul ( float4 ( input . normal . xyz , 0) ,
g_ WorldViewNormals ));
// 1 P
}
Page 7 of 21
// 1 P
Name:
Matriculation number:
7 Points
Fill out the given empty pixel shader such that the texture g diffuse is sampled at the fragments
texture coordinate using the given sampler state. On the resulting color, calculate simple N dot L
lighting and return the result. Also answer the following question:
Which kind of shading is implemented here? Your Answer: Phong (1P)
cbuffer M y S ec on dCo ns ta ntB uf fe r
{
float4 g_LightDirection ; // Light direction in view space
float4 g_LightColor ;
// Light color
};
SamplerState
{
Filter =
AddressU
AddressV
};
sampler
ANISOTROPIC ;
= Wrap ;
= Wrap ;
Page 8 of 21
Name:
Matriculation number:
(9 Points)
Texture
1
u
0,25
0,75
(c) In the image to the right, a texture is depicted in texture space. According to the texture coordinates (using
barycentric interpolation), draw the mapping of this texture onto the rendered triangles into figure 2.
11
Vertex Buffer
12
10
12
0.5
12
23
10
Index Buffer
11
12
13
13
12
11
10
9
8
7
6
5
4
3
4
2
1
10
14
15
Figure 2: Vertices 4 points (-1 per incorrect vertex), triangles 3 points (-1 per incorrect triangle), texture
2 points
Page 9 of 21
Name:
Matriculation number:
(9 Points)
In the code above, Phong() is a function which evaluates the Phong lighting model (in a not further
specified way) and returns the resulting RGB color (assuming white light and a white object).
Page 10 of 21
Name:
Matriculation number:
Three different combinations of these shaders were employed to render a sphere mesh centered at the
origin with per-vertex normals and light coming from the front (with respect to the following images).
The global variables g * were set to appropriate values (see comments in the code) which were constant
throughout the experiment.
Write below each of the images in figure 3 the name (Shader1, Shader2,...) of the vertex shader (VS)
and pixel shader (PS) that was used in the rendering of the image.
VS: Shader4
VS: Shader1
VS: Shader1
PS: Shader2
PS: Shader2
PS: Shader3
Page 11 of 21
Part II
Lecture
64 Points, approx. 50 Minutes
20 Points needed to pass
Name:
Matriculation number:
4.) Rasterization
(10 Points)
(a) Name 2 operations which are performed on the incoming vertex coordinates in the rasterization
stage.
2 Points
e.g. Homogeneous division, viewport transformation
(b) Does the rasterizer need to know the resolution of the currently selected viewport?
2 Points
Yes
(c) Name 3 parameters on which the number of fragments depends which are generated by the
rasterizer for a triangle.
2 Points
e.g. size, orientation, viewport resolution, distance
(d) The triangle in figure 4 subdivides the 2D plane in 7 regions as illustrated. Give the signs of
the barycentric coordinates with respect to triangle ABC for all points in the 7 regions. It is
sufficient to specify a value {, +}3 for each region. For instance, (+, +, +) if all points in the
region have positive barycentric coordinates.
4 Points
Page 14 of 21
Name:
Matriculation number:
(10 Points)
(a) At which stage in the rasterization-based rendering pipeline is a texture value assigned to a surface
point?
2 Points
Pixel or fragment stage / shader
(b) In Figure 5, a 2D texture map consisting of white (white circles) and black (black circles) texture
values is illustrated. For this texture, compute the texture values using bilinear interpolation at
the texture coordinates (0.5, 0.5) and ( 48 41 18 , 48 14 18 ).
4 Points
Solution: 0.5 and
6
16
= 0.375
Figure 5: Texture
(c) For the texture in Figure 5, compute the texture value using bilinear interpolation at the texture
coordinate (0.4, 0.4) in the mipmap level l = 1, i.e. the mipmap level succeeding the finest
resolution level.
4 Points
Solution: 0.5
Page 15 of 21
Name:
Matriculation number:
(8 Points)
What color is seen when looking along a ray which first hits an object with color (0.5, 0, 0, 0.5), then an
object with color (1, 1, 1, 0), and then an object with color (0.25, 0, 0, 0.5)? Assume a black background
(color (0, 0, 0, 1)). Here, the first three color components specify the Red, Green, and Blue components,
respectively, and the fourth component specifies the opacity. Opacity ranges from 0 to 1, where 0
indicates full transparency and 1 indicates full opacity. Use -blending to compute the color.
R = 12 12 + 12 0 1 + 21
G=B=0
(A = 1), not necessary
Page 16 of 21
1
2
1
4
1
4
1
16
5
16
= 0.3125
Name:
Matriculation number:
(16 Points)
(a) Given is a perfectly specular reflecting plane containing the origin (0, 0, 0)T in 3D space. The
plane is described by the set of all points (x, y, z) T such that
x
2
y 1 =0
z
0
A point light source is positioned at (10, 0, 0) T . Compute the direction of the reflected light
at the point in the plane at position (0, 0, 0)T . Note: Answers without a derivation will not be
graded. Arithmetic expressions like square roots do not have to be evaluated.
4 Points
T
(2,1,0)
2
, 15 , 0)T .
Reflection normal: n = ||(2,1,0)
T || = (
5
Reflection formula: v = i 2n(i n)
Light direction: i = (1, 0, 0)T
4
T
Result: v = ( 3
5 , 5 , 0)
(b) Given is the plane y = 0. A point light source is positioned at (1, 10, 1). The plane reflects only
diffuse. The viewer is positioned at (4, 6, 4) and sees all points on the plane with 0 x 8 and
0 z 8. At which point on the plane does the viewer perceive the highest reflection? 4 Points
Solution: (1, 0, 1)
(c) Describe the visual difference between shading a triangle using a) Gouraud shading and b) Phong
shading in the situation where a specular highlight lies entirely in the interior of the triangle.
2 Points
Gouraud: highlight can be missed if no vertex is in light cone. Phong: highlight will be
visible in the interior of the triangle.
Page 17 of 21
Name:
Matriculation number:
(d) Given is a scene as illustrated in Figure 6. Let p be a point on a specular reflecting material
surface. Assume L (the vector from p to the light source), N (the normal at p), and V (the
vector from p to the viewer) are all in the same plane. Draw into this illustration the angle
which is used in the Phong illumination model to compute the specular reflection.
6 Points
Page 18 of 21
Name:
Matriculation number:
(10 Points)
Given is a 2D scene consisting of 4 triangles (grey triangles in Figure 7). The circles indicate a corresponding bounding circle hierarchy (the hierarchy is depicted on the right of Figure 7). For another set
of 3 triangles (black triangles in Figure 7) the bounding circle is shown in bold. The numbers in the
Figure indicate the respective spheres.
(a) How many circle-circle tests and how many triangle-triangle tests have to be performed to test
for collisions between the grey and black triangles in the situation shown in Figure 7? Note: The
test has to make use of the bounding spheres representation. Write down all circle-circle tests as
pairs (i, j), where i and j are the numbers indicating the circles.
6 Points
(b) How many triangle-triangle tests have to be performed when active intervals of the circles indexed
3,4,6,7,8 along the horizontal and vertical axis of the 2D domain are used?
4 Points
(8,6) 3 tests, (8,4) 3 tests - 6 tests
Page 19 of 21
Name:
Matriculation number:
9.) Transformations
(10 Points)
(a) Write down a 33 matrix which realizes the following transformation: A 2D perspective projection
in the x/y-plane onto the line y = 0. The center of projection is at (0, 6). After the projection
the homogeneous component should be such that the homogeneous division generates the correct
values.
4 Points
1 0 0
0 0 0
0 16 1
In the following exercises you are supposed to specify the coefficients of 4 4 transformation matrices
for the representation of affine mappings in R3 . The coefficients should be given as precise as possible,
i.e., numbers should be given if possible and identifiers else. The same coefficients should be given the
same identifier. If a matrix can be specified by concatenation of multiple matrices, the concatenation
does not have to be computed explicitly.
Example: isotropic scaling
s
0
0
0
0
s
0
0
0
0
s
0
0
0
0
1
(b) A rotation so that the vector (1, 0, 0) is aligned with the vector (1, 1, 0), the vector (0, 1, 0) is
aligned with the vector (1, 1, 0), and the vector (0, 0, 1) is aligned with the vector (0, 0, 1).
4 Points
1 1 0 0
1 1 0 0
0 0 1 0
0 0 0 1
1 0
0 1
0 0
0 0
Page 20 of 21
0 4
1 0
0 0
0 0 0 1 0 0
1 0 0
0 1 0
0
0
0 1
0 1
1 0
0 1
0 0
0 0
2 Points
0 4
1 0
0 8
0 0 0 1 0 0
=
0 1 0
1 0 0
0
0
0 1
0 1
Name:
Page 21 of 21
Matriculation number: