checkerboard pattern

This commit is contained in:
2025-09-02 21:31:09 +02:00
parent 12e3d5a9d8
commit 0f13f037ce
9 changed files with 40 additions and 2 deletions

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

BIN
report/images/task2b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

BIN
report/images/task2d1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
report/images/task2d2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
report/images/task3a.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -14,3 +14,24 @@ The triangle is no longer visible.
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.

3
report/task3.md Normal file
View File

@@ -0,0 +1,3 @@
# Task 3
## a)

View File

@@ -1,7 +1,21 @@
#version 460 core
out layout(location=0) vec4 color;
in vec4 gl_FragCoord;
void main() {
color = vec4(1.0f, 1.0f, 1.0f, 1.0f);
vec4 b = vec4(0.0f,0.0f,0.0f,0.0f);
vec4 w = vec4(1.0f, 1.0f, 1.0f, 1.0f);
float square_size = 128.0f;
bool x = mod(gl_FragCoord.x, square_size) < square_size / 2.0f;
bool y = mod(gl_FragCoord.y, square_size) < square_size / 2.0f;
if (x && y) {
color = b;
} else if (x && !y) {
color = w;
} else if (!x && y) {
color = w;
} else if (!x && !y) {
color = b;
}
}

View File

@@ -169,7 +169,7 @@ fn main() {
// == // Set up your VAO around here
let vertices = vec![-0.6, -0.6, 0., 0.6, -0.6, 0., 0., 0.6, 0.];
let indices = vec![1, 0, 2];
let indices = vec![0, 1, 2];
let my_vao = unsafe { create_vao(&vertices, &indices) };
// == // Set up your shaders here