diff --git a/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java b/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java index 3dc9b056..3ead8118 100644 --- a/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java +++ b/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java @@ -69,6 +69,11 @@ public abstract class AbstractRenderPipeline extends TrackedObject { this.sectionRenderer = sectionRenderer; } + //Called before the pipeline starts running, used to update uniforms etc + public void preSetup(Viewport viewport) { + + } + protected abstract int setup(Viewport viewport, int sourceFramebuffer, int srcWidth, int srcHeight); protected abstract void postOpaquePreTranslucent(Viewport viewport); protected void finish(Viewport viewport, int sourceFrameBuffer, int srcWidth, int srcHeight) { @@ -200,8 +205,19 @@ public abstract class AbstractRenderPipeline extends TrackedObject { public abstract void setupAndBindTranslucent(Viewport viewport); + public void bindUniforms() { + this.bindUniforms(-1); + } + + public void bindUniforms(int index) { + } + //null means no function, otherwise return the taa injection function - public String taaFunction(AbstractSectionRenderer renderer, String functionName) { + public String taaFunction(String functionName) { + return this.taaFunction(-1, functionName); + } + + public String taaFunction(int uboBindingPoint, String functionName) { return null; } diff --git a/src/main/java/me/cortex/voxy/client/core/IrisVoxyRenderPipeline.java b/src/main/java/me/cortex/voxy/client/core/IrisVoxyRenderPipeline.java index c1e461bc..6f91e2f2 100644 --- a/src/main/java/me/cortex/voxy/client/core/IrisVoxyRenderPipeline.java +++ b/src/main/java/me/cortex/voxy/client/core/IrisVoxyRenderPipeline.java @@ -90,14 +90,18 @@ public class IrisVoxyRenderPipeline extends AbstractRenderPipeline { } @Override - protected int setup(Viewport viewport, int sourceFramebuffer, int srcWidth, int srcHeight) { + public void preSetup(Viewport viewport) { + super.preSetup(viewport); if (this.shaderUniforms != null) { //Update the uniforms long ptr = UploadStream.INSTANCE.uploadTo(this.shaderUniforms); this.data.getUniforms().updater().accept(ptr); UploadStream.INSTANCE.commit(); } + } + @Override + protected int setup(Viewport viewport, int sourceFramebuffer, int srcWidth, int srcHeight) { this.fb.resize(viewport.width, viewport.height); this.fbTranslucent.resize(viewport.width, viewport.height); @@ -144,10 +148,20 @@ public class IrisVoxyRenderPipeline extends AbstractRenderPipeline { } - private void doBindings() { + @Override + public void bindUniforms() { + this.bindUniforms(UNIFORM_BINDING_POINT); + } + + @Override + public void bindUniforms(int bindingPoint) { if (this.shaderUniforms != null) { - GL30.glBindBufferBase(GL_UNIFORM_BUFFER, 5, this.shaderUniforms.id);// todo: dont randomly select this to 5 + GL30.glBindBufferBase(GL_UNIFORM_BUFFER, bindingPoint, this.shaderUniforms.id);// todo: dont randomly select this to 5 } + } + + private void doBindings() { + this.bindUniforms(); if (this.data.getSsboSet() != null) { this.data.getSsboSet().bindingFunction().accept(10); } @@ -221,11 +235,16 @@ public class IrisVoxyRenderPipeline extends AbstractRenderPipeline { } @Override - public String taaFunction(AbstractSectionRenderer renderer, String functionName) { + public String taaFunction(String functionName) { + return this.taaFunction(UNIFORM_BINDING_POINT, functionName); + } + + @Override + public String taaFunction(int uboBindingPoint, String functionName) { var builder = new StringBuilder(); if (this.data.getUniforms() != null) { - builder.append("layout(binding = "+UNIFORM_BINDING_POINT+", std140) uniform ShaderUniformBindings ") + builder.append("layout(binding = "+uboBindingPoint+", std140) uniform ShaderUniformBindings ") .append(this.data.getUniforms().layout()) .append(";\n\n"); } diff --git a/src/main/java/me/cortex/voxy/client/core/RenderPipelineFactory.java b/src/main/java/me/cortex/voxy/client/core/RenderPipelineFactory.java index 3585bd9c..28026da6 100644 --- a/src/main/java/me/cortex/voxy/client/core/RenderPipelineFactory.java +++ b/src/main/java/me/cortex/voxy/client/core/RenderPipelineFactory.java @@ -7,6 +7,7 @@ import me.cortex.voxy.client.core.util.IrisUtil; import me.cortex.voxy.client.iris.IGetIrisVoxyPipelineData; import me.cortex.voxy.common.Logger; import net.irisshaders.iris.Iris; +import net.irisshaders.iris.api.v0.IrisApi; import java.util.function.BooleanSupplier; @@ -34,7 +35,13 @@ public class RenderPipelineFactory { return null; } Logger.info("Creating voxy iris render pipeline"); - return new IrisVoxyRenderPipeline(pipeData, nodeManager, nodeCleaner, traversal, frexSupplier); + try { + return new IrisVoxyRenderPipeline(pipeData, nodeManager, nodeCleaner, traversal, frexSupplier); + } catch (Exception e) { + Logger.error("Failed to create iris render pipeline", e); + IrisUtil.disableIrisShaders(); + return null; + } } return null; } diff --git a/src/main/java/me/cortex/voxy/client/core/VoxyRenderSystem.java b/src/main/java/me/cortex/voxy/client/core/VoxyRenderSystem.java index 770d9482..552b9b6d 100644 --- a/src/main/java/me/cortex/voxy/client/core/VoxyRenderSystem.java +++ b/src/main/java/me/cortex/voxy/client/core/VoxyRenderSystem.java @@ -139,7 +139,7 @@ public class VoxyRenderSystem { this.renderDistanceTracker.setRenderDistance(VoxyConfig.CONFIG.sectionRenderDistance); } - this.chunkBoundRenderer = new ChunkBoundRenderer(); + this.chunkBoundRenderer = new ChunkBoundRenderer(this.pipeline); Logger.info("Voxy render system created with " + geometryCapacity + " geometry capacity, using pipeline '" + this.pipeline.getClass().getSimpleName() + "' with renderer '" + sectionRenderer.getClass().getSimpleName() + "'"); } catch (RuntimeException e) { @@ -233,6 +233,7 @@ public class VoxyRenderSystem { //this.autoBalanceSubDivSize(); + this.pipeline.preSetup(viewport); TimingStatistics.E.start(); if (!IrisUtil.irisShadowActive()) { diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/ChunkBoundRenderer.java b/src/main/java/me/cortex/voxy/client/core/rendering/ChunkBoundRenderer.java index b69bd8b0..ac626ae7 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/ChunkBoundRenderer.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/ChunkBoundRenderer.java @@ -2,10 +2,12 @@ package me.cortex.voxy.client.core.rendering; import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import me.cortex.voxy.client.core.AbstractRenderPipeline; import me.cortex.voxy.client.core.gl.GlBuffer; import me.cortex.voxy.client.core.gl.GlVertexArray; import me.cortex.voxy.client.core.gl.shader.AutoBindingShader; import me.cortex.voxy.client.core.gl.shader.Shader; +import me.cortex.voxy.client.core.gl.shader.ShaderLoader; import me.cortex.voxy.client.core.gl.shader.ShaderType; import me.cortex.voxy.client.core.rendering.util.SharedIndexBuffer; import me.cortex.voxy.client.core.rendering.util.UploadStream; @@ -35,18 +37,28 @@ public class ChunkBoundRenderer { private final GlBuffer uniformBuffer = new GlBuffer(128); private final Long2IntOpenHashMap chunk2idx = new Long2IntOpenHashMap(INIT_MAX_CHUNK_COUNT); private long[] idx2chunk = new long[INIT_MAX_CHUNK_COUNT]; - private final Shader rasterShader = Shader.makeAuto() - .add(ShaderType.VERTEX, "voxy:chunkoutline/outline.vsh") - .add(ShaderType.FRAGMENT, "voxy:chunkoutline/outline.fsh") - .compile() - .ubo(0, this.uniformBuffer) - .ssbo(1, this.chunkPosBuffer); + private final Shader rasterShader; private final LongOpenHashSet addQueue = new LongOpenHashSet(); private final LongOpenHashSet remQueue = new LongOpenHashSet(); - public ChunkBoundRenderer() { + private final AbstractRenderPipeline pipeline; + public ChunkBoundRenderer(AbstractRenderPipeline pipeline) { this.chunk2idx.defaultReturnValue(-1); + this.pipeline = pipeline; + + String vert = ShaderLoader.parse("voxy:chunkoutline/outline.vsh"); + String taa = pipeline.taaFunction("getTAA"); + if (taa != null) { + vert = vert+"\n\n\n"+taa; + } + this.rasterShader = Shader.makeAuto() + .addSource(ShaderType.VERTEX, vert) + .defineIf("TAA", taa != null) + .add(ShaderType.FRAGMENT, "voxy:chunkoutline/outline.fsh") + .compile() + .ubo(0, this.uniformBuffer) + .ssbo(1, this.chunkPosBuffer); } public void addSection(long pos) { @@ -115,6 +127,7 @@ public class ChunkBoundRenderer { viewport.depthBoundingBuffer.bind(); this.rasterShader.bind(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedIndexBuffer.INSTANCE_BB_BYTE.id()); + this.pipeline.bindUniforms(); //Batch the draws into groups of size 32 int count = this.chunk2idx.size(); 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 8b885ab8..5409f7e0 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 @@ -95,7 +95,7 @@ public class MDICSectionRenderer extends AbstractSectionRenderer0&&iter.hasPrevious();index--){iter.previousLong();} + long slot = iter.previousLong(); + return (int) (slot>>ADDR_BITS); + } + /* public long allocFromLargest(int size) {//Allocates from the largest avalible block, this is useful for expanding later on @@ -190,4 +203,8 @@ public class AllocationArena { throw new IllegalStateException("Size set smaller than current size"); } } + + public long getLimit() { + return this.sizeLimit; + } } diff --git a/src/main/resources/assets/voxy/shaders/chunkoutline/outline.vsh b/src/main/resources/assets/voxy/shaders/chunkoutline/outline.vsh index 651085de..40b1a1e5 100644 --- a/src/main/resources/assets/voxy/shaders/chunkoutline/outline.vsh +++ b/src/main/resources/assets/voxy/shaders/chunkoutline/outline.vsh @@ -21,6 +21,10 @@ bool shouldRender(ivec3 icorner) { return (corner.x*corner.x + corner.z*corner.z < negInnerSec.w*negInnerSec.w) && abs(corner.y) < negInnerSec.w; } +#ifdef TAA +vec2 getTAA(); +#endif + void main() { uint id = (gl_InstanceID<<5)+gl_BaseInstance+(gl_VertexID>>3); @@ -38,4 +42,8 @@ void main() { //cubeCornerI.y = cubeCornerI.y*1024-512; gl_Position = MVP * vec4(vec3(cubeCornerI+origin)*16, 1); gl_Position.z -= 0.0005f; + + #ifdef TAA + gl_Position.xy += getTAA()*gl_Position.w;//Apply TAA if we have it + #endif } \ No newline at end of file diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46/cull/raster.frag b/src/main/resources/assets/voxy/shaders/lod/gl46/cull/raster.frag index f612a648..bcc2bf1e 100644 --- a/src/main/resources/assets/voxy/shaders/lod/gl46/cull/raster.frag +++ b/src/main/resources/assets/voxy/shaders/lod/gl46/cull/raster.frag @@ -1,8 +1,9 @@ #version 460 core -#extension GL_ARB_gpu_shader_int64 : enable -#define VISIBILITY_ACCESS #define VISIBILITY_BUFFER_BINDING 2 -#import +layout(binding = VISIBILITY_BUFFER_BINDING, std430) restrict buffer VisibilityBuffer { + uint visibilityData[]; +}; + layout(early_fragment_tests) in; flat in uint id; @@ -11,5 +12,5 @@ flat in uint value; void main() { visibilityData[id] = value; - //colour = vec4(float(id&7u)/7, float((id>>3)&7u)/7, float((id>>6)&7u)/7, 1); + //colour = vec4(float(id&7u)/7, float((id>>3)&7u)/7, float((id>>6)&7u)/7, 0); } \ No newline at end of file diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46/quads.frag b/src/main/resources/assets/voxy/shaders/lod/gl46/quads.frag index c4ce9a18..a736a92a 100644 --- a/src/main/resources/assets/voxy/shaders/lod/gl46/quads.frag +++ b/src/main/resources/assets/voxy/shaders/lod/gl46/quads.frag @@ -105,6 +105,7 @@ vec4 computeColour(vec2 texturePos, vec4 colour) { void main() { + //vec2 uv = vec2(0); //Tile is the tile we are in vec2 tile; vec2 uv2 = modf(uv, tile)*(1.0/(vec2(3.0,2.0)*256.0)); diff --git a/src/main/resources/client.voxy.mixins.json b/src/main/resources/client.voxy.mixins.json index f9c9fe92..842323cc 100644 --- a/src/main/resources/client.voxy.mixins.json +++ b/src/main/resources/client.voxy.mixins.json @@ -9,6 +9,7 @@ "iris.MixinPackRenderTargetDirectives", "iris.CustomUniformsAccessor", "iris.IrisRenderingPipelineAccessor", + "iris.MixinIris", "iris.MixinIrisRenderingPipeline", "iris.MixinIrisSamplers", "iris.MixinMatrixUniforms",