This commit is contained in:
Max Westerlund
2025-09-02 13:17:15 +02:00
parent b6f9966eb9
commit 71c5f3a3aa
15 changed files with 618 additions and 37 deletions

View File

@@ -1,9 +1,9 @@
#version 330 core
out vec4 FragColor;
#version 430 core
in vec4 vertexColor;
out vec4 FragColor;
in vec3 fragColor;
void main()
{
FragColor = vertexColor;
FragColor = vec4(fragColor, 1.0);
}

View File

@@ -1,10 +1,106 @@
#version 330 core
layout (location = 0) in vec3 aPosition;
#version 430 core
out vec4 vertexColor;
struct FaceData {
uint x;
uint y;
uint z;
uint facing; // 0=+X,1=-X,2=+Y,3=-Y,4=+Z,5=-Z
uint texture;
};
layout(std430, binding = 0) buffer FaceBuffer {
FaceData faces[];
};
out vec3 fragColor;
vec3 getVertexOffset(uint facing, uint vertIndex) {
if (facing == 0u) { // +X
vec3 offsets[6] = vec3[6](
vec3(0.5, -0.5, -0.5),
vec3(0.5, 0.5, 0.5),
vec3(0.5, -0.5, 0.5),
vec3(0.5, 0.5, 0.5),
vec3(0.5, -0.5, -0.5),
vec3(0.5, 0.5, -0.5)
);
return offsets[vertIndex];
} else if (facing == 1u) { // -X
vec3 offsets[6] = vec3[6](
vec3(-0.5, -0.5, 0.5),
vec3(-0.5, 0.5, -0.5),
vec3(-0.5, -0.5, -0.5),
vec3(-0.5, 0.5, -0.5),
vec3(-0.5, -0.5, 0.5),
vec3(-0.5, 0.5, 0.5)
);
return offsets[vertIndex];
} else if (facing == 2u) { // +Y (top)
vec3 offsets[6] = vec3[6](
vec3(-0.5, 0.5, -0.5),
vec3( 0.5, 0.5, 0.5),
vec3( 0.5, 0.5, -0.5),
vec3( 0.5, 0.5, 0.5),
vec3(-0.5, 0.5, -0.5),
vec3(-0.5, 0.5, 0.5)
);
return offsets[vertIndex];
} else if (facing == 3u) { // -Y (bottom)
vec3 offsets[6] = vec3[6](
vec3(-0.5, -0.5, 0.5),
vec3( 0.5, -0.5, -0.5),
vec3( 0.5, -0.5, 0.5),
vec3( 0.5, -0.5, -0.5),
vec3(-0.5, -0.5, 0.5),
vec3(-0.5, -0.5, -0.5)
);
return offsets[vertIndex];
} else if (facing == 4u) { // +Z (front)
vec3 offsets[6] = vec3[6](
vec3(-0.5, -0.5, 0.5),
vec3( 0.5, -0.5, 0.5),
vec3( 0.5, 0.5, 0.5),
vec3( 0.5, 0.5, 0.5),
vec3(-0.5, 0.5, 0.5),
vec3(-0.5, -0.5, 0.5)
);
return offsets[vertIndex];
} else if (facing == 5u) { // -Z (back)
vec3 offsets[6] = vec3[6](
vec3( 0.5, -0.5, -0.5),
vec3(-0.5, -0.5, -0.5),
vec3(-0.5, 0.5, -0.5),
vec3(-0.5, 0.5, -0.5),
vec3( 0.5, 0.5, -0.5),
vec3( 0.5, -0.5, -0.5)
);
return offsets[vertIndex];
}
}
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = vec4(aPosition, 1.0);
vertexColor = vec4(aPosition + vec3(0.5,0.5,0.5), 1.0);
float[6] lightMult = float[6](
0.6,
0.6,
1.0,
0.5,
0.8,
0.8
);
uint faceIndex = gl_VertexID / 6;
uint vertIndex = gl_VertexID % 6;
FaceData f = faces[faceIndex];
vec3 basePos = vec3(f.x, f.y, f.z);
vec4 worldPos = vec4(basePos + getVertexOffset(f.facing, vertIndex), 1.0);
fragColor = vec3(1.0, 1.0, 1.0) * lightMult[f.facing];
gl_Position = projection * view * worldPos;
}