Remaining things for outline culling

This commit is contained in:
mcrcortex
2025-05-02 23:45:18 +10:00
parent fce99fbde3
commit 79cd18d310
3 changed files with 46 additions and 16 deletions

View File

@@ -55,7 +55,7 @@ public class AutoBindingShader extends Shader {
} }
public AutoBindingShader ssbo(int index, GlBuffer buffer, long offset) { public AutoBindingShader ssbo(int index, GlBuffer buffer, long offset) {
this.bindings.add(new BufferBinding(GL_SHADER_STORAGE_BUFFER, index, buffer, offset, -1)); this.insertOrReplaceBinding(new BufferBinding(GL_SHADER_STORAGE_BUFFER, index, buffer, offset, -1));
return this; return this;
} }
@@ -69,10 +69,23 @@ public class AutoBindingShader extends Shader {
} }
public AutoBindingShader ubo(int index, GlBuffer buffer, long offset) { public AutoBindingShader ubo(int index, GlBuffer buffer, long offset) {
this.bindings.add(new BufferBinding(GL_UNIFORM_BUFFER, index, buffer, offset, -1)); this.insertOrReplaceBinding(new BufferBinding(GL_UNIFORM_BUFFER, index, buffer, offset, -1));
return this; return this;
} }
private void insertOrReplaceBinding(BufferBinding binding) {
//Check if there is already a binding at the index with the target, if so, replace it
for (int i = 0; i < this.bindings.size(); i++) {
var entry = this.bindings.get(i);
if (entry.target == binding.target && entry.index == binding.index) {
this.bindings.set(i, binding);
return;
}
}
//Else add the new binding
this.bindings.add(binding);
}
public AutoBindingShader texture(String define, GlTexture texture) { public AutoBindingShader texture(String define, GlTexture texture) {
return this.texture(define, -1, texture); return this.texture(define, -1, texture);
@@ -92,6 +105,7 @@ public class AutoBindingShader extends Shader {
super.bind(); super.bind();
if (!this.bindings.isEmpty()) { if (!this.bindings.isEmpty()) {
for (var binding : this.bindings) { for (var binding : this.bindings) {
binding.buffer.assertNotFreed();
if (binding.offset == 0 && binding.size == -1) { if (binding.offset == 0 && binding.size == -1) {
glBindBufferBase(binding.target, binding.index, binding.buffer.id); glBindBufferBase(binding.target, binding.index, binding.buffer.id);
} else { } else {
@@ -102,6 +116,7 @@ public class AutoBindingShader extends Shader {
if (!this.textureBindings.isEmpty()) { if (!this.textureBindings.isEmpty()) {
for (var binding : this.textureBindings) { for (var binding : this.textureBindings) {
if (binding.texture != null) { if (binding.texture != null) {
binding.texture.assertNotFreed();
GlStateManager._activeTexture(GlConst.GL_TEXTURE0+binding.unit); GlStateManager._activeTexture(GlConst.GL_TEXTURE0+binding.unit);
GlStateManager._bindTexture(0); GlStateManager._bindTexture(0);
glBindTextureUnit(binding.unit, binding.texture.id); glBindTextureUnit(binding.unit, binding.texture.id);

View File

@@ -1,9 +1,6 @@
package me.cortex.voxy.client.mixin.sodium; package me.cortex.voxy.client.mixin.sodium;
import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import me.cortex.voxy.client.VoxyClientInstance; import me.cortex.voxy.client.VoxyClientInstance;
import me.cortex.voxy.client.config.VoxyConfig; import me.cortex.voxy.client.config.VoxyConfig;
import me.cortex.voxy.client.core.IGetVoxyRenderSystem; import me.cortex.voxy.client.core.IGetVoxyRenderSystem;
@@ -11,10 +8,12 @@ import me.cortex.voxy.client.core.VoxyRenderSystem;
import me.cortex.voxy.commonImpl.VoxyCommon; import me.cortex.voxy.commonImpl.VoxyCommon;
import net.caffeinemc.mods.sodium.client.gl.device.CommandList; import net.caffeinemc.mods.sodium.client.gl.device.CommandList;
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSection; import net.caffeinemc.mods.sodium.client.render.chunk.RenderSection;
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionFlags;
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionManager; import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionManager;
import net.caffeinemc.mods.sodium.client.render.chunk.data.BuiltSectionInfo; import net.caffeinemc.mods.sodium.client.render.chunk.data.BuiltSectionInfo;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.ChunkSectionPos;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@@ -48,15 +47,16 @@ public class MixinRenderSectionManager {
} }
}*/ }*/
/*
@Inject(method = "onChunkRemoved", at = @At("HEAD")) @Inject(method = "onChunkRemoved", at = @At("HEAD"))
private void voxy$trackChunkRemove(int x, int z, CallbackInfo ci) { private void voxy$trackChunkRemove(int x, int z, CallbackInfo ci) {
if (this.level.worldRenderer != null) { if (this.level.worldRenderer != null) {
var system = ((IGetVoxyRenderSystem)(this.level.worldRenderer)).getVoxyRenderSystem(); var system = ((IGetVoxyRenderSystem)(this.level.worldRenderer)).getVoxyRenderSystem();
if (system != null) { if (system != null) {
system.chunkBoundRenderer.removeChunk(ChunkPos.toLong(x, z)); system.chunkBoundRenderer.removeSection(ChunkPos.toLong(x, z));
} }
} }
} }*/
@Inject(method = "onChunkRemoved", at = @At("HEAD")) @Inject(method = "onChunkRemoved", at = @At("HEAD"))
private void injectIngest(int x, int z, CallbackInfo ci) { private void injectIngest(int x, int z, CallbackInfo ci) {
@@ -76,16 +76,27 @@ public class MixinRenderSectionManager {
@Redirect(method = "updateSectionInfo", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/RenderSection;setInfo(Lnet/caffeinemc/mods/sodium/client/render/chunk/data/BuiltSectionInfo;)Z")) @Redirect(method = "updateSectionInfo", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/RenderSection;setInfo(Lnet/caffeinemc/mods/sodium/client/render/chunk/data/BuiltSectionInfo;)Z"))
private boolean voxy$updateOnUpload(RenderSection instance, BuiltSectionInfo info) { private boolean voxy$updateOnUpload(RenderSection instance, BuiltSectionInfo info) {
boolean retVal = instance.setInfo(info); boolean wasBuilt = instance.isBuilt();
if (!retVal) { int flags = instance.getFlags();
if (!instance.setInfo(info)) {
return false; return false;
} }
if (info == null || info == BuiltSectionInfo.EMPTY) { if (wasBuilt == instance.isBuilt()) {//Only want to do stuff on change
return true; return true;
} }
flags |= instance.getFlags();
if (flags == 0)//Only process things with stuff
return true;
VoxyRenderSystem system = ((IGetVoxyRenderSystem)(this.level.worldRenderer)).getVoxyRenderSystem(); VoxyRenderSystem system = ((IGetVoxyRenderSystem)(this.level.worldRenderer)).getVoxyRenderSystem();
if (system != null) { if (system == null) {
system.chunkBoundRenderer.addChunk(ChunkPos.toLong(instance.getChunkX(), instance.getChunkZ())); return true;
}
long pos = ChunkSectionPos.asLong(instance.getChunkX(), instance.getChunkY(), instance.getChunkZ());
if (wasBuilt) {//Remove
system.chunkBoundRenderer.removeSection(pos);
} else {//Add
system.chunkBoundRenderer.addSection(pos);
} }
return true; return true;
} }
@@ -95,6 +106,6 @@ public class MixinRenderSectionManager {
if (((IGetVoxyRenderSystem)(this.level.worldRenderer)).getVoxyRenderSystem() == null) { if (((IGetVoxyRenderSystem)(this.level.worldRenderer)).getVoxyRenderSystem() == null) {
return searchDistance; return searchDistance;
} }
return searchDistance + 20; return searchDistance + 32;
} }
} }

View File

@@ -10,16 +10,20 @@ layout(binding = 1, std430) restrict readonly buffer ChunkPosBuffer {
ivec2[] chunkPos; ivec2[] chunkPos;
}; };
ivec3 unpackPos(ivec2 pos) {
return ivec3(pos.y>>10, (pos.x<<12)>>12, ((pos.y<<22)|int(uint(pos.x)>>10))>>10);
}
void main() { void main() {
uint id = (gl_InstanceID<<5)+gl_BaseInstance+(gl_VertexID>>3); uint id = (gl_InstanceID<<5)+gl_BaseInstance+(gl_VertexID>>3);
ivec3 origin = ivec3(chunkPos[id], 0).xzy; ivec3 origin = unpackPos(chunkPos[id]);
origin -= section.xyz; origin -= section.xyz;
ivec3 cubeCornerI = ivec3(gl_VertexID&1, (gl_VertexID>>2)&1, (gl_VertexID>>1)&1); ivec3 cubeCornerI = ivec3(gl_VertexID&1, (gl_VertexID>>2)&1, (gl_VertexID>>1)&1);
//Expand the y height to be big (will be +- 8192) //Expand the y height to be big (will be +- 8192)
//TODO: make it W.R.T world height and offsets //TODO: make it W.R.T world height and offsets
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.0001f; gl_Position.z -= 0.0005f;
} }