add taa injection into ChunkBoundRenderer, shift up uniform update

This commit is contained in:
mcrcortex
2025-09-12 10:04:56 +10:00
parent 2a4d6d085c
commit ad182d4170
5 changed files with 57 additions and 12 deletions

View File

@@ -205,8 +205,18 @@ public abstract class AbstractRenderPipeline extends TrackedObject {
public abstract void setupAndBindTranslucent(Viewport<?> viewport); 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 //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; return null;
} }

View File

@@ -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) { 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) { if (this.data.getSsboSet() != null) {
this.data.getSsboSet().bindingFunction().accept(10); this.data.getSsboSet().bindingFunction().accept(10);
} }
@@ -225,11 +235,16 @@ public class IrisVoxyRenderPipeline extends AbstractRenderPipeline {
} }
@Override @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(); var builder = new StringBuilder();
if (this.data.getUniforms() != null) { 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(this.data.getUniforms().layout())
.append(";\n\n"); .append(";\n\n");
} }

View File

@@ -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.GlVertexArray;
import me.cortex.voxy.client.core.gl.shader.AutoBindingShader; 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.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.gl.shader.ShaderType;
import me.cortex.voxy.client.core.rendering.util.SharedIndexBuffer; import me.cortex.voxy.client.core.rendering.util.SharedIndexBuffer;
import me.cortex.voxy.client.core.rendering.util.UploadStream; 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 GlBuffer uniformBuffer = new GlBuffer(128);
private final Long2IntOpenHashMap chunk2idx = new Long2IntOpenHashMap(INIT_MAX_CHUNK_COUNT); private final Long2IntOpenHashMap chunk2idx = new Long2IntOpenHashMap(INIT_MAX_CHUNK_COUNT);
private long[] idx2chunk = new long[INIT_MAX_CHUNK_COUNT]; private long[] idx2chunk = new long[INIT_MAX_CHUNK_COUNT];
private final Shader rasterShader = Shader.makeAuto() private final Shader rasterShader;
.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 LongOpenHashSet addQueue = new LongOpenHashSet(); private final LongOpenHashSet addQueue = new LongOpenHashSet();
private final LongOpenHashSet remQueue = new LongOpenHashSet(); private final LongOpenHashSet remQueue = new LongOpenHashSet();
private final AbstractRenderPipeline pipeline;
public ChunkBoundRenderer(AbstractRenderPipeline pipeline) { public ChunkBoundRenderer(AbstractRenderPipeline pipeline) {
this.chunk2idx.defaultReturnValue(-1); 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) { public void addSection(long pos) {
@@ -116,6 +127,7 @@ public class ChunkBoundRenderer {
viewport.depthBoundingBuffer.bind(); viewport.depthBoundingBuffer.bind();
this.rasterShader.bind(); this.rasterShader.bind();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedIndexBuffer.INSTANCE_BB_BYTE.id()); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedIndexBuffer.INSTANCE_BB_BYTE.id());
this.pipeline.bindUniforms();
//Batch the draws into groups of size 32 //Batch the draws into groups of size 32
int count = this.chunk2idx.size(); int count = this.chunk2idx.size();

View File

@@ -95,7 +95,7 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
//The pipeline can be used to transform the renderer in abstract ways //The pipeline can be used to transform the renderer in abstract ways
String vertex = ShaderLoader.parse("voxy:lod/gl46/quads2.vert"); String vertex = ShaderLoader.parse("voxy:lod/gl46/quads2.vert");
String taa = pipeline.taaFunction(this, "taaShift"); String taa = pipeline.taaFunction("taaShift");
if (taa != null) { if (taa != null) {
vertex += "\n"+taa;//inject it at the end vertex += "\n"+taa;//inject it at the end
} }

View File

@@ -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; 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() { void main() {
uint id = (gl_InstanceID<<5)+gl_BaseInstance+(gl_VertexID>>3); uint id = (gl_InstanceID<<5)+gl_BaseInstance+(gl_VertexID>>3);
@@ -38,4 +42,8 @@ void main() {
//cubeCornerI.y = cubeCornerI.y*1024-512; //cubeCornerI.y = cubeCornerI.y*1024-512;
gl_Position = MVP * vec4(vec3(cubeCornerI+origin)*16, 1); gl_Position = MVP * vec4(vec3(cubeCornerI+origin)*16, 1);
gl_Position.z -= 0.0005f; gl_Position.z -= 0.0005f;
#ifdef TAA
gl_Position.xy += getTAA()*gl_Position.w;//Apply TAA if we have it
#endif
} }