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); var selection = selector.getBestSelectionOrCreate(world);
return new VoxelCore(selection); 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 y = ((light>>4)&0xF);
int sample = lmt.getColor(x,y); int sample = lmt.getColor(x,y);
sample = ((sample&0xFF0000)>>16)|(sample&0xFF00)|((sample&0xFF)<<16); 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.copyDataTo(this.connectedSectionCache);
connectedSection.release(); connectedSection.release();
} else { } else {
Arrays.fill(this.connectedSectionCache, Mapper.withLight(Mapper.AIR, 15)); Arrays.fill(this.connectedSectionCache, 0);
} }
obtainedOppositeSection0 = true; obtainedOppositeSection0 = true;
} }
@@ -396,7 +396,7 @@ public class RenderDataFactory {
connectedSection.copyDataTo(this.connectedSectionCache); connectedSection.copyDataTo(this.connectedSectionCache);
connectedSection.release(); connectedSection.release();
} else { } else {
Arrays.fill(this.connectedSectionCache, Mapper.withLight(Mapper.AIR, 15)); Arrays.fill(this.connectedSectionCache, 0);
} }
obtainedOppositeSection31 = true; obtainedOppositeSection31 = true;
} }

View File

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

View File

@@ -328,7 +328,6 @@ public class WorldImporter {
if (skyLight != null) { if (skyLight != null) {
sky = skyLight.get(bx, by, bz); sky = skyLight.get(bx, by, bz);
} }
sky = 15-sky;
return (byte) (sky|(block<<4)); 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 //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) { if (status == 1) {
//We need to set the data to air as it is undefined state //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(); section.acquire();
holder.obj = section; holder.obj = section;

View File

@@ -1,5 +1,6 @@
package me.cortex.voxy.common.world; package me.cortex.voxy.common.world;
import me.cortex.voxy.client.Voxy;
import me.cortex.voxy.common.voxelization.VoxelizedSection; import me.cortex.voxy.common.voxelization.VoxelizedSection;
import me.cortex.voxy.common.world.other.Mapper; import me.cortex.voxy.common.world.other.Mapper;
import me.cortex.voxy.common.world.service.SectionSavingService; import me.cortex.voxy.common.world.service.SectionSavingService;
@@ -131,6 +132,10 @@ public class WorldEngine {
long oldId = worldSection.set(x, y, z, newId); long oldId = worldSection.set(x, y, z, newId);
nonAirCountDelta += Mapper.isAir(oldId)==Mapper.isAir(newId)?0:(Mapper.isAir(newId)?-1:1 ); nonAirCountDelta += Mapper.isAir(oldId)==Mapper.isAir(newId)?0:(Mapper.isAir(newId)?-1:1 );
didChange |= newId != oldId; 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; long[] data = null;
//Computed on load, updated on insertion
private final AtomicInteger nonAirCount = new AtomicInteger(0);
private final ActiveSectionTracker tracker; private final ActiveSectionTracker tracker;
public final AtomicBoolean inSaveQueue = new AtomicBoolean(); public final AtomicBoolean inSaveQueue = new AtomicBoolean();

View File

@@ -1,6 +1,7 @@
package me.cortex.voxy.common.world.service; package me.cortex.voxy.common.world.service;
import it.unimi.dsi.fastutil.Pair; 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.VoxelizedSection;
import me.cortex.voxy.common.voxelization.WorldConversionFactory; import me.cortex.voxy.common.voxelization.WorldConversionFactory;
import me.cortex.voxy.common.world.WorldEngine; import me.cortex.voxy.common.world.WorldEngine;
@@ -37,7 +38,7 @@ public class VoxelIngestService {
for (var section : chunk.getSectionArray()) { for (var section : chunk.getSectionArray()) {
i++; i++;
var lighting = this.captureLightMap.remove(ChunkSectionPos.from(chunk.getPos(), i).asLong()); 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 //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)); this.world.insertUpdate(VoxelizedSection.createEmpty().setPosition(chunk.getPos().x, i, chunk.getPos().z));
} else { } else {
@@ -48,7 +49,7 @@ public class VoxelIngestService {
section.getBiomeContainer(), section.getBiomeContainer(),
(x, y, z, state) -> { (x, y, z, state) -> {
if (lighting == null || ((lighting.first() != null && lighting.first().isUninitialized())&&(lighting.second()!=null&&lighting.second().isUninitialized()))) { if (lighting == null || ((lighting.first() != null && lighting.first().isUninitialized())&&(lighting.second()!=null&&lighting.second().isUninitialized()))) {
return (byte) 0x0f; return (byte) 0;
} else { } else {
//Lighting is hell //Lighting is hell
int block = lighting.first()!=null?Math.min(15,lighting.first().get(x, y, z)):0; 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()) { if (block<state.getLuminance()) {
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)); return (byte) (sky|(block<<4));
} }
} }
@@ -76,7 +76,7 @@ public class VoxelIngestService {
for (var section : chunk.getSectionArray()) { for (var section : chunk.getSectionArray()) {
i++; i++;
if (section == null) continue; if (section == null) continue;
if (section.isEmpty()) continue; //if (section.isEmpty()) continue;
var pos = ChunkSectionPos.from(chunk.getPos(), i); var pos = ChunkSectionPos.from(chunk.getPos(), i);
var bl = blp.getLightSection(pos); var bl = blp.getLightSection(pos);
if (!(bl == null || bl.isUninitialized())) { if (!(bl == null || bl.isUninitialized())) {