Graphics Programming for Games II Jan 2011

14
 B.Sc. in Computing in Computer Games Development Year 3 January 2011 Letterkenny Institute of Technolo gy Course Code: PROG K7B01  Subject: Graphics Programming for Games II Stage: Award Date: January 2011 Examiners: Mr. Dermot Hegarty Dr. M. McNeill Time allowed: 2 hours  INSTRUCTIONS Answer any THREE questions from four All questions carry equal marks There are Appendices at the end of the examination paper containing information which may be useful in answering questions  Graphics Programming for Games II Page 1 of 14  BACHELOR OF SCIENCE IN COMPUTING IN COMPUTER GAMES DEVELOPMENT  

Transcript of Graphics Programming for Games II Jan 2011

8/3/2019 Graphics Programming for Games II Jan 2011

http://slidepdf.com/reader/full/graphics-programming-for-games-ii-jan-2011 1/14

 B.Sc. in Computing in Computer Games Development – Year 3 January 2011

Letterkenny Institute of Technology 

Course Code: PROG K7B01

 

Subject: Graphics Programming for Games II Stage: Award

Date: January 2011 Examiners: Mr. Dermot Hegarty Dr. M. McNeill

Time allowed: 2 hours  

INSTRUCTIONS

Answer any THREE questions from fourAll questions carry equal marks

There are Appendices at the end of the examination paper containinginformation which may be useful in answering questions

 

Graphics Programming for Games II Page 1 of 14

 BACHELOR OF SCIENCE IN COMPUTINGIN

COMPUTER GAMES DEVELOPMENT 

8/3/2019 Graphics Programming for Games II Jan 2011

http://slidepdf.com/reader/full/graphics-programming-for-games-ii-jan-2011 2/14

 B.Sc. in Computing in Computer Games Development – Year 3 January 2011

Question 1

(a) Explain how blending is achieved using OpenGl. Note that Appendix Agives an example of simple two-dimensional blending.

(6 marks)

(b) For three-dimensional blending we should implement the followingsequence of events:Draw opaque objects first. Then make depth buffer read-only and draw translucent objects.(i) Explain why opaque objects must be drawn before transparent

objects.(2 marks)

(ii) What is the purpose of making the depth buffer read-only?(4 marks)

(c) Appendix B shows some code that uses a display list and shows theresulting display.(i) Using the appendix as an example, give a detailed explanation of 

OpenGL display lists and how they can be used improveperformance (frame rate, for example). In your answer, explainwhy the drawing of the four green larger triangles will requiremuch more overall processing effort than the triangles in thedisplay list. Hints: immediate mode, retained mode; what getssent to the graphics card and when?

(9 marks)

(ii) Change the code such that the display list contains the fivetriangles, i.e. no need for the ‘for(i = 0; i < 5; i++)’

loop.(4 marks)

Graphics Programming for Games II Page 2 of 14

8/3/2019 Graphics Programming for Games II Jan 2011

http://slidepdf.com/reader/full/graphics-programming-for-games-ii-jan-2011 3/14

 B.Sc. in Computing in Computer Games Development – Year 3 January 2011

Question 2

(a) The figure above gives a visual depiction of the OpenGL graphicspipeline.Are shaders concerned with clipping? Explanation of your answer shouldmake reference to the diagram.

(3 marks)

(b) List the steps taken to provide shaders in an OpenGL applicationprogram.

(6 marks)

(c) Give brief explanations for the follow types of variables in GLSL: varying,uniform.

(4 marks)

(d) Give the code for a pass-through vertex shader and a pass-throughfragment shader.

(6 marks)

(e) Below is a vertex shader and an associated fragment shader. Explainwhat each shader does and what the overall effect is.

(6 marks)

vertex shader :

varying vec3 normal;

void main()

{

normal = gl_NormalMatrix * gl_Normal;

gl_Position = ftransform();}

Graphics Programming for Games II Page 3 of 14

8/3/2019 Graphics Programming for Games II Jan 2011

http://slidepdf.com/reader/full/graphics-programming-for-games-ii-jan-2011 4/14

 B.Sc. in Computing in Computer Games Development – Year 3 January 2011

  fragment shader:

varying vec3 normal;

void main(){

float intensity;vec4 color;vec3 n = normalize(normal);

intensity = dot(vec3(gl_LightSource[0].position),n);

if (intensity > 0.95)color = vec4(1.0,0.5,0.5,1.0);

else if (intensity > 0.5)color = vec4(0.6,0.3,0.3,1.0);

else if (intensity > 0.25)color = vec4(0.4,0.2,0.2,1.0);

elsecolor = vec4(0.2,0.1,0.1,1.0);

gl_FragColor = color;}

Graphics Programming for Games II Page 4 of 14

8/3/2019 Graphics Programming for Games II Jan 2011

http://slidepdf.com/reader/full/graphics-programming-for-games-ii-jan-2011 5/14

 B.Sc. in Computing in Computer Games Development – Year 3 January 2011

Question 3

In the context of 2-D texture mapping describe each of the following (notethat each item is worth five marks, so descriptions should be relatively

pointed and not unnecessarily verbose or elaborate):

(a) Mip-mapping(b) Tri-linear filtering(c) Specular suppression(d) Texture objects(e) Texture co-ordinates (only discuss manual generation; mention

wrapping modes)

Graphics Programming for Games II Page 5 of 14

8/3/2019 Graphics Programming for Games II Jan 2011

