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 82a3a3a5..8e9d1d33 100644 --- a/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java +++ b/src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java @@ -205,8 +205,18 @@ 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 a5c77555..6f91e2f2 100644 --- a/src/main/java/me/cortex/voxy/client/core/IrisVoxyRenderPipeline.java +++ b/src/main/java/me/cortex/voxy/client/core/IrisVoxyRenderPipeline.java @@ -148,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); } @@ -225,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/rendering/ChunkBoundRenderer.java b/src/main/java/me/cortex/voxy/client/core/rendering/ChunkBoundRenderer.java index 9d95354d..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 @@ -7,6 +7,7 @@ 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; @@ -36,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(); + 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) { @@ -116,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 AbstractSectionRenderer>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