Skip to content

Commit

Permalink
Port to Sodium 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
comp500 committed Aug 2, 2023
1 parent 017ff97 commit 3dd1814
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 107 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ minecraft_version=1.20.1
yarn_mappings=1.20.1+build.8
loader_version=0.14.21
# Mod Properties
mod_version=1.0.21
mod_version=1.0.22
maven_group=link.infra
archives_base_name=indium
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.84.0+1.20.1
sodium_version=0.4.10
sodium_minecraft_version=1.20
sodium_version=0.5.0
sodium_minecraft_version=1.20.1
# Publishing metadata
curseforge_id=459496
source_url=https://github.com/comp500/Indium/
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import me.jellysquid.mods.sodium.client.render.occlusion.BlockOcclusionCache;
import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockOcclusionCache;

@Mixin(BlockRenderer.class)
public interface AccessBlockRenderer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package link.infra.indium.mixin.sodium;

import me.jellysquid.mods.sodium.client.model.light.data.ArrayLightDataCache;
import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderCache;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -11,7 +12,6 @@

import link.infra.indium.renderer.accessor.AccessBlockRenderCache;
import link.infra.indium.renderer.render.TerrainRenderContext;
import me.jellysquid.mods.sodium.client.model.light.cache.ArrayLightDataCache;

@Mixin(BlockRenderCache.class)
public class MixinBlockRenderCache implements AccessBlockRenderCache {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package link.infra.indium.mixin.sodium;

import link.infra.indium.Indium;
import link.infra.indium.renderer.render.TerrainRenderContext;
import me.jellysquid.mods.sodium.client.render.chunk.compile.ChunkBuildBuffers;
import me.jellysquid.mods.sodium.client.render.chunk.compile.ChunkBuildContext;
import me.jellysquid.mods.sodium.client.render.chunk.compile.ChunkBuildOutput;
import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderContext;
import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer;
import me.jellysquid.mods.sodium.client.render.chunk.compile.tasks.ChunkBuilderMeshingTask;
import me.jellysquid.mods.sodium.client.render.chunk.compile.tasks.ChunkBuilderTask;
import me.jellysquid.mods.sodium.client.util.task.CancellationToken;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

/**
* The main injection point into Sodium - here we stop Sodium from rendering FRAPI block models, and do it ourselves
*/
@Mixin(ChunkBuilderMeshingTask.class)
public abstract class MixinChunkBuilderMeshingTask extends ChunkBuilderTask<ChunkBuildOutput> {
@Inject(method = "execute(Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildContext;Lme/jellysquid/mods/sodium/client/util/task/CancellationToken;)Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildOutput;",
at = @At("HEAD"), remap = false)
public void beforePerformBuild(ChunkBuildContext buildContext, CancellationToken cancellationToken, CallbackInfoReturnable<ChunkBuildOutput> cir) {
// Set up our rendering context
TerrainRenderContext.get(buildContext).prepare(buildContext);
}

@Inject(method = "execute(Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildContext;Lme/jellysquid/mods/sodium/client/util/task/CancellationToken;)Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildOutput;",
at = @At("RETURN"), remap = false)
public void afterPerformBuild(ChunkBuildContext buildContext, CancellationToken cancellationToken, CallbackInfoReturnable<ChunkBuildOutput> cir) {
// Tear down our rendering context
TerrainRenderContext.get(buildContext).release();
}

@Redirect(method = "execute(Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildContext;Lme/jellysquid/mods/sodium/client/util/task/CancellationToken;)Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildOutput;",
at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer;renderModel(Lme/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderContext;Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildBuffers;)V", remap = false), remap = false)
public void onRenderBlock(BlockRenderer blockRenderer, BlockRenderContext ctx, ChunkBuildBuffers buffers, ChunkBuildContext buildContext, CancellationToken cancellationToken) {
// We need to get the model with a bit more context than BlockRenderer has, so we do it here
if (Indium.ALWAYS_TESSELLATE_INDIUM || !ctx.model().isVanillaAdapter()) {
TerrainRenderContext.get(buildContext).tessellateBlock(ctx);
} else {
blockRenderer.renderModel(ctx, buffers);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package link.infra.indium.renderer.accessor;

import link.infra.indium.renderer.render.TerrainRenderContext;
import me.jellysquid.mods.sodium.client.model.light.cache.ArrayLightDataCache;
import me.jellysquid.mods.sodium.client.model.light.data.ArrayLightDataCache;

public interface AccessBlockRenderCache {
ArrayLightDataCache indium$getLightDataCache();
Expand Down
40 changes: 20 additions & 20 deletions src/main/java/link/infra/indium/renderer/aocalc/AoCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static link.infra.indium.renderer.helper.GeometryHelper.LIGHT_FACE_FLAG;
import static me.jellysquid.mods.sodium.client.model.light.data.LightDataAccess.unpackAO;
import static me.jellysquid.mods.sodium.client.model.light.data.LightDataAccess.unpackFO;
import static me.jellysquid.mods.sodium.client.model.light.data.LightDataAccess.unpackLM;
import static me.jellysquid.mods.sodium.client.model.light.data.LightDataAccess.getLightmap;
import static me.jellysquid.mods.sodium.client.model.light.data.LightDataAccess.unpackOP;
import static net.minecraft.util.math.Direction.DOWN;
import static net.minecraft.util.math.Direction.EAST;
Expand Down Expand Up @@ -366,23 +366,23 @@ private void computeFace(AoFaceData result, Direction lightFace, boolean isOnBlo
// direction of the light face, but it was actually mis-sampling and causing
// visible artifacts in certain situations

final long word0 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[0]);
final int light0 = unpackLM(word0);
final int word0 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[0]);
final int light0 = getLightmap(word0);
final float ao0 = unpackAO(word0);
final boolean isClear0 = unpackOP(word0);

final long word1 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[1]);
final int light1 = unpackLM(word1);
final int word1 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[1]);
final int light1 = getLightmap(word1);
final float ao1 = unpackAO(word1);
final boolean isClear1 = unpackOP(word1);

final long word2 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[2]);
final int light2 = unpackLM(word2);
final int word2 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[2]);
final int light2 = getLightmap(word2);
final float ao2 = unpackAO(word2);
final boolean isClear2 = unpackOP(word2);

final long word3 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[3]);
final int light3 = unpackLM(word3);
final int word3 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[3]);
final int light3 = getLightmap(word3);
final float ao3 = unpackAO(word3);
final boolean isClear3 = unpackOP(word3);

