Week 10 Tutorial Solutions

Question 1

a) Use Bresenham's algorithm to draw a line from P(3,3) to Q(10,5). Repeat for the line (3,3) to (9,6)

Ignore the pink pixels in this answer, it is part of the answer for question 2b.

b) Consider the symmetrical problem of drawing for Q to P. What changes do you need to make to the algorithm to guarantee you get the same set of pixels?

The first line was symmetrical, so there would be no difference drawing the line the other way from (10,5) to (3,3). However this is not the case with the second line. Asymmetries occur when you have a point of the line with F=0 and you must choose whether to increment at this point.

The pink pixels show the line from (3,3) to (9,6) which does step when F=0. The overlapping blue line goes from (9,6) to (3,3) and does step while F=0. Clearly they are not the same line.

To make sure lines are drawn the same way the code for lines the other way must be adjusted so that when tracing the line in the other direction the F=0 case is combined with the if condition that does not cause a decrement in y.

Question 2

Consider the scan line algorithm described in class. For the polygon drawn here, what does the edge list look like? What does the Active Edge List (AEL) look like just before filling the pixels on scan line 5? What pixels will be filled?

The Edge List

The inc is the inverse gradient, which is used to increment the x value later in the algorithm.

Active Edge List

By the time we get to a Y of 5, the first active edge has been incremented 3 times (as it started at y=2) and so the X is now 2 - 1/7 -1/7 -1/7. Similar calculations were used for the rest of the list.

(2,5) (3,5)(4,5)(5,5)(6,5) ,(9,5),(10,5),(11,5)

The general rules are:

Question 3:

Suppose you are interested in implementing a particle system to represent a fire. How would your particles evolve over time? What variables would you want to change? How would their values change over time?

Making a realistic fire involves a lot of subtle effects, but in the very least you would want:

An appropriate animated sprite for fire particles could handle size and colour transitions for you and provide greater realism.

Question 4:

In the assignment specification it says for the particle system "For the full marks this would need to include alpha blended billboarded particles, creation and destruction ,some kind of evolution over time (position, size, colour, as is appropriate for your kind of particles)."

Discuss what alpha blended billboarded particles are.

Particles that are partially transparent (alpha blended) and are 2d texured quads that are transformed so they are always facing the camera (billboarding). They need to face the camera so that as the user moves the camera around they can not see that the particles are simply 2d textured quads.

What are some issues that may arise when implementing blending in opengl? What are some ways these issues can be overcome?

The interaction between using the depth buffer for hidden surface removal and drawing translucent polygons in opengl can cause undesired results. For example if a transparent polygon is drawn first, a polygon that is behind it will never be drawn if the depth buffer is on. One solution is to draw all opaque polygons first and then draw the transparent polygons last. If you are drawing many transparent polygons (as in the case of a particle system) to do the it accurately you would need to sort your polygons and draw in back to front order. You may instead wish to turn off depth buffer writing using gl.glDepthMask(GL2.GL_FALSE); while you are drawing your transparent polygons. (Remember to set it back to true again for rendering the next frame). This may give results that look ok.

Question 5:

Suppose we had the following vertex shader
out vec2 texCoord;

void main (void) {	
  
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;	
	gl_FrontColor = gl_Color;	
	texCoord= vec2(gl_MultiTexCoord0);
}
And suppose we had executed the following command in our jogl program
texUnitLoc = gl.glGetUniformLocation(shaderprogram,"texUnit");
gl.glUniform1i(texUnitLoc , 0);

Assignment Use any left over time to discuss the assignment with your tutor