diff --git a/build.gradle b/build.gradle index 809df20a..cf3f8031 100644 --- a/build.gradle +++ b/build.gradle @@ -58,6 +58,7 @@ dependencies { modImplementation("maven.modrinth:cloth-config:13.0.121+fabric") modImplementation("maven.modrinth:modmenu:9.0.0") modCompileOnly("maven.modrinth:iris:1.6.17+1.20.4") + modCompileOnly("maven.modrinth:starlight:1.1.3+1.20.4") //modRuntimeOnly("maven.modrinth:iris:1.6.17+1.20.4") } diff --git a/gradle.properties b/gradle.properties index e33c365e..500969dc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,10 +5,10 @@ org.gradle.jvmargs=-Xmx1G # check these on https://modmuss50.me/fabric.html minecraft_version=1.20.4 yarn_mappings=1.20.4+build.1 -loader_version=0.15.0 +loader_version=0.15.1 # Mod Properties -mod_version = 0.1.1-alpha +mod_version = 0.1.2-alpha maven_group = me.cortex archives_base_name = voxy diff --git a/src/main/java/me/cortex/voxy/client/config/VoxyConfig.java b/src/main/java/me/cortex/voxy/client/config/VoxyConfig.java index 39fce38b..47f671d4 100644 --- a/src/main/java/me/cortex/voxy/client/config/VoxyConfig.java +++ b/src/main/java/me/cortex/voxy/client/config/VoxyConfig.java @@ -23,6 +23,7 @@ public class VoxyConfig { public boolean ingestEnabled = true; public int qualityScale = 12; public int maxSections = 200_000; + public int renderDistance = 128; public int geometryBufferSize = (1<<30)/8; public int ingestThreads = 2; public int savingThreads = 4; diff --git a/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java b/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java index fc862c3d..ab60f9fc 100644 --- a/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java +++ b/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java @@ -91,6 +91,12 @@ public class VoxyConfigScreenFactory implements ModMenuApi { .setDefaultValue(DEFAULT.maxSections) .build()); + category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.renderDistance"), config.maxSections, 16, 2048) + .setTooltip(Text.translatable("voxy.config.general.renderDistance.tooltip")) + .setSaveConsumer(val -> config.renderDistance = val) + .setDefaultValue(DEFAULT.renderDistance) + .build()); + //category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.compression"), config.savingCompressionLevel, 1, 21) // .setTooltip(Text.translatable("voxy.config.general.compression.tooltip")) // .setSaveConsumer(val -> config.savingCompressionLevel = val) diff --git a/src/main/java/me/cortex/voxy/client/core/DistanceTracker.java b/src/main/java/me/cortex/voxy/client/core/DistanceTracker.java index 8068d12c..0fd29a96 100644 --- a/src/main/java/me/cortex/voxy/client/core/DistanceTracker.java +++ b/src/main/java/me/cortex/voxy/client/core/DistanceTracker.java @@ -22,14 +22,16 @@ public class DistanceTracker { private final RenderTracker tracker; private final int minYSection; private final int maxYSection; + private final int renderDistance; - public DistanceTracker(RenderTracker tracker, int[] lodRingScales, int cacheLoadDistance, int cacheUnloadDistance) { + public DistanceTracker(RenderTracker tracker, int[] lodRingScales, int renderDistance, int cacheLoadDistance, int cacheUnloadDistance) { this.loDRings = new TransitionRing2D[lodRingScales.length]; this.cacheLoadRings = new TransitionRing2D[lodRingScales.length]; this.cacheUnloadRings = new TransitionRing2D[lodRingScales.length]; this.tracker = tracker; this.minYSection = MinecraftClient.getInstance().world.getBottomSectionCoord()/2;//-128; this.maxYSection = MinecraftClient.getInstance().world.getTopSectionCoord()/2;//128; + this.renderDistance = renderDistance; //The rings 0+ start at 64 vanilla rd, no matter what the game is set at, that is if the game is set to 32 rd 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 ba546cf3..a2944e36 100644 --- a/src/main/java/me/cortex/voxy/client/core/VoxelCore.java +++ b/src/main/java/me/cortex/voxy/client/core/VoxelCore.java @@ -49,10 +49,12 @@ public class VoxelCore { private final RenderTracker renderTracker; private final AbstractFarWorldRenderer renderer; + private Viewport viewport; private final PostProcessing postProcessing; //private final Thread shutdownThread = new Thread(this::shutdown); + public VoxelCore(ContextSelectionSystem.Selection worldSelection) { this.world = worldSelection.createEngine(); System.out.println("Initializing voxy core"); @@ -60,6 +62,7 @@ public class VoxelCore { //Trigger the shared index buffer loading SharedIndexBuffer.INSTANCE.id(); this.renderer = new Gl46FarWorldRenderer(VoxyConfig.CONFIG.geometryBufferSize, VoxyConfig.CONFIG.maxSections); + this.viewport = this.renderer.createViewport(); System.out.println("Renderer initialized"); this.renderTracker = new RenderTracker(this.world, this.renderer); @@ -71,7 +74,7 @@ public class VoxelCore { //To get to chunk scale multiply the scale by 2, the scale is after how many chunks does the lods halve int q = VoxyConfig.CONFIG.qualityScale; //TODO: add an option for cache load and unload distance - this.distanceTracker = new DistanceTracker(this.renderTracker, new int[]{q,q,q,q}, 8, 16); + this.distanceTracker = new DistanceTracker(this.renderTracker, new int[]{q,q,q,q}, VoxyConfig.CONFIG.renderDistance/2, 6, 6); System.out.println("Distance tracker initialized"); this.postProcessing = new PostProcessing(); @@ -151,21 +154,13 @@ public class VoxelCore { //var fb = Iris.getPipelineManager().getPipelineNullable().getSodiumTerrainPipeline().getTerrainSolidFramebuffer(); //fb.bind(); + var projection = computeProjectionMat(); + this.viewport.setProjection(projection).setModelView(matrices.peek().getPositionMatrix()).setCamera(cameraX, cameraY, cameraZ); + int boundFB = GL11.glGetInteger(GL_DRAW_FRAMEBUFFER_BINDING); this.postProcessing.setup(MinecraftClient.getInstance().getFramebuffer().textureWidth, MinecraftClient.getInstance().getFramebuffer().textureHeight, boundFB); - //TODO: FIXME: since we just bound the post processing FB the depth information isnt - // copied over, we must do this manually and also copy it with respect to the - // near/far planes - - - //TODO: have the renderer also render a bounding full face just like black boarders around lvl 0 - // this is cause the terrain might not exist and so all the caves are visible causing hell for the - // occlusion culler - - var projection = computeProjectionMat(); - - this.renderer.renderFarAwayOpaque(projection, matrices, cameraX, cameraY, cameraZ); + this.renderer.renderFarAwayOpaque(this.viewport); //Compute the SSAO of the rendered terrain this.postProcessing.computeSSAO(projection, matrices); @@ -204,7 +199,7 @@ public class VoxelCore { System.out.println("Render gen shut down"); try {this.world.shutdown();} catch (Exception e) {System.err.println(e);} System.out.println("World engine shut down"); - try {this.renderer.shutdown();} catch (Exception e) {System.err.println(e);} + try {this.renderer.shutdown(); if (viewport!=null)this.viewport.delete();} catch (Exception e) {System.err.println(e);} System.out.println("Renderer shut down"); if (this.postProcessing!=null){try {this.postProcessing.shutdown();} catch (Exception e) {System.err.println(e);}} System.out.println("Voxel core shut down"); diff --git a/src/main/java/me/cortex/voxy/client/core/model/ModelTextureBakery.java b/src/main/java/me/cortex/voxy/client/core/model/ModelTextureBakery.java index 03fb093a..1cae6127 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/ModelTextureBakery.java +++ b/src/main/java/me/cortex/voxy/client/core/model/ModelTextureBakery.java @@ -39,8 +39,7 @@ import static org.lwjgl.opengl.ARBImaging.glBlendEquation; import static org.lwjgl.opengl.ARBShaderImageLoadStore.GL_FRAMEBUFFER_BARRIER_BIT; import static org.lwjgl.opengl.ARBShaderImageLoadStore.glMemoryBarrier; import static org.lwjgl.opengl.GL11.*; -import static org.lwjgl.opengl.GL13.GL_TEXTURE0; -import static org.lwjgl.opengl.GL13.glActiveTexture; +import static org.lwjgl.opengl.GL13.*; import static org.lwjgl.opengl.GL14C.glBlendFuncSeparate; import static org.lwjgl.opengl.GL20C.glUniformMatrix4fv; import static org.lwjgl.opengl.GL45C.glBlitNamedFramebuffer; @@ -59,6 +58,7 @@ public class ModelTextureBakery { .addCapability(GL_BLEND) .addCapability(GL_CULL_FACE) .addTexture(GL_TEXTURE0) + .addTexture(GL_TEXTURE1) .build() ; private final Shader rasterShader = Shader.make() @@ -138,7 +138,8 @@ public class ModelTextureBakery { } - renderLayer.startDrawing(); + //TODO: figure out why calling this makes minecraft render black + //renderLayer.startDrawing(); glClearColor(0,0,0,0); glClearDepth(1); glBindFramebuffer(GL_FRAMEBUFFER, this.framebuffer.id); diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/AbstractFarWorldRenderer.java b/src/main/java/me/cortex/voxy/client/core/rendering/AbstractFarWorldRenderer.java index 2239afc9..17bdc07e 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/AbstractFarWorldRenderer.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/AbstractFarWorldRenderer.java @@ -3,12 +3,14 @@ package me.cortex.voxy.client.core.rendering; //NOTE: an idea on how to do it is so that any render section, we _keep_ aquired (yes this will be very memory intensive) // could maybe tosomething else +import com.mojang.blaze3d.systems.RenderSystem; import me.cortex.voxy.client.core.gl.GlBuffer; import me.cortex.voxy.client.core.model.ModelManager; import me.cortex.voxy.client.core.rendering.building.BuiltSection; import me.cortex.voxy.client.core.rendering.util.DownloadStream; import me.cortex.voxy.client.core.rendering.util.UploadStream; import me.cortex.voxy.common.world.other.Mapper; +import net.minecraft.block.Blocks; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.Camera; import net.minecraft.client.render.Frustum; @@ -36,7 +38,7 @@ import static org.lwjgl.opengl.GL30.*; //Todo: tinker with having the compute shader where each thread is a position to render? maybe idk -public abstract class AbstractFarWorldRenderer { +public abstract class AbstractFarWorldRenderer { protected final int vao = glGenVertexArrays(); protected final GlBuffer uniformBuffer; @@ -44,6 +46,8 @@ public abstract class AbstractFarWorldRenderer { protected final ModelManager models; protected final GlBuffer lightDataBuffer; + protected final int maxSections; + //Current camera base level section position protected int sx; protected int sy; @@ -54,6 +58,7 @@ public abstract class AbstractFarWorldRenderer { private final ConcurrentLinkedDeque blockStateUpdates = new ConcurrentLinkedDeque<>(); private final ConcurrentLinkedDeque biomeUpdates = new ConcurrentLinkedDeque<>(); public AbstractFarWorldRenderer(int geometrySize, int maxSections) { + this.maxSections = maxSections; this.uniformBuffer = new GlBuffer(1024); this.lightDataBuffer = new GlBuffer(256*4);//256 of uint this.geometry = new GeometryManager(geometrySize*8L, maxSections); @@ -112,11 +117,14 @@ public abstract class AbstractFarWorldRenderer { var update = this.blockStateUpdates.pop(); this.models.addEntry(update.id, update.state); } + //this.models.bakery.renderFaces(Blocks.LAVA.getDefaultState(), 1234, true); } + //TODO: fix this in a better way than this ungodly hacky stuff + RenderSystem.setShaderFogColor(1f, 1f, 1f, 0f); } - public abstract void renderFarAwayOpaque(Matrix4f projection, MatrixStack stack, double cx, double cy, double cz); + public abstract void renderFarAwayOpaque(T viewport); public abstract void renderFarAwayTranslucent(); @@ -147,4 +155,6 @@ public abstract class AbstractFarWorldRenderer { public ModelManager getModelManager() { return this.models; } + + public abstract T createViewport(); } diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/Gl46FarWorldRenderer.java b/src/main/java/me/cortex/voxy/client/core/rendering/Gl46FarWorldRenderer.java index ea4c823e..e45bc6c0 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/Gl46FarWorldRenderer.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/Gl46FarWorldRenderer.java @@ -5,6 +5,7 @@ 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.block.Blocks; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.util.math.MatrixStack; import org.joml.Matrix4f; @@ -30,7 +31,7 @@ import static org.lwjgl.opengl.GL43.*; import static org.lwjgl.opengl.GL43.GL_SHADER_STORAGE_BUFFER; import static org.lwjgl.opengl.GL45C.glClearNamedBufferData; -public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { +public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { private final Shader commandGen = Shader.make() .add(ShaderType.COMPUTE, "voxy:lod/gl46/cmdgen.comp") .compile(); @@ -49,15 +50,12 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { private final GlBuffer glCommandBuffer; private final GlBuffer glCommandCountBuffer; - private final GlBuffer glVisibilityBuffer; public Gl46FarWorldRenderer(int geometryBuffer, int maxSections) { super(geometryBuffer, maxSections); this.glCommandBuffer = new GlBuffer(maxSections*5L*4 * 6); this.glCommandCountBuffer = new GlBuffer(4*2); - this.glVisibilityBuffer = new GlBuffer(maxSections*4L); glClearNamedBufferData(this.glCommandBuffer.id, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE, new int[1]); - glClearNamedBufferData(this.glVisibilityBuffer.id, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE, new int[1]); setupVao(); } @@ -72,7 +70,6 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, this.glCommandBuffer.id); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, this.glCommandCountBuffer.id); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, this.geometry.metaId()); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, this.glVisibilityBuffer.id); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, this.models.getBufferId()); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 7, this.models.getColourBufferId()); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 8, this.lightDataBuffer.id);//Lighting LUT @@ -85,12 +82,11 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { // would be visible in the current viewport (if there are 2 viewports) //To fix the issue, need to make a viewport api, that independently tracks the frameId and has its own glVisibilityBuffer buffer - private int frameId; - private void updateUniformBuffer(Matrix4f projection, MatrixStack stack, double cx, double cy, double cz) { + private void updateUniformBuffer(Gl46Viewport viewport) { long ptr = UploadStream.INSTANCE.upload(this.uniformBuffer, 0, this.uniformBuffer.size()); - var mat = new Matrix4f(projection).mul(stack.peek().getPositionMatrix()); - var innerTranslation = new Vector3f((float) (cx-(this.sx<<5)), (float) (cy-(this.sy<<5)), (float) (cz-(this.sz<<5))); + var mat = new Matrix4f(viewport.projection).mul(viewport.modelView); + var innerTranslation = new Vector3f((float) (viewport.cameraX-(this.sx<<5)), (float) (viewport.cameraY-(this.sy<<5)), (float) (viewport.cameraZ-(this.sz<<5))); mat.translate(-innerTranslation.x, -innerTranslation.y, -innerTranslation.z); mat.getToAddress(ptr); ptr += 4*4*4; MemoryUtil.memPutInt(ptr, this.sx); ptr += 4; @@ -102,10 +98,10 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { plane.getToAddress(ptr); ptr += 4*4; } innerTranslation.getToAddress(ptr); ptr += 4*3; - MemoryUtil.memPutInt(ptr, this.frameId++); ptr += 4; + MemoryUtil.memPutInt(ptr, viewport.frameId++); ptr += 4; } - public void renderFarAwayOpaque(Matrix4f projection, MatrixStack stack, double cx, double cy, double cz) { + public void renderFarAwayOpaque(Gl46Viewport viewport) { if (this.geometry.getSectionCount() == 0) { return; } @@ -123,11 +119,12 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { //RenderSystem.enableBlend(); //RenderSystem.defaultBlendFunc(); - this.updateUniformBuffer(projection, stack, cx, cy, cz); + this.updateUniformBuffer(viewport); UploadStream.INSTANCE.commit(); glBindVertexArray(this.vao); + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, viewport.visibilityBuffer.id); //Bind the texture atlas @@ -215,6 +212,10 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { RenderLayer.getTranslucent().endDrawing(); } + @Override + public Gl46Viewport createViewport() { + return new Gl46Viewport(this.maxSections); + } @Override public void shutdown() { @@ -223,7 +224,6 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer { this.lodShader.free(); this.cullShader.free(); this.glCommandBuffer.free(); - this.glVisibilityBuffer.free(); this.glCommandCountBuffer.free(); } diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/Gl46Viewport.java b/src/main/java/me/cortex/voxy/client/core/rendering/Gl46Viewport.java new file mode 100644 index 00000000..e8ef86ff --- /dev/null +++ b/src/main/java/me/cortex/voxy/client/core/rendering/Gl46Viewport.java @@ -0,0 +1,55 @@ +package me.cortex.voxy.client.core.rendering; + +import me.cortex.voxy.client.core.gl.GlBuffer; +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.render.RenderLayer; +import net.minecraft.client.util.math.MatrixStack; +import org.joml.Matrix4f; +import org.joml.Vector3f; +import org.lwjgl.opengl.GL11C; +import org.lwjgl.system.MemoryUtil; + +import java.util.List; + +import static org.lwjgl.opengl.ARBIndirectParameters.GL_PARAMETER_BUFFER_ARB; +import static org.lwjgl.opengl.ARBIndirectParameters.glMultiDrawElementsIndirectCountARB; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.opengl.GL14C.glBlendFuncSeparate; +import static org.lwjgl.opengl.GL30.glBindVertexArray; +import static org.lwjgl.opengl.GL30C.GL_R8UI; +import static org.lwjgl.opengl.GL30C.GL_RED_INTEGER; +import static org.lwjgl.opengl.GL40C.GL_DRAW_INDIRECT_BUFFER; +import static org.lwjgl.opengl.GL42.GL_BLEND; +import static org.lwjgl.opengl.GL42.GL_CULL_FACE; +import static org.lwjgl.opengl.GL42.GL_DEPTH_TEST; +import static org.lwjgl.opengl.GL42.GL_ONE; +import static org.lwjgl.opengl.GL42.GL_ONE_MINUS_SRC_ALPHA; +import static org.lwjgl.opengl.GL42.GL_SRC_ALPHA; +import static org.lwjgl.opengl.GL42.GL_TEXTURE_2D; +import static org.lwjgl.opengl.GL42.GL_TEXTURE_BINDING_2D; +import static org.lwjgl.opengl.GL42.GL_UNSIGNED_BYTE; +import static org.lwjgl.opengl.GL42.GL_UNSIGNED_INT; +import static org.lwjgl.opengl.GL42.glBindTexture; +import static org.lwjgl.opengl.GL42.glColorMask; +import static org.lwjgl.opengl.GL42.glDepthMask; +import static org.lwjgl.opengl.GL42.glDisable; +import static org.lwjgl.opengl.GL42.glEnable; +import static org.lwjgl.opengl.GL42.*; +import static org.lwjgl.opengl.GL43.*; +import static org.lwjgl.opengl.GL45C.glClearNamedBufferData; + +public class Gl46Viewport extends Viewport { + GlBuffer visibilityBuffer; + public Gl46Viewport(int maxSections) { + this.visibilityBuffer = new GlBuffer(maxSections*4L); + glClearNamedBufferData(this.visibilityBuffer.id, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE, new int[1]); + } + + @Override + public void delete() { + this.visibilityBuffer.free(); + } +} diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/Viewport.java b/src/main/java/me/cortex/voxy/client/core/rendering/Viewport.java new file mode 100644 index 00000000..da8f575d --- /dev/null +++ b/src/main/java/me/cortex/voxy/client/core/rendering/Viewport.java @@ -0,0 +1,31 @@ +package me.cortex.voxy.client.core.rendering; + +import org.joml.Matrix4f; + +public abstract class Viewport { + int frameId; + Matrix4f projection; + Matrix4f modelView; + double cameraX; + double cameraY; + double cameraZ; + + public abstract void delete(); + + public Viewport setProjection(Matrix4f projection) { + this.projection = projection; + return this; + } + + public Viewport setModelView(Matrix4f modelView) { + this.modelView = modelView; + return this; + } + + public Viewport setCamera(double x, double y, double z) { + this.cameraX = x; + this.cameraY = y; + this.cameraZ = z; + return this; + } +} diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java index 9b38ba05..375adc47 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java @@ -256,7 +256,7 @@ public class RenderDataFactory { } //if the model has a fluid state but is not a liquid need to see if the solid state had a face rendered and that face is occluding, if so, dont render the fluid state face - if (ModelManager.faceOccludes(metadata, face)) { + if ((!ModelManager.isFluid(metadata)) && ModelManager.faceOccludes(metadata, face)) { return false; } diff --git a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinBackgroundRenderer.java b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinBackgroundRenderer.java deleted file mode 100644 index ac816a80..00000000 --- a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinBackgroundRenderer.java +++ /dev/null @@ -1,14 +0,0 @@ -package me.cortex.voxy.client.mixin.minecraft; - -import net.minecraft.client.render.BackgroundRenderer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - -@Mixin(BackgroundRenderer.class) -public class MixinBackgroundRenderer { - @ModifyConstant(method = "applyFog", constant = @Constant(floatValue = 192.0F), require = 0) - private static float changeFog(float fog) { - return 9999999f; - } -} diff --git a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinWorldRenderer.java b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinWorldRenderer.java index 09255922..b3b08c8b 100644 --- a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinWorldRenderer.java +++ b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinWorldRenderer.java @@ -19,10 +19,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(WorldRenderer.class) public abstract class MixinWorldRenderer implements IGetVoxelCore { - @Shadow protected abstract void renderLayer(RenderLayer renderLayer, MatrixStack matrices, double cameraX, double cameraY, double cameraZ, Matrix4f positionMatrix); - - @Shadow protected abstract void setupTerrain(Camera camera, Frustum frustum, boolean hasForcedFrustum, boolean spectator); - @Shadow private Frustum frustum; @Shadow private @Nullable ClientWorld world; @@ -103,15 +99,4 @@ public abstract class MixinWorldRenderer implements IGetVoxelCore { this.core = null; } } - - @Redirect(method = "render", at = @At(value = "INVOKE", target = "Ljava/lang/Math;max(FF)F"), require = 0) - private float redirectMax(float a, float b) { - return a; - } - - @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/GameRenderer;getViewDistance()F"), require = 0) - private float changeRD(GameRenderer instance) { - float viewDistance = instance.getViewDistance(); - return 16*5120; - } } diff --git a/src/main/java/me/cortex/voxy/common/world/other/LightingFetcher.java b/src/main/java/me/cortex/voxy/common/world/other/LightingFetcher.java new file mode 100644 index 00000000..de094cd2 --- /dev/null +++ b/src/main/java/me/cortex/voxy/common/world/other/LightingFetcher.java @@ -0,0 +1,79 @@ +package me.cortex.voxy.common.world.other; + +import ca.spottedleaf.starlight.common.light.StarLightEngine; +import ca.spottedleaf.starlight.common.light.StarLightInterface; +import ca.spottedleaf.starlight.common.light.StarLightLightingProvider; +import it.unimi.dsi.fastutil.Pair; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.MinecraftClient; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.ChunkSectionPos; +import net.minecraft.world.LightType; +import net.minecraft.world.chunk.ChunkNibbleArray; +import net.minecraft.world.chunk.WorldChunk; + +import java.util.Map; + +public class LightingFetcher { + //TODO: FIXME: I dont think the 2 codepaths are needed, just do what you do for starlight for vanilla and it should work just fine + + private static boolean STARLIGHT_INSTALLED = FabricLoader.getInstance().isModLoaded("starlight"); + private static void fetchLightingDataVanilla(Map> out, WorldChunk chunk) { + var lp = chunk.getWorld().getLightingProvider(); + var blockLight = lp.get(LightType.BLOCK); + var skyLight = lp.get(LightType.SKY); + int i = chunk.getBottomSectionCoord() - 1; + for (var section : chunk.getSectionArray()) { + i++; + if (section == null) continue; + if (section.isEmpty()) continue; + var pos = ChunkSectionPos.from(chunk.getPos(), i); + if (blockLight.getLightSection(pos).isUninitialized()) + continue; + var bl = blockLight.getLightSection(pos); + var sl = skyLight.getLightSection(pos); + if (bl == null && sl == null) continue; + bl = bl==null?null:bl.copy(); + sl = sl==null?null:sl.copy(); + out.put(pos.asLong(), Pair.of(bl, sl)); + } + } + + private static void fetchLightingDataStarlight(Map> out, WorldChunk chunk) { + var starlight = ((StarLightLightingProvider)chunk.getWorld().getLightingProvider()); + var blp = starlight.getLightEngine().getBlockReader(); + var slp = starlight.getLightEngine().getSkyReader(); + + int i = chunk.getBottomSectionCoord() - 1; + for (var section : chunk.getSectionArray()) { + i++; + if (section == null) continue; + if (section.isEmpty()) continue; + var pos = ChunkSectionPos.from(chunk.getPos(), i); + var bl = blp.getLightSection(pos); + if (!(bl == null || bl.isUninitialized())) { + bl = bl.copy(); + } else { + bl = null; + } + var sl = slp.getLightSection(pos); + if (!(sl == null || sl.isUninitialized())) { + sl = sl.copy(); + } else { + sl = null; + } + if (bl == null && sl == null) { + continue; + } + out.put(pos.asLong(), Pair.of(bl, sl)); + } + } + + public static void fetchLightingData(Map> out, WorldChunk chunk) { + if (STARLIGHT_INSTALLED) { + fetchLightingDataStarlight(out, chunk); + } else { + fetchLightingDataVanilla(out, chunk); + } + } +} diff --git a/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java b/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java index fda8c10c..1e99783f 100644 --- a/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java +++ b/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java @@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.Pair; import me.cortex.voxy.common.voxelization.VoxelizedSection; import me.cortex.voxy.common.voxelization.WorldConversionFactory; import me.cortex.voxy.common.world.WorldEngine; +import me.cortex.voxy.common.world.other.LightingFetcher; import net.minecraft.util.math.ChunkSectionPos; import net.minecraft.world.LightType; import net.minecraft.world.chunk.ChunkNibbleArray; @@ -79,24 +80,7 @@ public class VoxelIngestService { } public void enqueueIngest(WorldChunk chunk) { - var lp = chunk.getWorld().getLightingProvider(); - var blockLight = lp.get(LightType.BLOCK); - var skyLight = lp.get(LightType.SKY); - int i = chunk.getBottomSectionCoord() - 1; - for (var section : chunk.getSectionArray()) { - i++; - if (section == null) continue; - if (section.isEmpty()) continue; - var pos = ChunkSectionPos.from(chunk.getPos(), i); - if (lp.getStatus(LightType.BLOCK, pos) == LightStorage.Status.EMPTY) - continue; - var bl = blockLight.getLightSection(pos); - var sl = skyLight.getLightSection(pos); - if (bl == null && sl == null) continue; - bl = bl==null?null:bl.copy(); - sl = sl==null?null:sl.copy(); - this.captureLightMap.put(pos.asLong(), Pair.of(bl, sl)); - } + LightingFetcher.fetchLightingData(this.captureLightMap, chunk); this.ingestQueue.add(chunk); this.ingestCounter.release(); } diff --git a/src/main/resources/assets/voxy/lang/en_us.json b/src/main/resources/assets/voxy/lang/en_us.json index 20ca3e2d..3e15c665 100644 --- a/src/main/resources/assets/voxy/lang/en_us.json +++ b/src/main/resources/assets/voxy/lang/en_us.json @@ -15,6 +15,8 @@ "voxy.config.general.geometryBuffer.tooltip": "How many quads the geometry buffer can hold", "voxy.config.general.maxSections": "Max Sections", "voxy.config.general.maxSections.tooltip": "The max number of sections the renderer can contain", + "voxy.config.general.renderDistance": "Render Distance", + "voxy.config.general.renderDistance.tooltip": "The render distance in chunks", "voxy.config.threads.ingest": "Ingest", "voxy.config.threads.ingest.tooltip": "How many threads voxy will use for ingesting new chunks", diff --git a/src/main/resources/voxy.mixins.json b/src/main/resources/voxy.mixins.json index 1695a8b6..bcc8afa0 100644 --- a/src/main/resources/voxy.mixins.json +++ b/src/main/resources/voxy.mixins.json @@ -4,7 +4,6 @@ "compatibilityLevel": "JAVA_17", "client": [ "joml.AccessFrustumIntersection", - "minecraft.MixinBackgroundRenderer", "minecraft.MixinClientChunkManager", "minecraft.MixinDebugHud", "minecraft.MixinMinecraftClient",