http://slidepdf.com/reader/full/graphics-programming-for-games-ii-jan-2011 6/14

 B.Sc. in Computing in Computer Games Development – Year 3 January 2011

Question 4

Note: Appendix D contains equations and geometry related to the PhongLighting Model. You may find this useful.

(a) Appendix C shows code which produces a sphere, cone and teapot withdemonstrating lighting.Use it to explain OpenGL’s simulation of lighting and materialreflectivity. In your explanation, make sure to cover the essentialdifferences between ambient, diffuse, and specular reflection; mentionthe roles of normals in OpenGL programs such as the one given; mentionhow OpenGL combines lighting contributions.

(12 marks) 

(b) Write the few lines of code would make the SolidSphere (from part a)into a red ball and much less shiny than it is now, but not completelymatte.

(3 marks)

(c) Given the code fragment below, and, considering ambient and diffuseonly, explain what will be the colour (shade) at vertex vf[0]. Assumethat the light direction is in the direction of the normal; no attenuation.You should carefully explain your calculations. Your answer should be anRGB triple.

GLfloat l_amb[] = { 0.2, 0.3, 0.8, 1.0 };

GLfloat l_dif[] = { 0.4, 0.5, 0.9, 1.0 };GLfloat l_spc[] = { 1.0, 1.0, 1.0, 1.0 };

GLfloat m_spc[] = { 1.0, 1.0, 1.0, 1.0 };

GLfloat m_spc[] = { 0.0, 0.0, 0.0, 1.0 };

GLfloat m_shn[] = { 5.0 };

GLfloat m_amb[] = { 0.5, 0.5, 0.5, 1.0 };

GLfloat m_dif[] = { 0.8, 0.8, 0.8, 1.0 };

GLfloat l_pos[] = { 20.0, 20.0, 20.0, 0.0 };

glLightfv (GL_LIGHT0, GL_POSITION, l_pos);

glLightfv (GL_LIGHT0, GL_DIFFUSE, l_dif);

glLightfv (GL_LIGHT0, GL_AMBIENT, l_amb);

glLightfv (GL_LIGHT0, GL_SPECULAR, l_spc);

glMaterialfv(GL_FRONT, GL_SPECULAR, m_spc);

glMaterialfv(GL_FRONT, GL_SHININESS, m_shn);

glMaterialfv(GL_FRONT, GL_AMBIENT, m_amb);

glMaterialfv(GL_FRONT, GL_DIFFUSE, m_dif);

glVertex3fv(vf[0]);

(7 marks)

(d) Now, consider only specular reflection and assume that the viewing

direction (V) is in the same direction as the specular reflection

Graphics Programming for Games II Page 6 of 14

8/3/2019 Graphics Programming for Games II Jan 2011

http://slidepdf.com/reader/full/graphics-programming-for-games-ii-jan-2011 7/14

 B.Sc. in Computing in Computer Games Development – Year 3 January 2011

direction (R) so that V.R = 1, what will be the colour of the lightreflected, given the following code? Answer with an RGB triple.

GLfloat l_spc[] = { 1.0, 0.5, 0.25, 1.0 };

GLfloat m_spc[] = { 1.0, 1.0, 1.0, 1.0 };

GLfloat m_shn[] = { 2.0 };(3 marks)

Graphics Programming for Games II Page 7 of 14

8/3/2019 Graphics Programming for Games II Jan 2011

http://slidepdf.com/reader/full/graphics-programming-for-games-ii-jan-2011 8/14

 B.Sc. in Computing in Computer Games Development – Year 3 January 2011

Appendix A – Example of two-dimensional blending (plus output)

Graphics Programming for Games II Page 8 of 14

8/3/2019 Graphics Programming for Games II Jan 2011

http://slidepdf.com/reader/full/graphics-programming-for-games-ii-jan-2011 9/14

 B.Sc. in Computing in Computer Games Development – Year 3 January 2011

Appendix A – Continued (Output from code)

Graphics Programming for Games II Page 9 of 14

8/3/2019 Graphics Programming for Games II Jan 2011

http://slidepdf.com/reader/full/graphics-programming-for-games-ii-jan-2011 10/14

 B.Sc. in Computing in Computer Games Development – Year 3 January 2011

Appendix B – Display List Code (and output)

Graphics Programming for Games II Page 10 of 14

8/3/2019 Graphics Programming for Games II Jan 2011

http://slidepdf.com/reader/full/graphics-programming-for-games-ii-jan-2011 11/14

 B.Sc. in Computing in Computer Games Development – Year 3 January 2011

Appendix B – Continued (output from code)

Graphics Programming for Games II Page 11 of 14

8/3/2019 Graphics Programming for Games II Jan 2011

http://slidepdf.com/reader/full/graphics-programming-for-games-ii-jan-2011 12/14

 B.Sc. in Computing in Computer Games Development – Year 3 January 2011

Appendix C – Code and output for question 4

Cont’d…

Graphics Programming for Games II Page 12 of 14

8/3/2019 Graphics Programming for Games II Jan 2011

http://slidepdf.com/reader/full/graphics-programming-for-games-ii-jan-2011 13/14

 B.Sc. in Computing in Computer Games Development – Year 3 January 2011

Appendix C - continued

Graphics Programming for Games II Page 13 of 14

8/3/2019 Graphics Programming for Games II Jan 2011

http://slidepdf.com/reader/full/graphics-programming-for-games-ii-jan-2011 14/14

 B.Sc. in Computing in Computer Games Development – Year 3 January 2011

Appendix D – Phong Lighting Model

Graphics Programming for Games II Page 14 of 14