Compare commits

...
Author SHA1 Message Date
Logan Phillips 4a05ea1bfe Adds fluid and gas culling 2026-11-26 23:35:42 -05:00
8 changed files with 157 additions and 0 deletions

No files matched your search

@@ -505,6 +505,8 @@ public enum Mixins implements IMixins {
, "celeritas.biome_blending.MixinBlockLiquid"
, "celeritas.biome_blending.MixinWorld"
, "celeritas.biome_blending.MixinRenderBlocks"
, "celeritas.terrain.MixinRenderBlocks_HiddenFluidTops"
, "celeritas.terrain.MixinRenderBlockFluid_HiddenFluidTops"
, "celeritas.threading.MixinForgeHooksClient"
, "celeritas.threading.MixinChunkJobTyped"
, "celeritas.terrain.MixinChunk"
@@ -0,0 +1,72 @@
package com.gtnewhorizons.angelica.rendering.celeritas;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fluids.BlockFluidBase;
public final class HiddenFluidTops {
public static final int SEARCH_RADIUS = 2;
private static final int SEARCH_WIDTH = 2 * SEARCH_RADIUS + 1;
private static final int BLOCKED = 0;
private static final int COVERED = 1;
private static final int OPEN = 2;
private static final int[] STEP_X = {1, -1, 0, 0};
private static final int[] STEP_Z = {0, 0, 1, -1};
private HiddenFluidTops() {}
public static boolean isTopHidden(IBlockAccess world, Block fluid, int x, int y, int z, int topOffset) {
if (world.getBlock(x, y, z) != fluid) return false;
if (!isFullLevel(world, fluid, x, y, z) || !world.getBlock(x, y + topOffset, z).isOpaqueCube()) return false;
return !hasOpeningNearby(world, fluid, x, y, z, topOffset);
}
private static boolean hasOpeningNearby(IBlockAccess world, Block fluid, int x, int y, int z, int topOffset) {
int covered = 1 << (SEARCH_RADIUS + SEARCH_RADIUS * SEARCH_WIDTH);
int checked = 0;
int blocked = 0;
int unchecked;
while ((unchecked = covered & ~checked) != 0) {
final int cell = Integer.numberOfTrailingZeros(unchecked);
checked |= 1 << cell;
final int cellX = cell % SEARCH_WIDTH;
final int cellZ = cell / SEARCH_WIDTH;
for (int step = 0; step < 4; step++) {
final int nextX = cellX + STEP_X[step];
final int nextZ = cellZ + STEP_Z[step];
if (nextX < 0 || nextZ < 0 || nextX >= SEARCH_WIDTH || nextZ >= SEARCH_WIDTH) continue;
final int bit = 1 << (nextX + nextZ * SEARCH_WIDTH);
if (((covered | blocked) & bit) != 0) continue;
final int kind = classify(world, fluid, x + nextX - SEARCH_RADIUS, y, z + nextZ - SEARCH_RADIUS, topOffset);
if (kind == OPEN) return true;
if (kind == COVERED) {
covered |= bit;
} else {
blocked |= bit;
}
}
}
return false;
}
private static int classify(IBlockAccess world, Block fluid, int x, int y, int z, int topOffset) {
final Block block = world.getBlock(x, y, z);
if (block.isOpaqueCube()) return BLOCKED;
if (!isSameFluid(fluid, block)) return OPEN;
final Block blockOnTop = world.getBlock(x, y + topOffset, z);
if (isSameFluid(fluid, blockOnTop)) return BLOCKED;
return blockOnTop.isOpaqueCube() && isFullLevel(world, fluid, x, y, z) ? COVERED : OPEN;
}
private static boolean isSameFluid(Block fluid, Block other) {
if (fluid instanceof BlockLiquid) return other instanceof BlockLiquid && other.getMaterial() == fluid.getMaterial();
return other == fluid;
}
private static boolean isFullLevel(IBlockAccess world, Block fluid, int x, int y, int z) {
final int meta = world.getBlockMetadata(x, y, z);
return fluid instanceof BlockFluidBase forgeFluid ? meta == forgeFluid.getMaxRenderHeightMeta() : meta == 0;
}
}
@@ -585,6 +585,17 @@ public class SodiumGameOptionPages {
.build());
groups.add(OptionGroup.createBuilder()
.add(OptionImpl.createBuilder(boolean.class, sodiumOpts)
.setName(I18n.format("sodium.options.use_hidden_fluid_culling.name"))
.setTooltip(I18n.format("sodium.options.use_hidden_fluid_culling.tooltip"))
.setControl(TickBoxControl::new)
.setImpact(OptionImpact.LOW)
.setBinding((opts, value) -> opts.performance.useHiddenFluidCulling = value, opts -> opts.performance.useHiddenFluidCulling)
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
.build())
.build());
groups.add(OptionGroup.createBuilder()
.add(OptionImpl.createBuilder(boolean.class, angelicaOpts)
.setName(I18n.format("options.angelica.parallelAtlasDecode"))
@@ -254,6 +254,7 @@ public class SodiumGameOptions {
public boolean sectionGatedTesrCulling = true;
public boolean useFogOcclusion = true;
public boolean useBlockFaceCulling = true;
public boolean useHiddenFluidCulling = true;
public boolean useCompactVertexFormat = true;
public TranslucencyMode translucencyMode = TranslucencyMode.FAST;
public Boolean translucencySorting;
@@ -91,6 +91,8 @@ sodium.options.animate_only_visible_textures.name=Animate Only Visible Textures
sodium.options.animate_only_visible_textures.tooltip=If enabled, only animated textures determined to be visible will be updated. This can provide a significant boost to frame rates on some hardware, especially with heavier resource packs. If you experience issues with some textures not being animated, try disabling this option.
sodium.options.translucency_mode.name=Translucency Sorting
sodium.options.translucency_mode.tooltip=Fast sorts translucent terrain (water, stained glass, ice) and translucent tile entities back to front so overlapping layers draw correctly. Fancy also draws translucent terrain, translucent tile entities, particles, weather and clouds into separate layers that blend correctly over one another; it uses more video memory and GPU time and has no effect with a shader pack. Off is fastest but causes layering artifacts. Changing this reloads chunks.
sodium.options.use_hidden_fluid_culling.name=Fluid & Gas Culling
sodium.options.use_hidden_fluid_culling.tooltip=Culls quads from fluids and gases that the player can't typically see.
sodium.options.block_entities_before_translucent_terrain.name=Tile Entities Before Translucent Terrain
sodium.options.block_entities_before_translucent_terrain.tooltip=If enabled, translucent tile entities are drawn before translucent terrain (water, stained glass, ice), so that the latter does not hide the former behind it. Tile Entities in front of terrain may hide the terrain, and glows in front of terrain may appear behind it. Always on with Fancy translucency sorting.
sodium.options.cpu_render_ahead_limit.name=CPU Render-Ahead Limit
@@ -0,0 +1,32 @@
package com.gtnewhorizons.angelica.mixins.early.celeritas.terrain;
import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager;
import com.gtnewhorizons.angelica.experimental.surround.Surround;
import com.gtnewhorizons.angelica.proxy.ClientProxy;
import com.gtnewhorizons.angelica.rendering.StateAwareTessellator;
import com.gtnewhorizons.angelica.rendering.celeritas.HiddenFluidTops;
import net.minecraft.block.Block;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fluids.RenderBlockFluid;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@Mixin(value = RenderBlockFluid.class, remap = false)
public class MixinRenderBlockFluid_HiddenFluidTops {
@Surround(method = "renderWorldBlock",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/IBlockAccess;getBlock(III)Lnet/minecraft/block/Block;", ordinal = 0, remap = true),
remap = false)
private void angelica$checkFluidTop() {}
@Surround.Return
private Block angelica$hideFluidTop(Block blockOnTop, IBlockAccess world, int x, int topY, int z,
@Surround.Local(argsOnly = true) Block fluid, @Surround.Local(argsOnly = true, ordinal = 1) int y) {
if (blockOnTop != fluid && ClientProxy.options().performance.useHiddenFluidCulling
&& ((StateAwareTessellator) TessellatorManager.get()).angelica$isCeleritasMeshing()
&& HiddenFluidTops.isTopHidden(world, fluid, x, y, z, topY - y)) {
return fluid;
}
return blockOnTop;
}
}
@@ -0,0 +1,30 @@
package com.gtnewhorizons.angelica.mixins.early.celeritas.terrain;
import com.gtnewhorizon.gtnhlib.client.renderer.TessellatorManager;
import com.gtnewhorizons.angelica.experimental.surround.Surround;
import com.gtnewhorizons.angelica.proxy.ClientProxy;
import com.gtnewhorizons.angelica.rendering.StateAwareTessellator;
import com.gtnewhorizons.angelica.rendering.celeritas.HiddenFluidTops;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.world.IBlockAccess;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@Mixin(RenderBlocks.class)
public class MixinRenderBlocks_HiddenFluidTops {
@Surround(method = "renderBlockLiquid", at = @At(value = "INVOKE",
target = "Lnet/minecraft/block/Block;shouldSideBeRendered(Lnet/minecraft/world/IBlockAccess;IIII)Z", ordinal = 0))
private void angelica$checkFluidTop() {}
@Surround.Return
private boolean angelica$hideFluidTop(boolean renderTop, Block fluid, IBlockAccess world, int x, int y, int z, int side) {
if (renderTop && ClientProxy.options().performance.useHiddenFluidCulling
&& ((StateAwareTessellator) TessellatorManager.get()).angelica$isCeleritasMeshing()
&& HiddenFluidTops.isTopHidden(world, fluid, x, y - 1, z, 1)) {
return false;
}
return renderTop;
}
}
@@ -15,6 +15,7 @@ import com.gtnewhorizons.angelica.rendering.RenderingState;
import com.gtnewhorizons.angelica.rendering.celeritas.BlockRenderLayer;
import com.gtnewhorizons.angelica.rendering.celeritas.CeleritasSetup;
import com.gtnewhorizons.angelica.rendering.celeritas.CeleritasWorldRenderer;
import com.gtnewhorizons.angelica.rendering.celeritas.HiddenFluidTops;
import com.gtnewhorizons.angelica.rendering.tesr.ModelPartBatcher;
import com.gtnewhorizons.angelica.rendering.tesr.TesrBatchRenderer;
import com.gtnewhorizons.angelica.rendering.translucency.TranslucencyLayers;
@@ -263,6 +264,12 @@ public class MixinRenderGlobal implements IRenderGlobalExt {
this.celeritas$renderer.scheduleRebuildForBlockArea(minX, minY, minZ, maxX, maxY, maxZ, false);
}
@Redirect(method = "markBlockForUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;markBlocksForUpdate(IIIIII)V"))
private void celeritas$scheduleBlockChangeRebuild(RenderGlobal self, int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
final int extraMargin = ClientProxy.options().performance.useHiddenFluidCulling ? HiddenFluidTops.SEARCH_RADIUS - 1 : 0;
this.celeritas$renderer.scheduleRebuildForBlockArea(minX - extraMargin, minY, minZ - extraMargin, maxX + extraMargin, maxY, maxZ + extraMargin, false);
}
@Unique
public void angelica$reload() {
CeleritasSetup.ensureInitialized();