Skip to content

Commit

Permalink
holy shit it's working wtf
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Feb 13, 2025
1 parent 90938ac commit 4630bb3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.util.profiling.Profiler;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
Expand Down Expand Up @@ -116,14 +117,18 @@ public ChunkBuildOutput execute(ChunkBuildContext buildContext, CancellationToke
for (int z = minZ; z < maxZ; z++) {
for (int x = minX; x < maxX; x++) {
BlockState blockState = slice.getBlockState(x, y, z);
blockPos.set(x, y, z);

if (blockState.isAir() && !blockState.hasBlockEntity()) {
MemoryUtil.memPutInt(addr + (to1D(x & 15, y & 15, z & 15) * 8), 0);
MemoryUtil.memPutInt(addr + (to1D(x & 15, y & 15, z & 15) * 8) + 4, cache.getWorldSlice().getBrightness(LightLayer.SKY, blockPos));

continue;
}

blockPos.set(x, y, z);
modelOffset.set(x & 15, y & 15, z & 15);
MemoryUtil.memPutInt(addr + (to1D(x & 15, y & 15, z & 15) * Integer.BYTES), 1);
MemoryUtil.memPutInt(addr + (to1D(x & 15, y & 15, z & 15) * 8), 1);
MemoryUtil.memPutInt(addr + (to1D(x & 15, y & 15, z & 15) * 8) + 4, cache.getWorldSlice().getBrightness(LightLayer.SKY, blockPos));

if (blockState.getRenderShape() == RenderShape.MODEL) {
BakedModel model = cache.getBlockModels()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class RenderRegionManager {

private final StagingBuffer stagingBuffer;
private final GlBufferArena voxelArena;
private PendingSectionVoxelUpload upcomingUpload;

public RenderRegionManager(CommandList commandList) {
this.stagingBuffer = createStagingBuffer(commandList);
Expand Down Expand Up @@ -66,6 +67,26 @@ public void update() {
}
}
}

if (this.upcomingUpload != null) {
PendingSectionVoxelUpload upload = this.upcomingUpload;
this.upcomingUpload = null;
GL46C.glFinish();
System.out.println("Chunk " + upload.section.toString());
long addr = MemoryUtil.nmemAlloc(32768);
GL46C.nglGetNamedBufferSubData(voxelArena.getBufferObject().handle(), upload.upload.getResult().getOffset() * 32768, 32768, addr);
GL46C.glFinish();
DefaultShaderInterface.VOXEL = (int) (upload.upload.getResult().getOffset());
for (int x = 0; x < 4096; x++) {
boolean hasBlock = MemoryUtil.memGetInt(addr + (x * 8)) != 0;
int[] v = to3D(x);
if (!hasBlock) {
System.out.println("Block " + (upload.section.getOriginX() + v[0]) + ", " + (upload.section.getOriginY() + v[1]) + ", " + (upload.section.getOriginZ() + v[2]) + " is missing");
} else {
System.out.println("Block " + (upload.section.getOriginX() + v[0]) + ", " + (upload.section.getOriginY() + v[1]) + ", " + (upload.section.getOriginZ() + v[2]) + " exists");
}
}
}
}

public void uploadResults(CommandList commandList, Collection<BuilderTaskOutput> results) {
Expand Down Expand Up @@ -173,15 +194,7 @@ private void uploadResults(CommandList commandList, RenderRegion region, Collect
// Collect the upload results
for (PendingSectionVoxelUpload upload : voxelUpload) {
if (SectionPos.of(Minecraft.getInstance().player.blockPosition()).equals(SectionPos.of(upload.section.getChunkX(), upload.section.getChunkY(), upload.section.getChunkZ()))) {
System.out.println("Chunk " + upload.section.toString());
DefaultShaderInterface.VOXEL = (int) upload.upload.getResult().getOffset();
for (int x = 0; x < 4096; x++) {
boolean hasBlock = MemoryUtil.memGetInt(upload.data.getAddress() + (x * 4)) != 0;
if (!hasBlock) {
int[] v = to3D(x);
System.out.println("Block " + (upload.section.getOriginX() + v[0]) + ", " + (upload.section.getOriginY() + v[1]) + ", " + (upload.section.getOriginZ() + v[2]) + " is missing");
}
}
this.upcomingUpload = upload;
}

upload.section.setVoxelOffset(upload.upload.getResult().getOffset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#import <sodium:include/fog.glsl>

struct Chunk {
uint blocks[4096];
uvec2 blocks[4096];
};

layout(binding = 8, std430) buffer Voxels {
Expand Down Expand Up @@ -43,8 +43,8 @@ void main() {
}
#endif

if (ids[u_Test].blocks[to1D(11, 15, 5)] == 0u) {
fragColor = diffuseColor.rrra;
if (ids[u_Test].blocks[to1D(10, 4, 3)].y > 10u) {
fragColor = v_Color;
} else {

fragColor = _linearFog(diffuseColor, v_FragDistance, u_FogColor, u_FogStart, u_FogEnd);
Expand Down

0 comments on commit 4630bb3

Please sign in to comment.