Question 1: Winding Order and Culling
Consider the following code for drawing a pyramid.
Which way are the faces pointing? If you drew this in OpenGL with back face culling turned on, what would you see?
// the base gl.glBegin(GL2.GL_POLYGON); { gl.glVertex3d(1, 1, 0); gl.glVertex3d(-1, 1, 0); gl.glVertex3d(-1,-1, 0); gl.glVertex3d(1, -1, 0); } gl.glEnd(); // the sides gl.glBegin(GL2.GL_POLYGON); { gl.glVertex3d(0, 0, 2); gl.glVertex3d(1, 1, 0); gl.glVertex3d(-1, 1, 0); } gl.glEnd(); gl.glBegin(GL2.GL_POLYGON); { gl.glVertex3d(0, 0, 2); gl.glVertex3d(-1, -1, 0); gl.glVertex3d(-1, 1, 0); } gl.glEnd(); gl.glBegin(GL2.GL_POLYGON); { gl.glVertex3d(0, 0, 2); gl.glVertex3d(-1, -1, 0); gl.glVertex3d(1, -1, 0); } gl.glEnd(); gl.glBegin(GL2.GL_POLYGON); { gl.glVertex3d(0, 0, 2); gl.glVertex3d(1, -1, 0); gl.glVertex3d(1, 1, 0); } gl.glEnd();
Question 2: Depth buffer and transparency
Use bilinear interpolation to work out the pixel depths for the triangle below, given the coordinates and pseudo-depth values for the vertices as stated. Calculate depth values to two decimal places.
Show the result of copying the triangle into the depth buffer that already has the rectangle below in it
Suppose the green rectangle is transparent (with alpha = 0.25) and rgb values of (0.3,0.6,0.15) and the triangle is opaque (with alpha value = 1) and the rgb values of the triangle are (0.7,0,0.9). What does the resulting image look like in this case with standard alpha blending? What are the rgb values of the different pixels?
Suppose the rectangle is opaque( with alpha 1) and the triangle is transparent (with alpha = 0.25). What does the resulting image look like in this case? What are the rgb values of the different pixels?
Question 3: BSP trees
Consider the dungeon map below:
Assuming each wall is a single polygon, and assigning normals as you see fit, build a BSP tree for this map. There are many possible trees, depending on the order in which you choose polygons. What is the smallest tree you can find?
If the player is in the position marked, what order should the polygons be drawn so that all hidden surfaces are renderered properly?
Question 4: Illumination
Suppose you have modelled a vertex with the following material properties (assume emissive co-efficients are default values of 0).float amb[] = {0.0f, 0.0f, 0.1f, 1.0f}; float diff[] = {0.0f, 0.0f, 0.5f, 1.0f}; float spec[] = {1.0f, 1.0f, 1.0f, 1.0f}; float f[] = { 10.0f }; //phong exponent gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, amb,0); gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, diff,0); gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, spec,0); gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SHININESS, f,0);
And a light source with the following properties
float lightAmb[] = { 0.2f, 0.2f, 0.2f, 1.0f }; float lightDifAndSpec[] = { 1, 1, 1, 1 }; gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, lightAmb,0); gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, lightDifAndSpec,0); gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, lightDifAndSpec,0); float[] globAmb = {0.1f, 0.1f, 0.1f, 1.0f}; gl.glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globAmb, 0); //Calculate the camera viewpoint properly instead of using hack. gl.glLightModeli(GL2.GL_LIGHT_MODEL_LOCAL_VIEWER, GL2.GL_TRUE);
Assume