You are on page 1of 22

Version

2013-09-30 11:27

LOSUNG

Technische Universit
at M
unchen Institut f
ur Informatik
Lehrstuhl f
ur Computer Graphik & Visualisierung
Prof. R. Westermann

Exam: Game Engine Design


Surname:

First name:

Course of study:

Matriculation number:

Room:

Date:

Row:

August 2nd, 2013

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:

1.) Mesh Transformation and Rendering

(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.

Wrong Object Space

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

Game Engine Design Exams SS 2013

Name:

Matriculation number:

The following functions from the Direct3D 11 API are available:


D3DXMATRIX *
D3DXMATRIX *
D3DXMATRIX *
D3DXMATRIX *
D3DXMATRIX *

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

( D3DXMATRIX * pOut , const D3DXMATRIX * pM );


( D3DXMATRIX * pOut , float * pDeterminant ,
const D3DXMATRIX * pM );

// Assume this is already set correctly !

D3DXMATRIX CorrectAndTransform ( float x , float y , float z , float rotY )


{
// Your code here :
D3DXMATRIX matTransLocal ;
D 3 D X M a t rixT ransl atio n (& matTransLocal , 2 , -1.5 , 1.5);
D3DXMATRIX matScaleLocal ;
D3DX MatrixScaling (& matScaleLocal , -2 , 2 , 2);
// 1 Point per " correction component " ( translation , scaling , flip X ) = 3 P
D3DXMATRIX matTrans ;
D 3 D X M a t rixT ransl atio n (& matTrans , x , y , z );
D3DXMATRIX matRot ;
D 3 DX M a trixRotationY (& matRotY , rotY );
// 1 Point for correct world transformation ( translation + rotation )
return matTransLocal * matScaleLocal * matRot * matTrans * g_view ;

// 2 P order

// 2 P for correct usage : 1 P no " nullptr " as parameter , 1 P correct


// usage of pointers

// Alternative solutions : Additional rotation


D3DXMATRIX matRotLocal ;
D 3 DX M a trixRotationY (& matRotLocal , M_PI );
// ...
return matTransLocal * matScaleLocal * matRotLocal * matRot *
matTrans * g_view ;

Page 5 of 21

Game Engine Design Exams SS 2013

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 ;

Assume that g objects is already filled with several elements.


Fill out the function body below so that it iterates over the vector, calls CorrectAndTransform() with
the according parameters for each element and stores the result in the member variable transform.
In addition, transformNormals should be set to the matrix that transforms the objects normals to
view space without any assumptions about the performed transformations.
void Tr a n sf ormAllObjects ()
{
// Your code here :
for ( auto it = g_objects . begin (); it != g_objects . end (); ++ it ) // 1 P iteration
{
// 1 P correct call and assignment
it - > transform = CorrectAnd Transform ( it - >x , it - >y , it - >z , it - > rotY );
D3DXMATRIX inv ;
D3D XMatrixInverse (& inv , nullptr , & it - > transform );
// 1 P Inverse correct
// 1 P transpose & assignment
D 3 DXMatrixTranspose (& it - > transformNormals , & inv );
// Note : Inverse / Transpose order is arbitrary
}
// ... and some possible alternative iterations ...
for ( std :: vector < ObjectState >:: iterator i = ...) { ... }
for ( auto & obj : g_objects ) { obj . transform = ... }
std :: for_each ( g_objects . begin () , g_objects . end () , []( ObjectState & obj )
{ obj . transform = ... });

Page 6 of 21

Game Engine Design Exams SS 2013

Name:

Matriculation number:

1.3 Vertex Shader

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
};

: SV_POSITION ; // Clip space position


: TEXCOORD ;
// Texture coordinate
: NORMAL ;
// Normal in worldview space

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

Game Engine Design Exams SS 2013

Name:

Matriculation number:

1.4 Pixel Shader

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 ;

Texture2D < float > g_diffuse ;

float4 PS ( in PSIn frag ): SV_Target0


{
// Your code here :
//
1P
1 P Parameter
float4 color = g_diffuse . Sample ( sampler , frag . uv );
// 1 P Aufruf , 1 P Parameter
float l = dot ( normalize ( frag . normal ) , g_LightDirection . xyz );
// 1 P korrekte Rueckgabe , 1 P lightColor
return color * g_LightColor * l ;

Page 8 of 21

Game Engine Design Exams SS 2013

Name:

Matriculation number:

2.) Model Rendering

(9 Points)

The given vertex buffer and index buffer together define a 2D


mesh with D3D11 PRIMITIVE TOPOLOGY TRIANGLELIST. The
vertex buffer contains in consecutive order the x,y position and
the u,v texture coordinates for each vertex.

Texture

1
u

0,25

In the grid given in figure 2


(a) According to the vertex buffer, mark the vertex positions
with a cross.
(b) According to the index buffer, draw the triangles using
lines.

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

Game Engine Design Exams SS 2013

Name:

Matriculation number:

3.) Shaders in HLSL

(9 Points)

Below, four different vertex/pixel shaders are given in HLSL syntax:


cbuffer MyCBuffer {
matrix g_WorldViewProj ; // World - View - Projection matrix
float3 g_EyePos ;
// Position of the camera in world space
float3 g_LightDir ;
// Light direction in world space
};
struct StructA {
float3 pos : POSITION ;
float3 nor : NORMAL ;
};
struct StructB {
float4 svPos : SV_Position ;
float3 pos
: POSITION ;
float3 nor
: NORMAL ;
};
float3 Phong ( float3 normal , float3 light , float3 viewer ) {...}
float3 Gray ( float3 rgb ) { return ( float3 )( rgb . r + rgb . g + rgb . b ) / 3.0; }
void Shader1 ( in StructA i , out StructB o )
{
o . svPos = mul ( float4 ( i . pos , 1.0) , g_WorldViewProj );
o . pos = i . pos ;
o . nor = i . nor ;
}
float4 Shader2 ( in StructB i ) : SV_Target
{
return float4 ( Gray ( i . nor ) , 1.0);
}
float4 Shader3 ( in StructB i ) : SV_Target
{
i . nor = normalize ( i . pos );
i . nor = Phong ( i . nor , g_LightDir , normalize ( g_EyePos - i . pos ));
return float4 ( Gray ( i . nor ) , 1.0);
}
void Shader4 ( in StructA i , out StructB o )
{
o . svPos = mul ( float4 ( i . pos , 1.0) , g_WorldViewProj );
o . pos = i . pos ;
o . nor = Phong ( i . nor , g_LightDir , normalize ( g_EyePos - i . pos ));
}

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

Game Engine Design Exams SS 2013

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

Figure 3: Rendered images


3 Points per correct combination

Page 11 of 21

Game Engine Design Exams SS 2013

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

Figure 4: -1P for each incorrectly labeled region

Page 14 of 21

Game Engine Design Exams SS 2013

Name:

Matriculation number:

5.) Texture Mapping

(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

Game Engine Design Exams SS 2013

Name:

Matriculation number:

6.) Color Blending

(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

Game Engine Design Exams SS 2013

Name:

Matriculation number:

7.) Shading and Lighting

(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

Game Engine Design Exams SS 2013

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

Figure 6: 2P correct R, 4P correct angle

Page 18 of 21

Game Engine Design Exams SS 2013

Name:

Matriculation number:

8.) Collision Testing

(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

Figure 7: Collision Testing


circle-circle: 7 Tests: (8,1),(8,2),(8,3),(8,4),(8,5),(8,6),(8,7)
triangle-triangle: 3 tests - (8,4)

(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

Game Engine Design Exams SS 2013

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

Columns 1 and 2 need to be normalized ( 12 )


(c) Mirroring

1 0
0 1

0 0
0 0

Page 20 of 21

at the point (4, 0, 0)

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

Game Engine Design Exams SS 2013

Name:

Page 21 of 21

Matriculation number:

Game Engine Design Exams SS 2013

You might also like