Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/20.1/fabric' into 20.6/fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed May 15, 2024
2 parents a0d50bc + 1fdad48 commit 1a7413d
Show file tree
Hide file tree
Showing 30 changed files with 920 additions and 349 deletions.
30 changes: 18 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,26 @@ publishMods {
incompatible {
slug = "indium"
}
incompatible {
slug = "reeses-sodium-options"
}
}
}
modrinth {
projectId = "sk9rgfiA"
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
minecraftVersions.add("minecraft_version"())

incompatible {
slug = "sodium"
}
incompatible {
slug = "indium"
modrinth {
projectId = "sk9rgfiA"
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
minecraftVersions.add("minecraft_version"())

incompatible {
slug = "sodium"
}
incompatible {
slug = "indium"
}
incompatible {
slug = "reeses-sodium-options"
}
}
}
}

displayName = "[${"minecraft_version"()}] Embeddium-Fabric ${"mod_version"()}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ public class GlBufferArena {
static final boolean CHECK_ASSERTIONS = false;

private static final GlBufferUsage BUFFER_USAGE = GlBufferUsage.STATIC_DRAW;
/**
* When the arena needs to be grown, it will generally attempt to increase its size by (1 / RESIZE_FACTOR).
*/
private static final int RESIZE_FACTOR = 2;

private final int resizeIncrement;
private int resizeIncrement;

private final StagingBuffer stagingBuffer;
private GlMutableBuffer arenaBuffer;
Expand All @@ -33,7 +37,7 @@ public class GlBufferArena {

public GlBufferArena(CommandList commands, int initialCapacity, int stride, StagingBuffer stagingBuffer) {
this.capacity = initialCapacity;
this.resizeIncrement = initialCapacity / 16;
this.resizeIncrement = initialCapacity / RESIZE_FACTOR;

this.stride = stride;

Expand Down Expand Up @@ -134,6 +138,7 @@ private void transferSegments(CommandList commandList, Collection<PendingBufferC

this.arenaBuffer = dstBufferObj;
this.capacity = capacity;
this.resizeIncrement = this.capacity / RESIZE_FACTOR;
}

private ArrayList<GlBufferSegment> getUsedSegments() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,19 @@ public static OptionPage quality() {
.build())
.build());

groups.add(OptionGroup.createBuilder()
.setId(StandardOptions.Group.SORTING)
.add(OptionImpl.createBuilder(boolean.class, sodiumOpts)
.setId(StandardOptions.Option.TRANSLUCENT_FACE_SORTING)
.setName(Component.translatable("sodium.options.translucent_face_sorting.name"))
.setTooltip(Component.translatable("sodium.options.translucent_face_sorting.tooltip"))
.setControl(TickBoxControl::new)
.setImpact(OptionImpact.VARIES)
.setBinding((opts, value) -> opts.performance.useTranslucentFaceSorting = value, opts -> opts.performance.useTranslucentFaceSorting)
.setEnabled(!ShaderModBridge.isNvidiumEnabled())
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
.build())
.build());

return new OptionPage(Component.translatable("sodium.options.pages.quality"), ImmutableList.copyOf(groups));
}
Expand Down Expand Up @@ -397,17 +410,6 @@ public static OptionPage advanced() {
.setBinding((opts, value) -> opts.advanced.cpuRenderAheadLimit = value, opts -> opts.advanced.cpuRenderAheadLimit)
.build()
)
.add(OptionImpl.createBuilder(boolean.class, sodiumOpts)
.setId(StandardOptions.Option.TRANSLUCENT_FACE_SORTING)
.setName(Component.translatable("sodium.options.translucent_face_sorting.name"))
.setTooltip(Component.translatable("sodium.options.translucent_face_sorting.tooltip"))
.setControl(TickBoxControl::new)
.setImpact(OptionImpact.VARIES)
.setBinding((opts, value) -> opts.performance.useTranslucentFaceSorting = value, opts -> opts.performance.useTranslucentFaceSorting)
.setEnabled(!ShaderModBridge.isNvidiumEnabled())
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
.build()
)
.build());

