rasterized occlusion culling #38

Merged
embeddedt merged 20 commits from rdh/celeritas:raster into stonecutter 2026-09-04 22:15:05 -04:00
8 changed files with 775 additions and 1 deletions
Showing only changes of commit 852bfb8d8d - Show all commits

No files matched your search

@@ -76,6 +76,8 @@ public class SodiumGameOptions implements OptionStorage<SodiumGameOptions> {
public boolean useNoErrorGLContext = true;
public AsyncOcclusionMode asyncOcclusionMode = AsyncOcclusionMode.ONLY_SHADOW;
public boolean useRasterOcclusionCulling = false;
}
public static class AdvancedSettings {
@@ -157,6 +157,16 @@ public class CommonOptionPages {
.setBinding((opts, value) -> opts.performance.useFasterClouds = value, opts -> opts.performance.useFasterClouds)
.build())
//?}
.add(OptionImpl.createBuilder(boolean.class, sodiumOpts)
.setId(StandardOptions.Option.RASTER_OCCLUSION_CULLING.cast())
.setName(TextComponent.translatable("celeritas.options.raster_occlusion_culling.name"))
.setTooltip(TextComponent.translatable("celeritas.options.raster_occlusion_culling.tooltip"))
.setControl(TickBoxControl::new)
.setImpact(OptionImpact.VARIES)
.setBinding((opts, value) -> opts.performance.useRasterOcclusionCulling = value, opts -> opts.performance.useRasterOcclusionCulling)
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
.build()
)
.build());
return new OptionPage(StandardOptions.Pages.PERFORMANCE, TextComponent.translatable("sodium.options.pages.performance"), List.copyOf(groups));
@@ -0,0 +1,220 @@
/*
* Ported from Canvas (https://github.com/vram-guild/canvas), Copyright 2019, 2020 grondag.
* Licensed under the GNU Lesser General Public License v3.0.
*/
package org.embeddedt.embeddium.impl.render.chunk.occlusion.geometry;
import it.unimi.dsi.fastutil.ints.AbstractIntComparator;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntArrays;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
public class Area {
public static final int AREA_COUNT;
public static final int SECTION_COUNT;
private static final int[] AREA_KEY_TO_INDEX = new int[0x10000];
private static final int[] AREA_INDEX_TO_KEY;
private static final int[] SECTION_KEYS;
private static final int[] SECTION_INDEX;
private static final long[] AREA_BITS;
static {
final IntOpenHashSet areas = new IntOpenHashSet();
areas.add(Area.areaKey(0, 0, 15, 15));
areas.add(Area.areaKey(1, 0, 15, 15));
areas.add(Area.areaKey(0, 0, 14, 15));
areas.add(Area.areaKey(0, 1, 15, 15));
areas.add(Area.areaKey(0, 0, 15, 14));
for (int x0 = 0; x0 <= 15; x0++) {
for (int x1 = x0; x1 <= 15; x1++) {
for (int y0 = 0; y0 <= 15; y0++) {
for (int y1 = y0; y1 <= 15; y1++) {
areas.add(Area.areaKey(x0, y0, x1, y1));
}
}
}
}
AREA_COUNT = areas.size();
AREA_INDEX_TO_KEY = new int[AREA_COUNT];
AREA_BITS = new long[AREA_COUNT * 4];
int i = 0;
for (final int k : areas) {
AREA_INDEX_TO_KEY[i++] = k;
}
IntArrays.quickSort(AREA_INDEX_TO_KEY, new AbstractIntComparator() {
@Override
public int compare(int a, int b) {
final int result = Integer.compare(Area.size(b), Area.size(a));
// within same area size, prefer more compact rectangles
return result == 0 ? Integer.compare(Area.edgeCount(a), Area.edgeCount(b)) : result;
}
});
for (int j = 0; j < AREA_COUNT; j++) {
AREA_KEY_TO_INDEX[AREA_INDEX_TO_KEY[j]] = j;
}
final IntArrayList sections = new IntArrayList();
for (int j = 0; j < AREA_COUNT; ++j) {
final int a = AREA_INDEX_TO_KEY[j];
if ((Area.x0(a) == 0 && Area.x1(a) == 15) || (Area.y0(a) == 0 && Area.y1(a) == 15)) {
sections.add(indexToKey(j));
}
}
SECTION_COUNT = sections.size();
SECTION_KEYS = sections.toArray(new int[SECTION_COUNT]);
SECTION_INDEX = new int[SECTION_COUNT];
for (int k = 0; k < SECTION_COUNT; ++k) {
SECTION_INDEX[k] = keyToIndex(SECTION_KEYS[k]);
}
final long[] xMasks = new long[256];
final int[] yBits = new int[256];
final long[] yMasks = new long[16];
for (int x0 = 0; x0 <= 15; ++x0) {
for (int x1 = x0; x1 <= 15; ++x1) {
final long template = (0xFFFF << x0) & (0xFFFF >> (15 - x1));
xMasks[x0 | (x1 << 4)] = template | (template << 16) | (template << 32) | (template << 48);
}
}
for (int y0 = 0; y0 <= 15; ++y0) {
for (int y1 = y0; y1 <= 15; ++y1) {
yBits[y0 | (y1 << 4)] = (0xFFFF << y0) & (0xFFFF >> (15 - y1));
}
}
yMasks[0b0000] = 0L;
yMasks[0b0001] = 0x000000000000FFFFL;
yMasks[0b0010] = 0x00000000FFFF0000L;
yMasks[0b0100] = 0x0000FFFF00000000L;
yMasks[0b1000] = 0xFFFF000000000000L;
yMasks[0b0011] = 0x00000000FFFFFFFFL;
yMasks[0b0110] = 0x0000FFFFFFFF0000L;
yMasks[0b1100] = 0xFFFFFFFF00000000L;
yMasks[0b0111] = 0x0000FFFFFFFFFFFFL;
yMasks[0b1110] = 0xFFFFFFFFFFFF0000L;
yMasks[0b1111] = 0xFFFFFFFFFFFFFFFFL;
int j = 0;
for (int areaIndex = 0; areaIndex < AREA_COUNT; ++areaIndex) {
final int areaKey = indexToKey(areaIndex);
AREA_BITS[j++] = yMasks[(yBits[areaKey >> 8] >> (0 << 2)) & 0xF] & xMasks[areaKey & 0xFF];
AREA_BITS[j++] = yMasks[(yBits[areaKey >> 8] >> (1 << 2)) & 0xF] & xMasks[areaKey & 0xFF];
AREA_BITS[j++] = yMasks[(yBits[areaKey >> 8] >> (2 << 2)) & 0xF] & xMasks[areaKey & 0xFF];
AREA_BITS[j++] = yMasks[(yBits[areaKey >> 8] >> (3 << 2)) & 0xF] & xMasks[areaKey & 0xFF];
}
}
public static int keyToIndex(int key) {
return AREA_KEY_TO_INDEX[key];
}
public static int indexToKey(int index) {
return AREA_INDEX_TO_KEY[index];
}
public static int sectionToAreaIndex(int sectionIndex) {
return SECTION_INDEX[sectionIndex];
}
public static boolean isIncludedBySample(long[] sample, int sampleStart, int areaIndex) {
areaIndex <<= 2;
final long template = AREA_BITS[areaIndex];
final long template1 = AREA_BITS[++areaIndex];
final long template2 = AREA_BITS[++areaIndex];
final long template3 = AREA_BITS[++areaIndex];
return (template & sample[sampleStart]) == template
&& (template1 & sample[sampleStart + 1]) == template1
&& (template2 & sample[sampleStart + 2]) == template2
&& (template3 & sample[sampleStart + 3]) == template3;
}
public static boolean intersectsWithSample(long[] sample, int sampleStart, int areaIndex) {
areaIndex <<= 2;
return (AREA_BITS[areaIndex] & sample[sampleStart]) != 0
|| (AREA_BITS[++areaIndex] & sample[++sampleStart]) != 0
|| (AREA_BITS[++areaIndex] & sample[++sampleStart]) != 0
|| (AREA_BITS[++areaIndex] & sample[++sampleStart]) != 0;
}
public static boolean isAdditive(long[] sample, int sampleStart, int areaIndex) {
areaIndex <<= 2;
return (AREA_BITS[areaIndex] | sample[sampleStart]) != sample[sampleStart]
|| (AREA_BITS[++areaIndex] | sample[++sampleStart]) != sample[sampleStart]
|| (AREA_BITS[++areaIndex] | sample[++sampleStart]) != sample[sampleStart]
|| (AREA_BITS[++areaIndex] | sample[++sampleStart]) != sample[sampleStart];
}
public static void clearBits(long[] targetBits, int startIndex, int areaIndex) {
areaIndex <<= 2;
targetBits[startIndex] &= ~AREA_BITS[areaIndex];
targetBits[++startIndex] &= ~AREA_BITS[++areaIndex];
targetBits[++startIndex] &= ~AREA_BITS[++areaIndex];
targetBits[++startIndex] &= ~AREA_BITS[++areaIndex];
}
public static long bitsFromIndex(int areaIndex, int y) {
return AREA_BITS[(areaIndex << 2) + y];
}
public static int areaKey(int x0, int y0, int x1, int y1) {
return x0 | (x1 << 4) | (y0 << 8) | (y1 << 12);
}
public static int x0(int areaKey) {
return areaKey & 15;
}
public static int y0(int areaKey) {
return (areaKey >> 8) & 15;
}
public static int x1(int areaKey) {
return (areaKey >> 4) & 15;
}
public static int y1(int areaKey) {
return (areaKey >> 12) & 15;
}
public static int size(int areaKey) {
final int x0 = x0(areaKey);
final int y0 = y0(areaKey);
final int x1 = x1(areaKey);
final int y1 = y1(areaKey);
return (x1 - x0 + 1) * (y1 - y0 + 1);
}
public static int edgeCount(int areaKey) {
final int x0 = x0(areaKey);
final int y0 = y0(areaKey);
final int x1 = x1(areaKey);
final int y1 = y1(areaKey);
final int x = x1 - x0 + 1;
final int y = y1 - y0 + 1;
return x + y;
}
}
@@ -0,0 +1,183 @@
/*
* Ported from Canvas (https://github.com/vram-guild/canvas), Copyright 2019, 2020 grondag.
* Licensed under the GNU Lesser General Public License v3.0.
*/
package org.embeddedt.embeddium.impl.render.chunk.occlusion.geometry;
import java.util.function.IntConsumer;
public class AreaFinder {
final long[] bits = new long[4];
// based on approach described here:
// https://stackoverflow.com/a/7497967
// https://stackoverflow.com/a/7773870
// https://www.drdobbs.com/database/the-maximal-rectangle-problem/184410529
public static int findLargest(long[] bitsIn) {
int bestX0 = 0;
int bestY0 = 0;
int bestX1 = -1;
int bestY1 = -1;
int bestArea = 0;
// height of prior rows
// four bits per position, values 0-15
long heights = 0;
for (int y = 0; y < 16; ++y) {
final int rowBits = (int) ((bitsIn[y >> 2] >> ((y & 3) << 4)) & 0xFFFF);
if (rowBits == 0) {
heights = 0;
continue;
}
// track start of runs up to current height
long stackX15 = 0; // 0-15
long stackH16 = 0; // 1-16
int stackSize = 0;
// height of first column is zero if closed, otherwise 1 + previous row first column height
int runHeight = (rowBits & 1) == 0 ? 0 : (1 + getVal15(heights, 0));
int runStart = 0;
// save height for use by next row, unless at top row
if (y != 15) heights = setVal15(heights, 0, runHeight);
// NB: inclusive of 16. The height @ 16 will always be zero, closing off last column
for (int x = 1; x <= 16; ++x) {
// height here is 0 if closed, otherwise 1 + height of row below
final int h = (rowBits & (1 << x)) == 0 ? 0 : (1 + getVal15(heights, x));
// if higher than last start new run
if (h > runHeight) {
// push current run onto stack
if (runHeight != 0) {
stackX15 = setVal15(stackX15, stackSize, runStart);
stackH16 = setVal16(stackH16, stackSize, runHeight);
++stackSize;
}
// new run starts here
runStart = x;
runHeight = h;
} else {
// if reduction in height, close out current run and
// also runs on stack until revert to a sustainable run
// or the stack is empty
while (h < runHeight) {
// check for largest area on current run
final int a = (x - runStart) * runHeight;
if (a > bestArea) {
bestArea = a;
bestX0 = runStart;
bestX1 = x - 1;
bestY0 = y - runHeight + 1;
bestY1 = y;
}
if (stackSize == 0) {
// if we have an empty stack but non-zero height,
// then run at current height effectively starts
// where the just-closed prior run started
runHeight = h;
// NB: no change to run start - continue from prior
} else { // stackSize > 0
--stackSize;
final int stackStart = getVal15(stackX15, stackSize);
final int stackHeight = getVal16(stackH16, stackSize);
if (stackHeight == h) {
// if stack run height is same as current, resume run, leave stack popped
runHeight = h;
runStart = stackStart;
} else if (stackHeight < h) {
// if stack run height is less new height, leave on the stack
++stackSize;
// and new run starts from current position
runHeight = h;
// NB: no change to run start - continue from prior
} else {
// stack area is higher than new height
// leave stack popped and loop to close out area on the stack
runHeight = stackHeight;
runStart = stackStart;
}
}
}
}
// track height of this column but don't overflow on last row/column
if (y != 15 && x < 16) heights = setVal15(heights, x, h);
}
}
return Area.areaKey(bestX0, bestY0, bestX1, bestY1);
}
private static int getVal16(long packed, int x) {
return 1 + getVal15(packed, x);
}
private static long setVal16(long packed, int x, int val) {
return setVal15(packed, x, val - 1);
}
private static int getVal15(long packed, int x) {
return (int) ((packed >>> (x << 2)) & 0xF);
}
private static long setVal15(long packed, int x, int val) {
final int shift = x << 2;
final long mask = 0xFL << shift;
return (packed & ~mask) | (((long) val) << shift);
}
public long[] bitsFromIndex(int areaIndex) {
final long[] result = bits;
result[0] = Area.bitsFromIndex(areaIndex, 0);
result[1] = Area.bitsFromIndex(areaIndex, 1);
result[2] = Area.bitsFromIndex(areaIndex, 2);
result[3] = Area.bitsFromIndex(areaIndex, 3);
return result;
}
public void find(long[] bitsIn, int sourceIndex, IntConsumer areaIndexConsumer) {
final long[] bits = this.bits;
System.arraycopy(bitsIn, sourceIndex, bits, 0, 4);
int bitCount = Long.bitCount(bits[0]) + Long.bitCount(bits[1]) + Long.bitCount(bits[2]) + Long.bitCount(bits[3]);
while (bitCount > 0) {
final int key = findLargest(bits);
final int index = Area.keyToIndex(key);
areaIndexConsumer.accept(index);
Area.clearBits(bits, 0, index);
bitCount -= Area.size(key);
}
}
public void findSections(long[] bitsIn, int sourceIndex, IntConsumer areaIndexConsumer) {
final long[] bits = this.bits;
System.arraycopy(bitsIn, sourceIndex, bits, 0, 4);
final int bitCount = Long.bitCount(bits[0]) + Long.bitCount(bits[1]) + Long.bitCount(bits[2]) + Long.bitCount(bits[3]);
if (bitCount == 0) {
return;
}
for (int i = 0; i < Area.SECTION_COUNT; ++i) {
final int areaIndex = Area.sectionToAreaIndex(i);
if (Area.isIncludedBySample(bits, 0, areaIndex)) {
areaIndexConsumer.accept(areaIndex);
}
}
}
}
@@ -0,0 +1,354 @@
/*
* Adapted from Canvas (https://github.com/vram-guild/canvas), Copyright 2019, 2020 grondag.
* Licensed under the GNU Lesser General Public License v3.0.
*/
package org.embeddedt.embeddium.impl.render.chunk.occlusion.geometry;
import grondag.bitraster.PackedBox;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import java.util.Arrays;
import java.util.function.IntConsumer;
/**
* Decomposes a section's opaque voxels into disjoint occluder boxes. Input is 64 longs of occupancy
* for a 16x16x16 section.
*
* <p>Rectangles are found in the low two axes of the index and extended along the high one, so a
* caller with a different axis order permutes the resulting {@link PackedBox} instead of the input.
*
* <p>Boxes never cover a voxel the source left clear, but may leave some covered voxels out: two
* passes run and any residue is dropped. That costs culling, never correctness.
*/
public class BoxFinder {
/** One bit per voxel of a 16x16x16 section. */
public static final int INTERIOR_CACHE_WORDS = 64;
public static final int SLICE_WORD_COUNT = 4;
public final IntArrayList boxes = new IntArrayList();
public final AreaFinder areaFinder;
final long[] source = new long[INTERIOR_CACHE_WORDS];
final long[] filled = new long[INTERIOR_CACHE_WORDS];
/**
* Bits 0-15 indicate which slices contain the area with the same index of the value.
*/
final int[] areaSlices = new int[Area.AREA_COUNT];
private final LongArrayList sortedBoxes = new LongArrayList();
int mask;
private final IntConsumer markSliceConsumer = areaIndex -> areaSlices[areaIndex] |= mask;
private int voxelCount;
public BoxFinder(AreaFinder areaFinder) {
this.areaFinder = areaFinder;
}
public void findBoxes(long[] sourceBits, int sourceIndex) {
Arrays.fill(filled, 0L);
System.arraycopy(sourceBits, sourceIndex, source, 0, INTERIOR_CACHE_WORDS);
boxes.clear();
markSectionSlices();
buildSortedSections();
findSections();
clearSectionBits();
voxelCount = voxelCount(sourceBits, sourceIndex);
markBoxSlices();
markBoxNeighborSlices();
buildSortedBoxes();
findDisjointBoxes();
if (voxelCount > 0) {
clearSectionBits();
markBoxSlices();
markBoxNeighborSlices();
buildSortedBoxes();
findDisjointBoxes();
}
}
private void buildSortedSections() {
final LongArrayList sortedBoxes = this.sortedBoxes;
sortedBoxes.clear();
final int[] areaSlices = this.areaSlices;
if (areaSlices[0] != 0) {
// handle special case of full Z-plane
addBoxesFromSlice(Area.indexToKey(0), areaSlices[0]);
}
for (int i = 1; i < Area.SECTION_COUNT; ++i) {
final int areaIndex = Area.sectionToAreaIndex(i);
final int slice = areaSlices[areaIndex];
if (slice == 0xFFFF) {
final int areaKey = Area.indexToKey(areaIndex);
final int dy = (Area.y1(areaKey) - Area.y0(areaKey) + 1);
final int dx = (Area.x1(areaKey) - Area.x0(areaKey) + 1);
final long vol = (dx * dy * 16);
sortedBoxes.add((vol << 34) | (areaIndex << 10) | (16 << 5) | 0);
}
}
sortedBoxes.sort((a, b) -> Long.compare(b, a));
}
private void markBoxNeighborSlices() {
final int[] areaSlices = this.areaSlices;
for (int areaIndex = 0; areaIndex < Area.AREA_COUNT; ++areaIndex) {
int slice = areaSlices[areaIndex];
if (slice != 0) {
if ((slice & 1) == 1 && (slice & 2) == 0) {
// special case first slice - can only transfer up
if (Area.isIncludedBySample(source, SLICE_WORD_COUNT, areaIndex)) {
slice |= 2;
}
}
int mask = 2;
for (int z = 1; z < 15; z++) {
if ((slice & mask) != 0) {
// transfer to lower slice if not already present
final int lowMask = (mask >> 1);
if ((slice & lowMask) == 0) {
if (Area.isIncludedBySample(source, (z - 1) * SLICE_WORD_COUNT, areaIndex)) {
slice |= lowMask;
}
}
// transfer to upper slice if not already present
final int highMask = (mask << 1);
if ((slice & highMask) == 0) {
if (Area.isIncludedBySample(source, (z + 1) * SLICE_WORD_COUNT, areaIndex)) {
slice |= highMask;
}
}
}
mask <<= 1;
}
if ((slice & 0b1000000000000000) == 0b1000000000000000 && (slice & 0b0100000000000000) == 0) {
if (Area.isIncludedBySample(source, SLICE_WORD_COUNT * 14, areaIndex)) {
slice |= 0b0100000000000000;
}
}
areaSlices[areaIndex] = slice;
}
}
}
private void buildSortedBoxes() {
final LongArrayList sortedBoxes = this.sortedBoxes;
sortedBoxes.clear();
final int[] areaSlices = this.areaSlices;
for (int areaIndex = 0; areaIndex < Area.AREA_COUNT; ++areaIndex) {
final int slice = areaSlices[areaIndex];
if (slice != 0) {
addBoxesFromSlice(Area.indexToKey(areaIndex), slice);
}
}
sortedBoxes.sort((a, b) -> Long.compare(b, a));
}
private void addBoxesFromSlice(int areaKey, int slice) {
int z0 = -1;
int mask = 1;
final int x0 = Area.x0(areaKey);
final int y0 = Area.y0(areaKey);
final int x1 = Area.x1(areaKey);
final int y1 = Area.y1(areaKey);
final int areaIndex = Area.keyToIndex(areaKey);
for (int z = 0; z < 16; z++) {
if ((slice & mask) == 0) {
// no bit, end run if started
if (z0 != -1) {
final int dz = (z - z0);
final int dy = (y1 - y0 + 1);
final int dx = (x1 - x0 + 1);
final long vol = dx * dy * dz;
sortedBoxes.add((vol << 34) | (areaIndex << 10) | (z << 5) | z0);
z0 = -1;
}
} else {
// bit set, start run if not started
if (z0 == -1) {
z0 = z;
}
}
mask <<= 1;
}
// handle case when run extends to last bit
if (z0 != -1) {
final int dz = (16 - z0);
final int dy = (y1 - y0 + 1);
final int dx = (x1 - x0 + 1);
final long vol = dx * dy * dz;
sortedBoxes.add((vol << 34) | (areaIndex << 10) | (16 << 5) | z0);
}
}
// PERF: still slow on relative basis to rest of chunk baking
private void markBoxSlices() {
final long[] sourceBits = source;
final AreaFinder areaFinder = this.areaFinder;
final int[] areaSlices = this.areaSlices;
Arrays.fill(areaSlices, 0);
mask = 1;
int sourceIndex = 0;
for (int i = 0; i < 16; ++i) {
areaFinder.find(sourceBits, sourceIndex, markSliceConsumer);
sourceIndex += SLICE_WORD_COUNT;
mask <<= 1;
}
}
private void markSectionSlices() {
final long[] sourceBits = source;
final AreaFinder areaFinder = this.areaFinder;
final int[] areaSlices = this.areaSlices;
Arrays.fill(areaSlices, 0);
mask = 1;
int sourceIndex = 0;
for (int i = 0; i < 16; ++i) {
areaFinder.findSections(sourceBits, sourceIndex, markSliceConsumer);
sourceIndex += SLICE_WORD_COUNT;
mask <<= 1;
}
}
private void findSections() {
final LongArrayList sortedBoxes = this.sortedBoxes;
final int limit = sortedBoxes.size();
final IntArrayList boxes = this.boxes;
for (int i = 0; i < limit; i++) {
final long box = sortedBoxes.getLong(i);
final int areaIndex = (int) (box >> 10) & 0xFFFFFF;
final int z0 = (int) box & 31;
final int z1 = (int) (box >> 5) & 31;
if (isAdditive(areaIndex, z0, z1)) {
fill(areaIndex, z0, z1);
final int areaKey = Area.indexToKey(areaIndex);
boxes.add(PackedBox.pack(Area.x0(areaKey), Area.y0(areaKey), z0, Area.x1(areaKey) + 1, Area.y1(areaKey) + 1, z1, PackedBox.RANGE_EXTREME));
}
}
}
private void findDisjointBoxes() {
final LongArrayList sortedBoxes = this.sortedBoxes;
final int limit = sortedBoxes.size();
final IntArrayList boxes = this.boxes;
for (int i = 0; i < limit; i++) {
final long box = sortedBoxes.getLong(i);
final int areaIndex = (int) (box >> 10) & 0xFFFFFF;
final int z0 = (int) box & 31;
final int z1 = (int) (box >> 5) & 31;
if (!intersects(areaIndex, z0, z1)) {
fill(areaIndex, z0, z1);
final int vol = (int) (box >>> 34);
final int areaKey = Area.indexToKey(areaIndex);
boxes.add(PackedBox.pack(Area.x0(areaKey), Area.y0(areaKey), z0, Area.x1(areaKey) + 1, Area.y1(areaKey) + 1, z1, rangeFromVolume(vol)));
voxelCount -= vol;
if (voxelCount == 0) {
break;
}
}
}
}
private int rangeFromVolume(int maxArea) {
return maxArea <= 64 ? PackedBox.RANGE_NEAR : maxArea > 512 ? PackedBox.RANGE_FAR : PackedBox.RANGE_MID;
}
private int voxelCount(long[] sourceBits, int sourceIndex) {
int result = 0;
final int limit = sourceIndex + INTERIOR_CACHE_WORDS;
for (int i = sourceIndex; i < limit; ++i) {
final long bits = sourceBits[i];
result += Long.bitCount(bits);
}
return result;
}
private void fill(int areaIndex, int z0, int z1) {
final long[] filled = this.filled;
int index = z0 * SLICE_WORD_COUNT;
final long[] bits = areaFinder.bitsFromIndex(areaIndex);
for (int z = z0; z < z1; ++z) {
filled[index] |= bits[0];
filled[index + 1] |= bits[1];
filled[index + 2] |= bits[2];
filled[index + 3] |= bits[3];
index += SLICE_WORD_COUNT;
}
}
private boolean intersects(int areaIndex, int z0, int z1) {
final long[] filled = this.filled;
int index = z0 * SLICE_WORD_COUNT;
for (int z = z0; z < z1; ++z) {
if (Area.intersectsWithSample(filled, index, areaIndex)) {
return true;
}
index += SLICE_WORD_COUNT;
}
return false;
}
private boolean isAdditive(int areaIndex, int z0, int z1) {
final long[] filled = this.filled;
int index = z0 * SLICE_WORD_COUNT;
final long a0 = Area.bitsFromIndex(areaIndex, 0);
final long a1 = Area.bitsFromIndex(areaIndex, 1);
final long a2 = Area.bitsFromIndex(areaIndex, 2);
final long a3 = Area.bitsFromIndex(areaIndex, 3);
for (int z = z0; z < z1; ++z) {
if (((~filled[index++] & a0) | (~filled[index++] & a1) | (~filled[index++] & a2) | (~filled[index++] & a3)) != 0) {
return true;
}
}
return false;
}
private void clearSectionBits() {
for (int i = 0; i < INTERIOR_CACHE_WORDS; ++i) {
source[i] &= ~filled[i];
}
}
}
@@ -68,5 +68,6 @@ public final class StandardOptions {
public static final OptionIdentifier<Void> USE_FASTER_CLOUDS = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "use_faster_clouds");
public static final OptionIdentifier<Void> ASYNC_GRAPH_SEARCH = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "async_graph_search");
public static final OptionIdentifier<Void> CHUNK_FADE_IN_DURATION = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "chunk_fade_in_duration");
public static final OptionIdentifier<Void> RASTER_OCCLUSION_CULLING = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "raster_occlusion_culling");
}
}
@@ -18,6 +18,8 @@ celeritas.options.async_graph_search.tooltip=Performs occlusion/frustum culling
celeritas.options.chunk_fade_in_duration.name=Chunk Fade-In Duration
celeritas.options.chunk_fade_in_duration.value=%s ms
celeritas.options.chunk_fade_in_duration.tooltip=Controls how long it takes for newly loaded chunks to fully appear. Longer durations create a smoother transition between unloaded and loaded chunks, reducing visual popping, but may make distant terrain appear to 'fade in' more slowly.
celeritas.options.raster_occlusion_culling.name=Rasterized Occlusion Culling
celeritas.options.raster_occlusion_culling.tooltip=Rasterizes nearby terrain into a small software coverage buffer and uses it to skip chunks hidden behind solid terrain, such as a valley behind a hill. This can substantially reduce the amount of terrain drawn, but costs extra CPU time each frame, so it helps most when the GPU is the bottleneck.\n\nChanging this rebuilds all chunks.
sodium.option_impact.low=Low
sodium.option_impact.medium=Medium
sodium.option_impact.high=High
@@ -17,5 +17,7 @@
"celeritas.options.async_graph_search.tooltip": "Performs occlusion/frustum culling asynchronously, up to one frame behind the current camera position. This can improve frametimes, particularly at higher render distances, but at the cost of chunks popping into view if the camera is turned too aggressively.",
"celeritas.options.chunk_fade_in_duration.name": "Chunk Fade-In Duration",
"celeritas.options.chunk_fade_in_duration.value": "%s ms",
"celeritas.options.chunk_fade_in_duration.tooltip": "Controls how long it takes for newly loaded chunks to fully appear. Longer durations create a smoother transition between unloaded and loaded chunks, reducing visual popping, but may make distant terrain appear to 'fade in' more slowly."
"celeritas.options.chunk_fade_in_duration.tooltip": "Controls how long it takes for newly loaded chunks to fully appear. Longer durations create a smoother transition between unloaded and loaded chunks, reducing visual popping, but may make distant terrain appear to 'fade in' more slowly.",
"celeritas.options.raster_occlusion_culling.name": "Rasterized Occlusion Culling",
"celeritas.options.raster_occlusion_culling.tooltip": "Rasterizes nearby terrain into a small software coverage buffer and uses it to skip chunks hidden behind solid terrain, such as a valley behind a hill. This can substantially reduce the amount of terrain drawn, but costs extra CPU time each frame, so it helps most when the GPU is the bottleneck.\n\nChanging this rebuilds all chunks."
}