Expand All @@ -397,48 +397,48 @@ private void computeFace(AoFaceData result, Direction lightFace, boolean isOnBlo
cAo0 = ao0;
cLight0 = light0;
} else {
final long word02 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[0], neighbors[2]);
final int word02 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[0], neighbors[2]);
cAo0 = unpackAO(word02);
cLight0 = unpackLM(word02);
cLight0 = getLightmap(word02);
}

if (!isClear3 && !isClear0) {
cAo1 = ao0;
cLight1 = light0;
} else {
final long word03 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[0], neighbors[3]);
final int word03 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[0], neighbors[3]);
cAo1 = unpackAO(word03);
cLight1 = unpackLM(word03);
cLight1 = getLightmap(word03);
}

if (!isClear2 && !isClear1) {
cAo2 = ao1;
cLight2 = light1;
} else {
final long word12 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[1], neighbors[2]);
final int word12 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[1], neighbors[2]);
cAo2 = unpackAO(word12);
cLight2 = unpackLM(word12);
cLight2 = getLightmap(word12);
}

if (!isClear3 && !isClear1) {
cAo3 = ao1;
cLight3 = light1;
} else {
final long word13 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[1], neighbors[3]);
final int word13 = cache.get(lightPosX, lightPosY, lightPosZ, neighbors[1], neighbors[3]);
cAo3 = unpackAO(word13);
cLight3 = unpackLM(word13);
cLight3 = getLightmap(word13);
}

long centerWord = cache.get(lightPosX, lightPosY, lightPosZ);
int centerWord = cache.get(lightPosX, lightPosY, lightPosZ);

// If on block face or neighbor isn't occluding, "center" will be neighbor brightness
// Doesn't use light pos because logic not based solely on this block's geometry
int lightCenter;

