Attempt to improve lighting

This commit is contained in:
mcrcortex
2024-08-08 00:40:17 +10:00
parent f536b0cd74
commit d2483283f5
9 changed files with 19 additions and 15 deletions

View File

@@ -35,4 +35,8 @@ public class Voxy implements ClientModInitializer {
var selection = selector.getBestSelectionOrCreate(world);
return new VoxelCore(selection);
}
public static void breakpoint() {
int breakpoint = 0;
}
}

View File

@@ -18,7 +18,7 @@ public class LightMapHelper {
int y = ((light>>4)&0xF);
int sample = lmt.getColor(x,y);
sample = ((sample&0xFF0000)>>16)|(sample&0xFF00)|((sample&0xFF)<<16);
MemoryUtil.memPutInt(upload + (((x<<4)|(15-y))*4), sample|(0xFF<<28));//Skylight is inverted
MemoryUtil.memPutInt(upload + (((x<<4)|(y))*4), sample|(0xFF<<28));
}
}

View File

@@ -368,7 +368,7 @@ public class RenderDataFactory {
connectedSection.copyDataTo(this.connectedSectionCache);
connectedSection.release();
} else {
Arrays.fill(this.connectedSectionCache, Mapper.withLight(Mapper.AIR, 15));
Arrays.fill(this.connectedSectionCache, 0);
}
obtainedOppositeSection0 = true;
}
@@ -396,7 +396,7 @@ public class RenderDataFactory {
connectedSection.copyDataTo(this.connectedSectionCache);
connectedSection.release();
} else {
Arrays.fill(this.connectedSectionCache, Mapper.withLight(Mapper.AIR, 15));
Arrays.fill(this.connectedSectionCache, 0);
}
obtainedOppositeSection31 = true;
}

View File

@@ -40,8 +40,8 @@ public class HierarchicalNodeManager {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
for(int x = -100; x<=100;x++) {
for (int z = -100; z <= 100; z++) {
for(int x = -50; x<=50;x++) {
for (int z = -50; z <= 50; z++) {
for (int y = -3; y <= 3; y++) {
updateFilterer.watch(0,x,y,z);
updateFilterer.unwatch(0,x,y,z);

View File

@@ -328,7 +328,6 @@ public class WorldImporter {
if (skyLight != null) {
sky = skyLight.get(bx, by, bz);
}
sky = 15-sky;
return (byte) (sky|(block<<4));
}
);

View File

@@ -66,7 +66,7 @@ public class ActiveSectionTracker {
//TODO: REWRITE THE section tracker _again_ to not be so shit and jank, and so that Arrays.fill is not 10% of the execution time
if (status == 1) {
//We need to set the data to air as it is undefined state
Arrays.fill(section.data, 0);//Max skylight
Arrays.fill(section.data, 0);
}
section.acquire();
holder.obj = section;

View File

@@ -1,5 +1,6 @@
package me.cortex.voxy.common.world;
import me.cortex.voxy.client.Voxy;
import me.cortex.voxy.common.voxelization.VoxelizedSection;
import me.cortex.voxy.common.world.other.Mapper;
import me.cortex.voxy.common.world.service.SectionSavingService;
@@ -131,6 +132,10 @@ public class WorldEngine {
long oldId = worldSection.set(x, y, z, newId);
nonAirCountDelta += Mapper.isAir(oldId)==Mapper.isAir(newId)?0:(Mapper.isAir(newId)?-1:1 );
didChange |= newId != oldId;
/*
if (oldId != newId && Mapper.isAir(oldId) && Mapper.isAir(newId)) {
Voxy.breakpoint();
}*/
}
}
}

View File

@@ -29,10 +29,6 @@ public final class WorldSection {
long[] data = null;
//Computed on load, updated on insertion
private final AtomicInteger nonAirCount = new AtomicInteger(0);
private final ActiveSectionTracker tracker;
public final AtomicBoolean inSaveQueue = new AtomicBoolean();

View File

@@ -1,6 +1,7 @@
package me.cortex.voxy.common.world.service;
import it.unimi.dsi.fastutil.Pair;
import me.cortex.voxy.client.Voxy;
import me.cortex.voxy.common.voxelization.VoxelizedSection;
import me.cortex.voxy.common.voxelization.WorldConversionFactory;
import me.cortex.voxy.common.world.WorldEngine;
@@ -37,7 +38,7 @@ public class VoxelIngestService {
for (var section : chunk.getSectionArray()) {
i++;
var lighting = this.captureLightMap.remove(ChunkSectionPos.from(chunk.getPos(), i).asLong());
if (section.isEmpty()) {
if (section.isEmpty() && lighting==null) {//If the chunk section has lighting data, propagate it
//TODO: add local cache so that it doesnt constantly create new sections
this.world.insertUpdate(VoxelizedSection.createEmpty().setPosition(chunk.getPos().x, i, chunk.getPos().z));
} else {
@@ -48,7 +49,7 @@ public class VoxelIngestService {
section.getBiomeContainer(),
(x, y, z, state) -> {
if (lighting == null || ((lighting.first() != null && lighting.first().isUninitialized())&&(lighting.second()!=null&&lighting.second().isUninitialized()))) {
return (byte) 0x0f;
return (byte) 0;
} else {
//Lighting is hell
int block = lighting.first()!=null?Math.min(15,lighting.first().get(x, y, z)):0;
@@ -56,7 +57,6 @@ public class VoxelIngestService {
if (block<state.getLuminance()) {
block = state.getLuminance();
}
sky = 15-sky;//This is cause sky light is inverted which saves memory when saving empty sections
return (byte) (sky|(block<<4));
}
}
@@ -76,7 +76,7 @@ public class VoxelIngestService {
for (var section : chunk.getSectionArray()) {
i++;
if (section == null) continue;
if (section.isEmpty()) continue;
//if (section.isEmpty()) continue;
var pos = ChunkSectionPos.from(chunk.getPos(), i);
var bl = blp.getLightSection(pos);
if (!(bl == null || bl.isUninitialized())) {