From fa8fa6784559ed0fc8d780e36880273f77e272c4 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Thu, 11 Dec 2025 10:49:50 -0500 Subject: i did a lot --- assets/fragment.glsl | 8 +++--- assets/vertex.glsl | 79 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 9 deletions(-) (limited to 'assets') diff --git a/assets/fragment.glsl b/assets/fragment.glsl index 4065771..5ce136e 100755 --- a/assets/fragment.glsl +++ b/assets/fragment.glsl @@ -1,6 +1,6 @@ #version 330 core -flat in uint pass_data; +flat in uvec2 pass_data; out vec4 color; @@ -15,8 +15,8 @@ const float TINT[6] = float[]( void main(void) { - uint face = pass_data >> 2u; - uint block = pass_data & 3u; + uint block = (pass_data.x >> 28) & 15u; + uint face = (pass_data.x >> 25) & 7u; float tint = TINT[face]; - color = vec4(tint, tint, tint, 1); + color = vec4(vec3(tint), 1); } diff --git a/assets/vertex.glsl b/assets/vertex.glsl index d14d852..f4c3fde 100755 --- a/assets/vertex.glsl +++ b/assets/vertex.glsl @@ -1,14 +1,83 @@ #version 330 core -in vec3 position; -in uint data; +layout (location = 0) in vec3 quad; -uniform mat4 proj_view; +layout (std140) uniform Matrices { + mat4 proj; + mat4 view; +}; -flat out uint pass_data; +// world chunk position +const int CHUNK_SIZE = 16; +uniform ivec3 chunk_position; + +const int MAX_FACES = CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE; +layout (std140) uniform Face { + // normaly a uint but std140 layout + // requires 16-byte alignment + uvec4 face_data[MAX_FACES / 4]; +}; + +flat out uvec2 pass_data; + +uint get_half(int index) +{ + int arr_index = index / 4; + int vec_index = index % 4; + return face_data[arr_index][vec_index]; +} + +uvec2 get_data(int index) +{ + uint lower = get_half(index * 2); + uint upper = get_half(index * 2 + 1); + return uvec2(lower, upper); +} + +vec3 get_quad(uint face, uint width, uint height) +{ + vec3 squad = quad; + squad.x *= width; + squad.y *= height; + + switch(face) { + case 0u: // PX + return squad.yzx + vec3(1, 0, 0); + case 1u: // NX + return squad.yxz; + case 2u: // PY + return squad.xyz + vec3(0, 1, 0); + case 3u: // NY + return squad.zyx; + case 4u: // PZ + return squad.zxy + vec3(0, 0, 1); + case 5u: // NZ + return squad.xzy; + } + // should not happen + return vec3(0); +} void main(void) { - gl_Position = proj_view * vec4(position, 1.0); + // get face data + uvec2 data = get_data(gl_InstanceID); + uint x = (data.x >> 0) & 31u; + uint y = (data.x >> 5) & 31u; + uint z = (data.x >> 10) & 31u; + uint width = (data.x >> 15) & 31u; + uint height = (data.x >> 20) & 31u; + uint face = (data.x >> 25) & 7u; + + // get quad verts + vec3 quad = get_quad(face, width, height); + + // get position + vec3 position = vec3(x, y, z); + position += chunk_position * CHUNK_SIZE; + position += quad; + + // draw + gl_Position = proj * view * vec4(position, 1.0); pass_data = data; } -- cgit v1.2.3-freya