Skip to content

Commit

Permalink
Upgrade Sodium and fix DH
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Aug 25, 2024
1 parent cb049f5 commit c6c7b94
Show file tree
Hide file tree
Showing 19 changed files with 103 additions and 120 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ val MINECRAFT_VERSION by extra { "1.21.1" }
val NEOFORGE_VERSION by extra { "21.1.19" }
val FABRIC_LOADER_VERSION by extra { "0.16.0" }
val FABRIC_API_VERSION by extra { "0.102.0+1.21.1" }
val SODIUM_FILE by extra { "sodium-LOADER-0.6.0-beta.1+mc1.21.jar" }
val SODIUM_FILE by extra { "sodium-LOADER-0.6.0-snapshot+mc1.21-local.jar" }

// https://semver.org/
val MOD_VERSION by extra { "1.8.0-beta.2" }
Expand Down
8 changes: 4 additions & 4 deletions common/src/main/java/net/irisshaders/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ public static void onRenderSystemInit() {

PBRTextureManager.INSTANCE.init();

VertexSerializerRegistry.instance().registerSerializer(VertexFormatRegistry.instance().get(DefaultVertexFormat.NEW_ENTITY), VertexFormatRegistry.instance().get(IrisVertexFormats.TERRAIN), new EntityToTerrainVertexSerializer());
VertexSerializerRegistry.instance().registerSerializer(VertexFormatRegistry.instance().get(IrisVertexFormats.ENTITY), VertexFormatRegistry.instance().get(IrisVertexFormats.TERRAIN), new IrisEntityToTerrainVertexSerializer());
VertexSerializerRegistry.instance().registerSerializer(VertexFormatRegistry.instance().get(DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP), VertexFormatRegistry.instance().get(IrisVertexFormats.GLYPH), new GlyphExtVertexSerializer());
VertexSerializerRegistry.instance().registerSerializer(VertexFormatRegistry.instance().get(DefaultVertexFormat.NEW_ENTITY), VertexFormatRegistry.instance().get(IrisVertexFormats.ENTITY), new ModelToEntityVertexSerializer());
VertexSerializerRegistry.instance().registerSerializer(DefaultVertexFormat.NEW_ENTITY, IrisVertexFormats.TERRAIN, new EntityToTerrainVertexSerializer());
VertexSerializerRegistry.instance().registerSerializer(IrisVertexFormats.ENTITY, IrisVertexFormats.TERRAIN, new IrisEntityToTerrainVertexSerializer());
VertexSerializerRegistry.instance().registerSerializer(DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, IrisVertexFormats.GLYPH, new GlyphExtVertexSerializer());
VertexSerializerRegistry.instance().registerSerializer(DefaultVertexFormat.NEW_ENTITY, IrisVertexFormats.ENTITY, new ModelToEntityVertexSerializer());

// Only load the shader pack when we can access OpenGL
loadShaderpack();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.irisshaders.iris.compat.sodium.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.caffeinemc.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer;
import net.caffeinemc.mods.sodium.client.render.chunk.terrain.TerrainRenderPass;
import net.caffeinemc.mods.sodium.client.render.frapi.mesh.MutableQuadViewImpl;
import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(BlockRenderer.class)
public class MixinBlockRenderer {
@Unique
private boolean hasOverride;

@Inject(method = "renderModel", at = @At("HEAD"))
private void iris$renderModelHead(BakedModel model, BlockState state, BlockPos pos, BlockPos origin, CallbackInfo ci) {
if (WorldRenderingSettings.INSTANCE.getBlockTypeIds().containsKey(state.getBlock())) {
hasOverride = true;
}
}

@Inject(method = "renderModel", at = @At("TAIL"))
private void iris$renderModelTail(BakedModel model, BlockState state, BlockPos pos, BlockPos origin, CallbackInfo ci) {
hasOverride = false;
}

@WrapOperation(method = "bufferQuad", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer;attemptPassDowngrade(Lnet/caffeinemc/mods/sodium/client/render/frapi/mesh/MutableQuadViewImpl;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;Lnet/caffeinemc/mods/sodium/client/render/chunk/terrain/TerrainRenderPass;)Lnet/caffeinemc/mods/sodium/client/render/chunk/terrain/TerrainRenderPass;"))
private TerrainRenderPass iris$skipPassDowngrade(BlockRenderer instance, MutableQuadViewImpl mutableQuadView, TextureAtlasSprite quad, TerrainRenderPass sprite, Operation<TerrainRenderPass> original) {
if (hasOverride) return null;

return original.call(instance, mutableQuadView, quad, sprite);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.mojang.blaze3d.vertex.VertexFormat;
import net.caffeinemc.mods.sodium.api.util.NormI8;
import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter;
import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatDescription;
import net.caffeinemc.mods.sodium.api.vertex.format.common.ColorVertex;
import net.caffeinemc.mods.sodium.client.render.immediate.CloudRenderer;
import net.irisshaders.iris.Iris;
Expand Down Expand Up @@ -79,10 +78,10 @@ private static VertexFormat rebuild(VertexFormat p_350837_) {
return IrisApi.getInstance().isShaderPackInUse() ? IrisVertexFormats.CLOUDS : p_350837_;
}

@ModifyArg(remap = false, method = "emitCellGeometry3D", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;push(Lorg/lwjgl/system/MemoryStack;JILnet/caffeinemc/mods/sodium/api/vertex/format/VertexFormatDescription;)V"), index = 3)
private static VertexFormatDescription modifyArgIris(VertexFormatDescription vertexFormatDescription) {
@ModifyArg(remap = false, method = "emitCellGeometry3D", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;push(Lorg/lwjgl/system/MemoryStack;JILcom/mojang/blaze3d/vertex/VertexFormat;)V"), index = 3)
private static VertexFormat modifyArgIris(VertexFormat vertexFormatDescription) {
if (IrisApi.getInstance().isShaderPackInUse()) {
return CloudVertex.FORMAT;
return IrisVertexFormats.CLOUDS;
} else {
return ColorVertex.FORMAT;
}
Expand All @@ -93,10 +92,10 @@ private static int allocateNewSize2D(int size) {
return IrisApi.getInstance().isShaderPackInUse() ? 80 : size;
}

@ModifyArg(remap = false, method = "emitCellGeometry2D", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;push(Lorg/lwjgl/system/MemoryStack;JILnet/caffeinemc/mods/sodium/api/vertex/format/VertexFormatDescription;)V"), index = 3)
private static VertexFormatDescription modifyArgIris2D(VertexFormatDescription vertexFormatDescription) {
@ModifyArg(remap = false, method = "emitCellGeometry2D", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/api/vertex/buffer/VertexBufferWriter;push(Lorg/lwjgl/system/MemoryStack;JILcom/mojang/blaze3d/vertex/VertexFormat;)V"), index = 3)
private static VertexFormat modifyArgIris2D(VertexFormat vertexFormatDescription) {
if (IrisApi.getInstance().isShaderPackInUse()) {
return CloudVertex.FORMAT;
return IrisVertexFormats.CLOUDS;
} else {
return ColorVertex.FORMAT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionManager;
import net.irisshaders.iris.mixin.LevelRendererAccessor;
import net.irisshaders.iris.shadows.ShadowRenderingState;
import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderBuffers;
Expand All @@ -23,14 +24,35 @@

@Mixin(SodiumWorldRenderer.class)
public class MixinSodiumWorldRenderer {
@Unique
private float lastSunAngle;

@Redirect(method = "setupTerrain", remap = false,
at = @At(value = "INVOKE",
target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager;needsUpdate()Z",
target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager;needsUpdate()Z", ordinal = 0,
remap = false))
private boolean iris$forceChunkGraphRebuildInShadowPass(RenderSectionManager instance) {
if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) {
float sunAngle = Minecraft.getInstance().level.getSunAngle(CapturedRenderingState.INSTANCE.getTickDelta());
if (lastSunAngle != sunAngle) {
lastSunAngle = sunAngle;
return true;
}

return instance.needsUpdate();
} else {
return instance.needsUpdate();
}
}

@Redirect(method = "setupTerrain", remap = false,
at = @At(value = "INVOKE",
target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager;needsUpdate()Z", ordinal = 1,
remap = false))
private boolean iris$forceEndGraphRebuild(RenderSectionManager instance) {
if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) {
// TODO: Detect when the sun/moon isn't moving
return true;
return false;
} else {
return instance.needsUpdate();
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ public class MixinItemBlockRenderTypes {

@Inject(method = "getChunkRenderType", at = @At("HEAD"), cancellable = true)
private static void iris$setCustomRenderType(BlockState arg, CallbackInfoReturnable<RenderType> cir) {
Map<Block, BlockRenderType> idMap = WorldRenderingSettings.INSTANCE.getBlockTypeIds();
if (idMap != null) {
BlockRenderType type = idMap.get(arg.getBlock());
if (type != null) {
cir.setReturnValue(LAYER_SET_VANILLA[type.ordinal()]);
}
BlockRenderType type = WorldRenderingSettings.INSTANCE.getBlockTypeIds().get(arg.getBlock());
if (type != null) {
cir.setReturnValue(LAYER_SET_VANILLA[type.ordinal()]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public VanillaRenderingPipeline() {
WorldRenderingSettings.INSTANCE.setAmbientOcclusionLevel(1.0f);
WorldRenderingSettings.INSTANCE.setUseExtendedVertexFormat(false);
WorldRenderingSettings.INSTANCE.setVoxelizeLightBlocks(false);
WorldRenderingSettings.INSTANCE.setBlockTypeIds(null);
WorldRenderingSettings.INSTANCE.setBlockTypeIds(Object2ObjectMaps.emptyMap());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
import net.irisshaders.iris.Iris;
import net.minecraft.client.renderer.RenderType;
Expand Down Expand Up @@ -97,6 +98,8 @@ private static void addTag(TagEntry tagEntry, Object2IntMap<BlockState> idMap, i
}

public static Map<Block, BlockRenderType> createBlockTypeMap(Map<NamespacedId, BlockRenderType> blockPropertiesMap) {
if (blockPropertiesMap.isEmpty()) return Object2ObjectMaps.emptyMap();

Map<Block, BlockRenderType> blockTypeIds = new Reference2ReferenceOpenHashMap<>();

blockPropertiesMap.forEach((id, blockType) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public void setBlockStateIds(Object2IntMap<BlockState> blockStateIds) {
this.blockStateIds = blockStateIds;
}

@Nullable
public Map<Block, BlockRenderType> getBlockTypeIds() {
return blockTypeIds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@
import net.caffeinemc.mods.sodium.api.vertex.attributes.common.ColorAttribute;
import net.caffeinemc.mods.sodium.api.vertex.attributes.common.NormalAttribute;
import net.caffeinemc.mods.sodium.api.vertex.attributes.common.PositionAttribute;
import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatDescription;
import net.caffeinemc.mods.sodium.api.vertex.format.VertexFormatRegistry;
import net.irisshaders.iris.vertices.IrisVertexFormats;
import org.joml.Matrix4f;

public final class CloudVertex {
public static final VertexFormatDescription FORMAT = VertexFormatRegistry.instance()
.get(IrisVertexFormats.CLOUDS);

public static final int STRIDE = 20;

private static final int OFFSET_POSITION = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.caffeinemc.mods.sodium.api.memory.MemoryIntrinsics;
import net.caffeinemc.mods.sodium.api.util.NormI8;
import net.caffeinemc.mods.sodium.api.vertex.format.common.ModelVertex;
import net.caffeinemc.mods.sodium.api.vertex.format.common.EntityVertex;
import net.caffeinemc.mods.sodium.api.vertex.serializer.VertexSerializer;
import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.irisshaders.iris.vertices.IrisVertexFormats;
Expand All @@ -17,12 +17,12 @@ public void serialize(long src, long dst, int vertexCount) {
for (int i = 0; i < quadCount; i++) {
int normal = MemoryUtil.memGetInt(src + 32);
int tangent = NormalHelper.computeTangent(NormI8.unpackX(normal), NormI8.unpackY(normal), NormI8.unpackZ(normal), MemoryUtil.memGetFloat(src), MemoryUtil.memGetFloat(src + 4), MemoryUtil.memGetFloat(src + 8), MemoryUtil.memGetFloat(src + 16), MemoryUtil.memGetFloat(src + 20),
MemoryUtil.memGetFloat(src + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 4 + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 8 + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 16 + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 20 + ModelVertex.STRIDE),
MemoryUtil.memGetFloat(src + ModelVertex.STRIDE + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 4 + ModelVertex.STRIDE + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 8 + ModelVertex.STRIDE + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 16 + ModelVertex.STRIDE + ModelVertex.STRIDE), MemoryUtil.memGetFloat(src + 20 + ModelVertex.STRIDE + ModelVertex.STRIDE));
MemoryUtil.memGetFloat(src + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 4 + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 8 + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 16 + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 20 + EntityVertex.STRIDE),
MemoryUtil.memGetFloat(src + EntityVertex.STRIDE + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 4 + EntityVertex.STRIDE + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 8 + EntityVertex.STRIDE + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 16 + EntityVertex.STRIDE + EntityVertex.STRIDE), MemoryUtil.memGetFloat(src + 20 + EntityVertex.STRIDE + EntityVertex.STRIDE));
float midU = 0, midV = 0;
for (int vertex = 0; vertex < 4; vertex++) {
midU += MemoryUtil.memGetFloat(src + 16 + (ModelVertex.STRIDE * vertex));
midV += MemoryUtil.memGetFloat(src + 20 + (ModelVertex.STRIDE * vertex));
midU += MemoryUtil.memGetFloat(src + 16 + (EntityVertex.STRIDE * vertex));
midV += MemoryUtil.memGetFloat(src + 20 + (EntityVertex.STRIDE * vertex));
}

midU /= 4;
Expand All @@ -39,7 +39,7 @@ public void serialize(long src, long dst, int vertexCount) {
MemoryUtil.memPutInt(dst + 44, tangent);
MemoryUtil.memPutInt(dst + 48, 0);

src += ModelVertex.STRIDE;
src += EntityVertex.STRIDE;
dst += IrisVertexFormats.TERRAIN.getVertexSize();
}
}
Expand Down

This file was deleted.

Loading

0 comments on commit c6c7b94

Please sign in to comment.