From 5242104d873b0a569601467a14c358e930e539cf Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Tue, 24 Dec 2024 12:57:17 +1000 Subject: [PATCH] Other stuff --- .../me/cortex/voxy/client/core/VoxelCore.java | 9 ++ .../client/core/rendering/RenderService.java | 15 ++- .../voxelization/WorldConversionFactory.java | 9 ++ .../voxy/common/world/SaveLoadSystem2.java | 57 +++++++++++ .../voxy/shaders/lod/gl46/test/raw.frag | 7 ++ .../voxy/shaders/lod/gl46/test/raw.vert | 97 +++++++++++++++++++ 6 files changed, 190 insertions(+), 4 deletions(-) create mode 100644 src/main/java/me/cortex/voxy/common/world/SaveLoadSystem2.java create mode 100644 src/main/resources/assets/voxy/shaders/lod/gl46/test/raw.frag create mode 100644 src/main/resources/assets/voxy/shaders/lod/gl46/test/raw.vert diff --git a/src/main/java/me/cortex/voxy/client/core/VoxelCore.java b/src/main/java/me/cortex/voxy/client/core/VoxelCore.java index e32930f8..d5e1d196 100644 --- a/src/main/java/me/cortex/voxy/client/core/VoxelCore.java +++ b/src/main/java/me/cortex/voxy/client/core/VoxelCore.java @@ -126,6 +126,15 @@ public class VoxelCore { if (IrisUtil.irisShadowActive()) { return; } + + + //Do some very cheeky stuff for MiB + if (false) { + int sector = (((int)Math.floor(cameraX)>>4)+512)>>10; + cameraX -= sector<<14;//10+4 + cameraY += (16+(256-32-sector*30))*16; + } + matrices.push(); matrices.translate(-cameraX, -cameraY, -cameraZ); matrices.pop(); diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java b/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java index 4180d5bf..79883782 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/RenderService.java @@ -52,7 +52,7 @@ public class RenderService, J extends Vi //Max sections: ~500k //Max geometry: 1 gb - this.sectionRenderer = (T) createSectionRenderer(this.modelService.getStore(),1<<20, (1L<<32)-1024); + this.sectionRenderer = (T) createSectionRenderer(this.modelService.getStore(),1<<20, (1L<<31)-1024); //Do something incredibly hacky, we dont need to keep the reference to this around, so just connect and discard var router = new SectionUpdateRouter(); @@ -98,7 +98,10 @@ public class RenderService, J extends Vi }*/ if (true) { if (true) { - final int H_WIDTH = 10; + if (true) { + return; + } + final int H_WIDTH = 50; for (int x = -H_WIDTH; x <= H_WIDTH; x++) { for (int z = -H_WIDTH; z <= H_WIDTH; z++) { for (int y = -1; y <= 0; y++) { @@ -107,8 +110,8 @@ public class RenderService, J extends Vi } } } else { - for (int x = -5; x <= 20; x++) { - for (int z = -5; z <= 20; z++) { + for (int x = -75; x <= 75; x++) { + for (int z = -75; z <= 75; z++) { for (int y = 0; y <= 1; y++) { this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(4, x, y, z)); } @@ -145,7 +148,11 @@ public class RenderService, J extends Vi //this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(4, 0,0,0)); } + private int q = -1024; public void setup(Camera camera) { + if (q<(151*151*2)&&q++>=0) { + this.nodeManager.insertTopLevelNode(WorldEngine.getWorldSectionId(4, (q%151)-75, ((q/151)/151)-1, ((q/151)%151)-75)); + } this.modelService.tick(); } diff --git a/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java b/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java index 8544d960..a0627b65 100644 --- a/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java +++ b/src/main/java/me/cortex/voxy/common/voxelization/WorldConversionFactory.java @@ -130,5 +130,14 @@ public class WorldConversionFactory { data[J(0, 0, 0)], data[J(1, 0, 0)], data[J(0, 0, 1)], data[J(1, 0, 1)], data[J(0, 1, 0)], data[J(1, 1, 0)], data[J(0, 1, 1)], data[J(1, 1, 1)], mapper); + + + + + //Do some very cheeky stuff for MiB + if (false) { + int sector = (section.x+512)>>10; + section.setPosition(section.x-(sector<<10), section.y+16+(256-32-sector*30), section.z);//Note sector size mult is 30 because the top chunk is replicated (and so is bottom chunk) + } } } diff --git a/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem2.java b/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem2.java new file mode 100644 index 00000000..63849aa3 --- /dev/null +++ b/src/main/java/me/cortex/voxy/common/world/SaveLoadSystem2.java @@ -0,0 +1,57 @@ +package me.cortex.voxy.common.world; + +import it.unimi.dsi.fastutil.longs.Long2ShortOpenHashMap; +import me.cortex.voxy.common.util.MemoryBuffer; +import me.cortex.voxy.common.util.UnsafeUtil; +import me.cortex.voxy.common.world.other.Mapper; +import me.cortex.voxy.commonImpl.VoxyCommon; +import org.lwjgl.system.MemoryUtil; + +public class SaveLoadSystem2 { + public static final boolean VERIFY_HASH_ON_LOAD = VoxyCommon.isVerificationFlagOn("verifySectionHash"); + public static final boolean VERIFY_MEMORY_ACCESS = VoxyCommon.isVerificationFlagOn("verifyMemoryAccess"); + public static final int BIGGEST_SERIALIZED_SECTION_SIZE = 32 * 32 * 32 * 8 * 2 + 8; + + public static int lin2z(int i) {//y,z,x + int x = i&0x1F; + int y = (i>>10)&0x1F; + int z = (i>>5)&0x1F; + return Integer.expand(x,0b1001001001001)|Integer.expand(y,0b10010010010010)|Integer.expand(z,0b100100100100100); + + //zyxzyxzyxzyxzyx + } + + public static int z2lin(int i) { + int x = Integer.compress(i, 0b1001001001001); + int y = Integer.compress(i, 0b10010010010010); + int z = Integer.compress(i, 0b100100100100100); + return x|(y<<10)|(z<<5); + } + + + private record SerialCache() {} + private record DeserialCache() {} + private static final ThreadLocal SERIALIZE_CACHE = ThreadLocal.withInitial(()->new SerialCache()); + private static final ThreadLocal DESERIALIZE_CACHE = ThreadLocal.withInitial(()->new DeserialCache()); + + + //TODO: make it so that MemoryBuffer is cached and reused + public static MemoryBuffer serialize(WorldSection section) { + var cache = SERIALIZE_CACHE.get(); + //Split into separate block, biome, blocklight, skylight + // where block and biome are pelleted (0 block id (air) is implicitly in the pallet ) + // if all entries in a specific array are the same, just emit that single value + // do bitpacking on the resulting arrays for pallets/when packing the palleted arrays + // if doing bitpacking + pallet is larger than just emitting raw entries, do that + + //Header includes position (long), (maybe time?), version storage type/version, child existence, air block count? + // + return null; + + } + + public static boolean deserialize(WorldSection section, MemoryBuffer data) { + var cache = DESERIALIZE_CACHE.get(); + return false; + } +} diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46/test/raw.frag b/src/main/resources/assets/voxy/shaders/lod/gl46/test/raw.frag new file mode 100644 index 00000000..4bd2bde2 --- /dev/null +++ b/src/main/resources/assets/voxy/shaders/lod/gl46/test/raw.frag @@ -0,0 +1,7 @@ +#version 460 core + +layout(location = 6) in flat uint quadDebug; +layout(location = 0) out vec4 outColour; +void main() { + outColour = vec4(float(quadDebug&15u)/15, float((quadDebug>>4)&15u)/15, float((quadDebug>>8)&15u)/15, 1); +} \ No newline at end of file diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46/test/raw.vert b/src/main/resources/assets/voxy/shaders/lod/gl46/test/raw.vert new file mode 100644 index 00000000..ecca7c37 --- /dev/null +++ b/src/main/resources/assets/voxy/shaders/lod/gl46/test/raw.vert @@ -0,0 +1,97 @@ +#version 460 core +#extension GL_ARB_gpu_shader_int64 : enable + +#define QUAD_BUFFER_BINDING 1 +#define SECTION_METADATA_BUFFER_BINDING 2 +#define MODEL_BUFFER_BINDING 3 +#define MODEL_COLOUR_BUFFER_BINDING 4 +#define LIGHTING_SAMPLER_BINDING 1 + + +#import +#import +#import + +layout(location = 6) out flat uint quadDebug; + +uint extractLodLevel() { + return uint(gl_BaseInstance)>>27; +} + +//Note the last 2 bits of gl_BaseInstance are unused +//Gives a relative position of +-255 relative to the player center in its respective lod +ivec3 extractRelativeLodPos() { + return (ivec3(gl_BaseInstance)<>ivec3(23); +} + +vec4 uint2vec4RGBA(uint colour) { + return vec4((uvec4(colour)>>uvec4(24,16,8,0))&uvec4(0xFF))/255.0; +} + +vec4 getFaceSize(uint faceData) { + float EPSILON = 0.001f; + + vec4 faceOffsetsSizes = extractFaceSizes(faceData); + + //Expand the quads by a very small amount + faceOffsetsSizes.xz -= vec2(EPSILON); + faceOffsetsSizes.yw += vec2(EPSILON); + + //Make the end relative to the start + faceOffsetsSizes.yw -= faceOffsetsSizes.xz; + + return faceOffsetsSizes; +} + +//TODO: make branchless by using ternaries i think +vec3 swizzelDataAxis(uint axis, vec3 data) { + if (axis == 0) { //Up/down + data = data.xzy; + } + //Not needed, here for readability + //if (axis == 1) {//north/south + // offset = offset.xyz; + //} + if (axis == 2) { //west/east + data = data.zxy; + } + return data; +} + +//TODO: add a mechanism so that some quads can ignore backface culling +// this would help alot with stuff like crops as they would look kinda weird i think, +// same with flowers etc +void main() { + int cornerIdx = gl_VertexID&3; + Quad quad = quadData[uint(gl_VertexID)>>2]; + uint face = extractFace(quad); + uint modelId = extractStateId(quad); + BlockModel model = modelData[modelId]; + uint faceData = model.faceData[face]; + + uint lodLevel = extractLodLevel(); + + + ivec2 quadSize = extractSize(quad); + + + vec4 faceSize = getFaceSize(faceData); + + vec2 cQuadSize = (faceSize.yw + quadSize - 1) * vec2((cornerIdx>>1)&1, cornerIdx&1); + + vec3 cornerPos = extractPos(quad); + float depthOffset = extractFaceIndentation(faceData); + cornerPos += swizzelDataAxis(face>>1, vec3(faceSize.xz, mix(depthOffset, 1-depthOffset, float(face&1u)))); + + + vec3 origin = vec3(((extractRelativeLodPos()<>1,vec3(cQuadSize,0)))*(1<>16; + hash = hash*1231421+123141; + hash ^= hash>>16; + hash = hash * 1827364925 + 123325621; + quadDebug = hash; +} \ No newline at end of file