From 6ebc4739b9e750822fefba5954a00cae5ad9069e Mon Sep 17 00:00:00 2001 From: mcrcortex <{ID}+{username}@users.noreply.github.com> Date: Mon, 15 Apr 2024 01:08:32 +1000 Subject: [PATCH] wip hiz --- .../voxy/client/core/gl/GlFramebuffer.java | 6 +- .../Gl46MeshletsFarWorldRenderer.java | 15 ++- .../voxy/client/core/rendering/HiZBuffer.java | 98 +++++++++++++++++++ .../rendering/building/RenderDataFactory.java | 2 +- .../assets/voxy/shaders/hiz/blit.fsh | 9 ++ .../assets/voxy/shaders/hiz/blit.vsh | 8 ++ .../voxy/shaders/lod/gl46mesh/cmdgen.comp | 2 +- .../voxy/shaders/lod/gl46mesh/quads.frag | 10 ++ .../voxy/shaders/lod/gl46mesh/quads.vert | 4 +- 9 files changed, 149 insertions(+), 5 deletions(-) create mode 100644 src/main/java/me/cortex/voxy/client/core/rendering/HiZBuffer.java create mode 100644 src/main/resources/assets/voxy/shaders/hiz/blit.fsh create mode 100644 src/main/resources/assets/voxy/shaders/hiz/blit.vsh diff --git a/src/main/java/me/cortex/voxy/client/core/gl/GlFramebuffer.java b/src/main/java/me/cortex/voxy/client/core/gl/GlFramebuffer.java index b9d428bd..e68c63c0 100644 --- a/src/main/java/me/cortex/voxy/client/core/gl/GlFramebuffer.java +++ b/src/main/java/me/cortex/voxy/client/core/gl/GlFramebuffer.java @@ -11,7 +11,11 @@ public class GlFramebuffer extends TrackedObject { } public GlFramebuffer bind(int attachment, GlTexture texture) { - glNamedFramebufferTexture(this.id, attachment, texture.id, 0); + return this.bind(attachment, texture, 0); + } + + public GlFramebuffer bind(int attachment, GlTexture texture, int lvl) { + glNamedFramebufferTexture(this.id, attachment, texture.id, lvl); return this; } diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/Gl46MeshletsFarWorldRenderer.java b/src/main/java/me/cortex/voxy/client/core/rendering/Gl46MeshletsFarWorldRenderer.java index 769bd7b3..9902a2a0 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/Gl46MeshletsFarWorldRenderer.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/Gl46MeshletsFarWorldRenderer.java @@ -5,11 +5,13 @@ import me.cortex.voxy.client.core.gl.shader.Shader; import me.cortex.voxy.client.core.gl.shader.ShaderType; import me.cortex.voxy.client.core.rendering.util.UploadStream; import me.cortex.voxy.client.mixin.joml.AccessFrustumIntersection; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.RenderLayer; import org.joml.Matrix4f; import org.joml.Vector3f; import org.lwjgl.system.MemoryUtil; +import static org.lwjgl.opengl.ARBDirectStateAccess.glGetNamedFramebufferAttachmentParameteriv; import static org.lwjgl.opengl.ARBIndirectParameters.GL_PARAMETER_BUFFER_ARB; import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL14C.glBlendFuncSeparate; @@ -56,9 +58,10 @@ public class Gl46MeshletsFarWorldRenderer extends AbstractFarWorldRenderer #define extractMeshletStart extractQuadStart layout(local_size_x = 64) in; -#define QUADS_PER_MESHLET 62 +#define QUADS_PER_MESHLET 30 void emitMeshlets(inout uint mli, inout uint meshletPtr, uint mskedCnt, uint cnt) { for (;mskedCnt != 0; mskedCnt--,mli++) { diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46mesh/quads.frag b/src/main/resources/assets/voxy/shaders/lod/gl46mesh/quads.frag index 7732974e..8b244fa3 100644 --- a/src/main/resources/assets/voxy/shaders/lod/gl46mesh/quads.frag +++ b/src/main/resources/assets/voxy/shaders/lod/gl46mesh/quads.frag @@ -10,6 +10,7 @@ layout(location = 2) in flat vec4 tinting; layout(location = 3) in flat vec4 addin; layout(location = 4) in flat uint flags; layout(location = 5) in flat vec4 conditionalTinting; +layout(location = 6) in flat uint meshlet; //layout(location = 6) in flat vec4 solidColour; layout(location = 0) out vec4 outColour; @@ -29,4 +30,13 @@ void main() { outColour = (colour * tinting) + addin; //outColour = vec4(uv + baseUV, 0, 1); + + /* + uint hash = meshlet*1231421+123141; + hash ^= hash>>16; + hash = hash*1231421+123141; + hash ^= hash>>16; + + outColour = vec4(float(hash&15u)/15, float((hash>>4)&15u)/15, float((hash>>8)&15u)/15, 1); + */ } \ No newline at end of file diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46mesh/quads.vert b/src/main/resources/assets/voxy/shaders/lod/gl46mesh/quads.vert index 8241f8d3..06f23145 100644 --- a/src/main/resources/assets/voxy/shaders/lod/gl46mesh/quads.vert +++ b/src/main/resources/assets/voxy/shaders/lod/gl46mesh/quads.vert @@ -1,6 +1,6 @@ #version 450 #extension GL_ARB_gpu_shader_int64 : enable -#define QUADS_PER_MESHLET 62 +#define QUADS_PER_MESHLET 30 #define MESHLET_ACCESS readonly //There are 16 bytes of metadata at the start of the meshlet @@ -36,6 +36,7 @@ uint extractDetail(PosHeader pos) { } #endif +layout(location = 6) out flat uint meshlet; PosHeader meshletPosition; Quad quad; bool setupMeshlet() { @@ -49,6 +50,7 @@ bool setupMeshlet() { return true; } + meshlet = data; uint baseId = (data*MESHLET_SIZE); uint quadIndex = baseId + (gl_VertexID>>2) + 2; meshletPosition = geometryPool[baseId];