From 5979b17891c591a2bab577cf8f84fee5a25ba045 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Sun, 17 Nov 2024 21:18:05 +1000 Subject: [PATCH] Fix lighting --- .../client/core/rendering/LightMapHelper.java | 24 ++++++++++++++----- .../section/MDICSectionRenderer.java | 9 ++++--- .../voxy/shaders/lod/gl46/bindings.glsl | 13 ++++------ .../assets/voxy/shaders/lod/gl46/quads2.vert | 2 +- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/LightMapHelper.java b/src/main/java/me/cortex/voxy/client/core/rendering/LightMapHelper.java index 5a04048a..d71cf35f 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/LightMapHelper.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/LightMapHelper.java @@ -6,13 +6,23 @@ import net.minecraft.client.MinecraftClient; import org.lwjgl.system.MemoryUtil; import static org.lwjgl.opengl.ARBUniformBufferObject.glBindBufferBase; +import static org.lwjgl.opengl.GL11.glBindTexture; +import static org.lwjgl.opengl.GL33.glBindSampler; +import static org.lwjgl.opengl.GL33.glGenSamplers; import static org.lwjgl.opengl.GL43.GL_SHADER_STORAGE_BUFFER; +import static org.lwjgl.opengl.GL45.glBindTextureUnit; public class LightMapHelper { + private static final int SAMPLER = glGenSamplers(); + + static { + //SAMPLER + } + /* private static final GlBuffer LIGHT_MAP_BUFFER = new GlBuffer(256*4); public static void tickLightmap() { long upload = UploadStream.INSTANCE.upload(LIGHT_MAP_BUFFER, 0, 256*4); - var lmt = MinecraftClient.getInstance().gameRenderer.getLightmapTextureManager().texture.getImage(); + var lmt = MinecraftClient.getInstance().gameRenderer.getLightmapTextureManager().lightmapFramebuffer.getImage(); for (int light = 0; light < 256; light++) { int x = light&0xF; int y = ((light>>4)&0xF); @@ -20,10 +30,12 @@ public class LightMapHelper { sample = ((sample&0xFF0000)>>16)|(sample&0xFF00)|((sample&0xFF)<<16); MemoryUtil.memPutInt(upload + (((x<<4)|(y))*4), sample|(0xFF<<28)); } - } + //TODO: CRITICAL FIXME + }*/ - public static void bind(int lightingBufferIndex) { - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, lightingBufferIndex, LIGHT_MAP_BUFFER.id); + public static void bind(int lightingIndex) { + //glBindBufferBase(GL_SHADER_STORAGE_BUFFER, lightingBufferIndex, LIGHT_MAP_BUFFER.id); + //glBindSampler(lightingIndex, SAMPLER); + glBindTextureUnit(lightingIndex, MinecraftClient.getInstance().gameRenderer.getLightmapTextureManager().lightmapFramebuffer.getColorAttachment()); } - -} +} \ No newline at end of file diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/section/MDICSectionRenderer.java b/src/main/java/me/cortex/voxy/client/core/rendering/section/MDICSectionRenderer.java index 3a8bb3e8..7e7bee89 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/section/MDICSectionRenderer.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/section/MDICSectionRenderer.java @@ -89,7 +89,7 @@ public class MDICSectionRenderer extends AbstractSectionRenderer>uvec4(16,8,0,24); - arr = arr & uvec4(0xFF); - return vec4(arr)*vec4(1.0f/255.0f); + int i2 = int(index); + return texture(lightSampler, vec2((i2>>4)&0xF, i2&0xF)/16.0f); } #endif diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46/quads2.vert b/src/main/resources/assets/voxy/shaders/lod/gl46/quads2.vert index adeefe73..5a322270 100644 --- a/src/main/resources/assets/voxy/shaders/lod/gl46/quads2.vert +++ b/src/main/resources/assets/voxy/shaders/lod/gl46/quads2.vert @@ -5,7 +5,7 @@ #define SECTION_METADATA_BUFFER_BINDING 2 #define MODEL_BUFFER_BINDING 3 #define MODEL_COLOUR_BUFFER_BINDING 4 -#define LIGHTING_BUFFER_BINDING 5 +#define LIGHTING_SAMPLER_BINDING 1 #import