return new OptionPage(Component.translatable("sodium.options.pages.advanced"), ImmutableList.copyOf(groups));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
import me.jellysquid.mods.sodium.client.model.color.interop.BlockColorsExtended;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.renderer.BiomeColors;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;


// TODO: Make the registry a global somewhere that is only initialized once after content load
public class ColorProviderRegistry {
private final Reference2ReferenceMap<Block, ColorProvider<BlockState>> blocks = new Reference2ReferenceOpenHashMap<>();
private final Reference2ReferenceMap<Fluid, ColorProvider<FluidState>> fluids = new Reference2ReferenceOpenHashMap<>();
Expand All @@ -35,18 +34,18 @@ public ColorProviderRegistry(BlockColors blockColors) {

// TODO: Allow mods to install their own color resolvers here
private void installOverrides() {
this.registerBlocks(DefaultColorProviders.GrassColorProvider.BLOCKS,
this.registerBlocks(new DefaultColorProviders.VertexBlendedBiomeColorAdapter<>(BiomeColors::getAverageGrassColor),
Blocks.GRASS_BLOCK, Blocks.FERN, Blocks.SHORT_GRASS, Blocks.POTTED_FERN,
Blocks.PINK_PETALS, Blocks.SUGAR_CANE, Blocks.LARGE_FERN, Blocks.TALL_GRASS);

this.registerBlocks(DefaultColorProviders.FoliageColorProvider.BLOCKS,
this.registerBlocks(new DefaultColorProviders.VertexBlendedBiomeColorAdapter<>(BiomeColors::getAverageFoliageColor),
Blocks.OAK_LEAVES, Blocks.JUNGLE_LEAVES, Blocks.ACACIA_LEAVES,
Blocks.DARK_OAK_LEAVES, Blocks.VINE, Blocks.MANGROVE_LEAVES);

this.registerBlocks(DefaultColorProviders.WaterColorProvider.BLOCKS,
this.registerBlocks(new DefaultColorProviders.VertexBlendedBiomeColorAdapter<>(BiomeColors::getAverageWaterColor),
Blocks.WATER, Blocks.BUBBLE_COLUMN);

this.registerFluids(DefaultColorProviders.WaterColorProvider.FLUIDS,
this.registerFluids(new DefaultColorProviders.VertexBlendedBiomeColorAdapter<>(BiomeColors::getAverageWaterColor),
Fluids.WATER, Fluids.FLOWING_WATER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;

Expand All @@ -22,6 +23,7 @@ public static ColorProvider<FluidState> adapt(FluidRenderHandler handler) {
return new FabricFluidAdapter(handler);
}

@Deprecated(forRemoval = true)
public static class GrassColorProvider<T> extends BlendedColorProvider<T> {
public static final ColorProvider<BlockState> BLOCKS = new GrassColorProvider<>();

Expand All @@ -35,6 +37,7 @@ protected int getColor(WorldSlice world, int x, int y, int z) {
}
}

@Deprecated(forRemoval = true)
public static class FoliageColorProvider<T> extends BlendedColorProvider<T> {
public static final ColorProvider<BlockState> BLOCKS = new FoliageColorProvider<>();

Expand All @@ -48,6 +51,7 @@ protected int getColor(WorldSlice world, int x, int y, int z) {
}
}

@Deprecated(forRemoval = true)
public static class WaterColorProvider<T> extends BlendedColorProvider<T> {
public static final ColorProvider<BlockState> BLOCKS = new WaterColorProvider<>();
public static final ColorProvider<FluidState> FLUIDS = new WaterColorProvider<>();
Expand All @@ -62,6 +66,24 @@ protected int getColor(WorldSlice world, int x, int y, int z) {
}
}

public static class VertexBlendedBiomeColorAdapter<T> extends BlendedColorProvider<T> {
private final VanillaBiomeColor vanillaGetter;

@FunctionalInterface
public interface VanillaBiomeColor {
int getAverageColor(BlockAndTintGetter getter, BlockPos pos);
}

public VertexBlendedBiomeColorAdapter(VanillaBiomeColor vanillaGetter) {
this.vanillaGetter = vanillaGetter;
}

@Override
protected int getColor(WorldSlice world, BlockPos pos) {
return vanillaGetter.getAverageColor(world, pos);
}
}

private static class VanillaAdapter implements ColorProvider<BlockState> {
private final BlockColor provider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@

public class LightPipelineProvider {
private final EnumMap<LightMode, LightPipeline> lighters = new EnumMap<>(LightMode.class);
private final LightDataAccess cache;

public LightPipelineProvider(LightDataAccess cache) {
this.cache = cache;
this.lighters.put(LightMode.SMOOTH, new SmoothLightPipeline(cache));
this.lighters.put(LightMode.FLAT, new FlatLightPipeline(cache));
}

public LightDataAccess getLightData() {
return this.cache;
}

public LightPipeline getLighter(LightMode type) {
LightPipeline pipeline = this.lighters.get(type);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
public abstract class BlendedColorProvider<T> implements ColorProvider<T> {
private static boolean shouldUseVertexBlending;

private final BlockPos.MutableBlockPos cursor = new BlockPos.MutableBlockPos();

public static void checkBlendingEnabled() {
shouldUseVertexBlending = Minecraft.getInstance().options.biomeBlendRadius().get() > 0;
}
Expand All @@ -26,7 +28,7 @@ public void getColors(WorldSlice view, BlockPos pos, T state, ModelQuadView quad
}
} else {
// Just sample the exact position of that block (like vanilla), and use the same color on all vertices
Arrays.fill(output, ColorARGB.toABGR(this.getColor(view, pos.getX(), pos.getY(), pos.getZ())));
Arrays.fill(output, ColorARGB.toABGR(this.getColor(view, pos)));
}
}

Expand All @@ -48,11 +50,13 @@ private int getVertexColor(WorldSlice world, BlockPos blockPos, ModelQuadView qu
final int worldIntY = blockPos.getY() + intY;
final int worldIntZ = blockPos.getZ() + intZ;

var neighborPos = cursor;

// Retrieve the color values for each neighboring block
final int c00 = this.getColor(world, worldIntX + 0, worldIntY, worldIntZ + 0);
final int c01 = this.getColor(world, worldIntX + 0, worldIntY, worldIntZ + 1);
final int c10 = this.getColor(world, worldIntX + 1, worldIntY, worldIntZ + 0);
final int c11 = this.getColor(world, worldIntX + 1, worldIntY, worldIntZ + 1);
final int c00 = this.getColor(world, neighborPos.set(worldIntX + 0, worldIntY, worldIntZ + 0));
final int c01 = this.getColor(world, neighborPos.set(worldIntX + 0, worldIntY, worldIntZ + 1));
final int c10 = this.getColor(world, neighborPos.set(worldIntX + 1, worldIntY, worldIntZ + 0));
final int c11 = this.getColor(world, neighborPos.set(worldIntX + 1, worldIntY, worldIntZ + 1));

// Linear interpolation across the Z-axis
int z0;
Expand Down Expand Up @@ -83,5 +87,12 @@ private int getVertexColor(WorldSlice world, BlockPos blockPos, ModelQuadView qu
return ColorARGB.toABGR(x0);
}

protected abstract int getColor(WorldSlice world, int x, int y, int z);
protected int getColor(WorldSlice world, BlockPos pos) {
return getColor(world, pos.getX(), pos.getY(), pos.getZ());
}

@Deprecated(forRemoval = true)
protected int getColor(WorldSlice world, int x, int y, int z) {
throw new AssertionError("Must override one of the getColor methods");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class DefaultChunkRenderer extends ShaderChunkRenderer {

private final GlVertexAttributeBinding[] vertexAttributeBindings;

private boolean isIndexedPass;

public DefaultChunkRenderer(RenderDevice device, ChunkVertexType vertexType) {
super(device, vertexType);

Expand All @@ -60,6 +62,8 @@ public void render(ChunkRenderMatrices matrices,

Iterator<ChunkRenderList> iterator = renderLists.iterator(renderPass.isReverseOrder());

this.isIndexedPass = renderPass.isSorted();

while (iterator.hasNext()) {
ChunkRenderList renderList = iterator.next();

Expand All @@ -76,7 +80,11 @@ public void render(ChunkRenderMatrices matrices,
continue;
}

this.sharedIndexBuffer.ensureCapacity(commandList, this.batch.getIndexBufferSize());


if (!this.isIndexedPass) {
this.sharedIndexBuffer.ensureCapacity(commandList, this.batch.getIndexBufferSize());
}

var tessellation = this.prepareTessellation(commandList, region);

Expand Down Expand Up @@ -106,6 +114,8 @@ private static void fillCommandBuffer(MultiDrawBatch batch,
int originY = renderRegion.getChunkY();
int originZ = renderRegion.getChunkZ();

int indexPointerMask = pass.isSorted() ? 0xFFFFFFFF : 0;

while (iterator.hasNext()) {
int sectionIndex = iterator.nextByteAsInt();

Expand All @@ -117,7 +127,7 @@ private static void fillCommandBuffer(MultiDrawBatch batch,

int slices;

if (useBlockFaceCulling && (!pass.isReverseOrder() || !SodiumClientMod.canApplyTranslucencySorting())) {
if (useBlockFaceCulling && !pass.isSorted()) {
slices = getVisibleFaces(camera.intX, camera.intY, camera.intZ, chunkX, chunkY, chunkZ);
} else {
slices = ModelQuadFacing.ALL;
Expand All @@ -126,21 +136,23 @@ private static void fillCommandBuffer(MultiDrawBatch batch,
slices &= SectionRenderDataUnsafe.getSliceMask(pMeshData);

if (slices != 0) {
addDrawCommands(batch, pMeshData, slices);
addDrawCommands(batch, pMeshData, slices, indexPointerMask);
}
}
}

@SuppressWarnings("IntegerMultiplicationImplicitCastToLong")
private static void addDrawCommands(MultiDrawBatch batch, long pMeshData, int mask) {
private static void addDrawCommands(MultiDrawBatch batch, long pMeshData, int mask, int indexPointerMask) {
final var pBaseVertex = batch.pBaseVertex;
final var pElementCount = batch.pElementCount;
final var pElementPointer = batch.pElementPointer;

int size = batch.size;

for (int facing = 0; facing < ModelQuadFacing.COUNT; facing++) {
MemoryUtil.memPutInt(pBaseVertex + (size << 2), SectionRenderDataUnsafe.getVertexOffset(pMeshData, facing));
MemoryUtil.memPutInt(pElementCount + (size << 2), SectionRenderDataUnsafe.getElementCount(pMeshData, facing));
MemoryUtil.memPutAddress(pElementPointer + (size << 3), SectionRenderDataUnsafe.getIndexOffset(pMeshData, facing) & indexPointerMask);

size += (mask >> facing) & 1;
}
Expand Down Expand Up @@ -213,10 +225,15 @@ private static float getCameraTranslation(int chunkBlockPos, int cameraBlockPos,

private GlTessellation prepareTessellation(CommandList commandList, RenderRegion region) {
var resources = region.getResources();
var tessellation = resources.getTessellation();
var tessellation = this.isIndexedPass ? resources.getIndexedTessellation() : resources.getTessellation();

if (tessellation == null) {
resources.updateTessellation(commandList, tessellation = this.createRegionTessellation(commandList, resources));
tessellation = this.createRegionTessellation(commandList, resources);
if (this.isIndexedPass) {
resources.updateIndexedTessellation(commandList, tessellation);
} else {
resources.updateTessellation(commandList, tessellation);
}
}

return tessellation;
Expand Down Expand Up @@ -253,7 +270,7 @@ private GlVertexAttributeBinding[] getBindingsForType() {
private GlTessellation createRegionTessellation(CommandList commandList, RenderRegion.DeviceResources resources) {
return commandList.createTessellation(GlPrimitiveType.TRIANGLES, new TessellationBinding[] {
TessellationBinding.forVertexBuffer(resources.getVertexBuffer(), this.vertexAttributeBindings),
TessellationBinding.forElementBuffer(this.sharedIndexBuffer.getBufferObject())
TessellationBinding.forElementBuffer(this.isIndexedPass ? resources.getIndexBuffer() : this.sharedIndexBuffer.getBufferObject())
});
}

Expand Down

0 comments on commit 1a7413d

Please sign in to comment.