From b1bd04f1bcc0f71b68ad31977606f3a339556eb6 Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Thu, 4 Jul 2024 21:14:11 +0200 Subject: [PATCH] =?UTF-8?q?Make=20it=20possible=20to=20draw=20larger=20qua?= =?UTF-8?q?ds=20(although=20all=20of=20them=20are=20drawn=20at=20a=201?= =?UTF-8?q?=C3=971=20size=20at=20the=20moment).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit more progress towards #133 --- assets/cubyz/shaders/chunks/chunk_fragment.fs | 4 ++-- assets/cubyz/shaders/chunks/chunk_vertex.vs | 22 +++++++++++++++---- src/renderer/chunk_meshing.zig | 7 +++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/assets/cubyz/shaders/chunks/chunk_fragment.fs b/assets/cubyz/shaders/chunks/chunk_fragment.fs index dfaf396e..82aa7bce 100644 --- a/assets/cubyz/shaders/chunks/chunk_fragment.fs +++ b/assets/cubyz/shaders/chunks/chunk_fragment.fs @@ -85,8 +85,8 @@ vec3 unpack15BitLight(uint val) { } vec3 readLightValue() { - uint x = uint(lightPosition.x); - uint y = uint(lightPosition.y); + uint x = clamp(uint(lightPosition.x), 0, lightArea.x - 1); + uint y = clamp(uint(lightPosition.y), 0, lightArea.y - 1); uint light00 = lightData[lightBufferIndex + (x*lightArea.y + y)]; uint light01 = lightData[lightBufferIndex + (x*lightArea.y + y + 1)]; uint light10 = lightData[lightBufferIndex + ((x + 1)*lightArea.y + y)]; diff --git a/assets/cubyz/shaders/chunks/chunk_vertex.vs b/assets/cubyz/shaders/chunks/chunk_vertex.vs index 4dc3cab1..d0246ce3 100644 --- a/assets/cubyz/shaders/chunks/chunk_vertex.vs +++ b/assets/cubyz/shaders/chunks/chunk_vertex.vs @@ -98,10 +98,14 @@ void main() { vec3 modelPosition = vec3(chunks[chunkID].position.xyz - playerPositionInteger) - playerPositionFraction; int encodedPosition = faceData[faceID].encodedPosition; int textureAndQuad = faceData[faceID].textureAndQuad; + uvec2 quadSize = uvec2( + encodedPosition >> 15 & 31, + encodedPosition >> 20 & 31 + ); lightBufferIndex = (transparent ? chunks[chunkID].lightStartTransparent : chunks[chunkID].lightStartOpaque) + faceData[faceID].lightBufferIndex; - lightArea = uvec2(2, 2); + lightArea = quadSize + uvec2(1, 1); lightPosition = vec2(vertexID >> 1, vertexID & 1); - isBackFace = encodedPosition>>19 & 1; + isBackFace = encodedPosition>>31 & 1; ditherSeed = encodedPosition & 15; textureIndex = textureAndQuad & 65535; @@ -120,7 +124,17 @@ void main() { normal = quads[quadIndex].normal; - position += quads[quadIndex].corners[vertexID]; + vec3 cornerPosition = quads[quadIndex].corners[0]; + vec2 uvCornerPosition = quads[quadIndex].cornerUV[0]; + if((vertexID & 2) != 0) { + cornerPosition += (quads[quadIndex].corners[2] - quads[quadIndex].corners[0])*quadSize.x; + uvCornerPosition += (quads[quadIndex].cornerUV[2] - quads[quadIndex].cornerUV[0])*quadSize.x; + } + if((vertexID & 1) != 0) { + cornerPosition += (quads[quadIndex].corners[vertexID] - quads[quadIndex].corners[vertexID & 2])*quadSize.y; + uvCornerPosition += (quads[quadIndex].cornerUV[vertexID] - quads[quadIndex].cornerUV[vertexID & 2])*quadSize.y; + } + position += cornerPosition; position *= voxelSize; position += modelPosition; @@ -129,5 +143,5 @@ void main() { vec4 mvPos = viewMatrix*vec4(position, 1); gl_Position = projectionMatrix*mvPos; mvVertexPos = mvPos.xyz; - uv = quads[quadIndex].cornerUV[vertexID]*voxelSize; + uv = uvCornerPosition*voxelSize; } \ No newline at end of file diff --git a/src/renderer/chunk_meshing.zig b/src/renderer/chunk_meshing.zig index 4434c2bd..7f65fe39 100644 --- a/src/renderer/chunk_meshing.zig +++ b/src/renderer/chunk_meshing.zig @@ -244,9 +244,10 @@ pub const FaceData = extern struct { x: u5, y: u5, z: u5, - padding: u4 = 0, + xSize: u5, + ySize: u5, + padding: u6 = 0, isBackFace: bool, - padding2: u12 = 0, }, blockAndQuad: packed struct(u32) { texture: u16, @@ -256,7 +257,7 @@ pub const FaceData = extern struct { pub inline fn init(texture: u16, quadIndex: u16, x: i32, y: i32, z: i32, comptime backFace: bool) FaceData { return FaceData { - .position = .{.x = @intCast(x), .y = @intCast(y), .z = @intCast(z), .isBackFace = backFace}, + .position = .{.x = @intCast(x), .y = @intCast(y), .z = @intCast(z), .xSize = 1, .ySize = 1, .isBackFace = backFace}, .blockAndQuad = .{.texture = texture, .quadIndex = quadIndex}, .lightBufferIndex = undefined, };