if (isOnBlockFace || !unpackFO(centerWord)) {
lightCenter = unpackLM(centerWord);
lightCenter = getLightmap(centerWord);
} else {
lightCenter = unpackLM(cache.get(x, y, z));
lightCenter = getLightmap(cache.get(x, y, z));
}

float aoCenter = unpackAO(centerWord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import java.util.List;

import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.DefaultMaterials;
import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.Material;
import org.jetbrains.annotations.Nullable;

import link.infra.indium.renderer.IndiumRenderer;
Expand Down Expand Up @@ -64,7 +66,7 @@ public void emitDirectly() {

private final BlockPos.Mutable lightPos = new BlockPos.Mutable();

protected abstract void bufferQuad(MutableQuadViewImpl quad, RenderLayer renderLayer);
protected abstract void bufferQuad(MutableQuadViewImpl quad, Material material);

@Override
public QuadEmitter getEmitter() {
Expand Down Expand Up @@ -92,10 +94,11 @@ private void renderQuad(MutableQuadViewImpl quad, boolean isVanilla) {
final boolean ao = blockInfo.useAo && (aoMode == TriState.TRUE || (aoMode == TriState.DEFAULT && blockInfo.defaultAo));
final boolean emissive = mat.emissive();
final RenderLayer renderLayer = blockInfo.effectiveRenderLayer(mat.blendMode());
final Material sodiumMaterial = DefaultMaterials.forRenderLayer(renderLayer);

colorizeQuad(quad, colorIndex);
shadeQuad(quad, isVanilla, ao, emissive);
bufferQuad(quad, renderLayer);
bufferQuad(quad, sodiumMaterial);
}

/** handles block color, common to all renders. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import link.infra.indium.renderer.aocalc.AoCalculator;
import link.infra.indium.renderer.mesh.MutableQuadViewImpl;
import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.Material;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.util.math.MatrixStack;
Expand All @@ -40,7 +40,7 @@ public NonTerrainBlockRenderContext() {
}

@Override
protected void bufferQuad(MutableQuadViewImpl quad, RenderLayer renderLayer) {
protected void bufferQuad(MutableQuadViewImpl quad, Material material) {
bufferQuad(quad, vertexConsumer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Arrays;

import me.jellysquid.mods.sodium.client.model.light.cache.ArrayLightDataCache;
import me.jellysquid.mods.sodium.client.model.light.data.ArrayLightDataCache;
import me.jellysquid.mods.sodium.client.model.light.data.LightDataAccess;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockRenderView;
Expand All @@ -17,20 +17,20 @@ public class SingleBlockLightDataCache extends LightDataAccess {
private static final int NEIGHBOR_BLOCK_RADIUS = 2;
private static final int BLOCK_LENGTH = 1 + (NEIGHBOR_BLOCK_RADIUS * 2);

private final long[] light;
private final int[] light;

private int xOffset, yOffset, zOffset;

public SingleBlockLightDataCache() {
this.light = new long[BLOCK_LENGTH * BLOCK_LENGTH * BLOCK_LENGTH];
this.light = new int[BLOCK_LENGTH * BLOCK_LENGTH * BLOCK_LENGTH];
}

public void reset(BlockPos origin, BlockRenderView blockView) {
this.xOffset = origin.getX() - NEIGHBOR_BLOCK_RADIUS;
this.yOffset = origin.getY() - NEIGHBOR_BLOCK_RADIUS;
this.zOffset = origin.getZ() - NEIGHBOR_BLOCK_RADIUS;

Arrays.fill(this.light, 0L);
Arrays.fill(this.light, 0);

this.world = blockView;
}
Expand All @@ -44,10 +44,10 @@ private int index(int x, int y, int z) {
}

@Override
public long get(int x, int y, int z) {
public int get(int x, int y, int z) {
int l = this.index(x, y, z);

long word = this.light[l];
int word = this.light[l];

if (word != 0) {
return word;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package link.infra.indium.renderer.render;

import me.jellysquid.mods.sodium.client.render.occlusion.BlockOcclusionCache;
import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockOcclusionCache;
import net.minecraft.util.math.Direction;

public class TerrainBlockRenderInfo extends BlockRenderInfo {
Expand Down
Loading

0 comments on commit 3dd1814

Please sign in to comment.