Files
OpenGL_Intro/report/task2.md
2025-09-02 21:31:09 +02:00

3.6 KiB

Task 2

a)

What is the name of this phenomenon?

Clipping

When does it occur?

It occurs when some part of an object is outside the clipping volume which is a 2x2x2 cube at the origin with coordinate values ranging from -1 to 1. Since the z coordinate for v0 and v1 is 1.2 and -1.2, whic is outside this range, the triangle is clipped by the vertex shader and the part which sticks out is not rendered. The two corners have essentially been clipped off by the clip box.

What is its purpose?

The clip box ensures that objects behind the camera and generally when geometry exceeds the bounds of the screen.

b)

What happens?

The triangle is no longer visible.

Why does it happen?

This is because of back-face culling. When the triangle is deemed to be facing away from the camera it is culled. And thus not rendered.

What is the condition under which this effect occurs?

If the cross product of two arbitrary edges of a triangle, which respects the vertex order is negative. Because of this the ordering in the index buffer is important since it determines which wheter or not the triangle is considered facing away or towards the camera.

c)

Why does the depth buffer need to be reset each frame? Describe what you would observe in a scene with a sphere moving rightward when not clearing the depth buffer.

The depth buffer needs to be reset each frame to ensure that only triangles that would not have been visible are not rendered. If it is only updated, only things that get closer or as close as any previous geometry at the same pixel coordinates get rendered. The left part of the sphere would go invisible and not reappear assuming that the depth buffer is updated. Since the sphere is moving to the right will the left part of the sphere pass through parts which have measured the depth of the middle part of the sphere which is the part which is closest. Those triangles on the left side of the sphere therefore get culled.

In which situation can the Fragment Shader be executed multiple times for the same pixel? (Assume we do not use multisampling.)

If you render geometry on top of each other, the fragment shader may render multiple times for the same pixel in the area which is overlapping.

What are the two most commonly used types of Shaders? What are the responsibilites of each of them?

The two most commonly used types of Shaders are the vertex and fragment shaders. The fragment shader is used to determine the color of a pixel given some or none inputs such as position, normals. The vertex shader is responsible for doing transformations on vertices such as scaling, rotating, translating and shearing.

Why is it common to use an index buffer to specify which vertices should be connected into triangles, as opposed to relying on the order which the vertices are specified in the vertex buffer?

To reduce the amount of duplicated data since complex models usually have many triangles that compose of many of the same vertices.

While the last input of gl::VertexAttribPointer() is a pointer, we usually pass in a null pointer. Describe a situation in which you would pass a non-zero value into this function.

If you have multiple objects you likely still want to store it all in a single vertex buffer. This value is essentially an offset to where the data for the object starts such that you don't have to have separate buffers.

d)

Mirror/flip the whole scene both horizontally and vertically at the same time.

I negated the position in the vertex shader.

Change the colour of the drawn triangle(s) to a different colour.

I set second float in the rgba value in the fragment shader to 0.