Skip to content

Commit

Permalink
New Sodium + experimenting with dynamic vertex format
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Aug 26, 2024
1 parent 5f1f218 commit 9a4458b
Show file tree
Hide file tree
Showing 39 changed files with 344 additions and 211 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
14 changes: 9 additions & 5 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 Expand Up @@ -713,7 +713,11 @@ public static boolean loadedIncompatiblePack() {
return DHCompat.lastPackIncompatible();
}

/**
public static boolean isPackInUseQuick() {
return getPipelineManager().getPipelineNullable() instanceof IrisRenderingPipeline;
}

/**
* Called very early on in Minecraft initialization. At this point we *cannot* safely access OpenGL, but we can do
* some very basic setup, config loading, and environment checks.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static boolean checkFrame() {
if (DhApi.Delayed.configs == null) return dhEnabled;

if ((dhEnabled != DhApi.Delayed.configs.graphics().renderingEnabled().getValue() || guiScale != Minecraft.getInstance().options.guiScale().get())
&& IrisApi.getInstance().isShaderPackInUse()) {
&& Iris.isPackInUseQuick()) {
guiScale = Minecraft.getInstance().options.guiScale().get();
dhEnabled = DhApi.Delayed.configs.graphics().renderingEnabled().getValue();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.seibel.distanthorizons.api.objects.math.DhApiVec3i;
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBox;
import com.seibel.distanthorizons.api.objects.render.DhApiRenderableBoxGroupShading;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.api.v0.IrisApi;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.blending.BlendModeOverride;
Expand Down Expand Up @@ -269,7 +270,7 @@ public void bindVertexBuffer(int i) {

@Override
public boolean overrideThisFrame() {
return IrisApi.getInstance().isShaderPackInUse();
return Iris.isPackInUseQuick();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static void setupSetDeferredBeforeRenderingEvent() {
@Override
public void beforeRender(DhApiCancelableEventParam<DhApiRenderParam> event) {

DhApi.Delayed.renderProxy.setDeferTransparentRendering(IrisApi.getInstance().isShaderPackInUse() && getInstance().shouldOverride);
DhApi.Delayed.renderProxy.setDeferTransparentRendering(Iris.isPackInUseQuick() && getInstance().shouldOverride);
DhApi.Delayed.configs.graphics().fog().drawMode().setValue(getInstance().shouldOverride ? EDhApiFogDrawMode.FOG_DISABLED : EDhApiFogDrawMode.FOG_ENABLED);
}
};
Expand Down Expand Up @@ -365,7 +365,7 @@ private static void setupBeforeApplyShaderEvent() {
DhApiBeforeApplyShaderRenderEvent beforeApplyShaderEvent = new DhApiBeforeApplyShaderRenderEvent() {
@Override
public void beforeRender(DhApiCancelableEventParam<DhApiRenderParam> event) {
if (IrisApi.getInstance().isShaderPackInUse()) {
if (Iris.isPackInUseQuick()) {
DHCompatInternal instance = getInstance();

OverrideInjector.INSTANCE.unbind(IDhApiShadowCullingFrustum.class, (IDhApiOverrideable) ShadowRenderer.FRUSTUM);
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 @@ -53,7 +52,7 @@ public abstract class MixinCloudRenderer {

@Inject(method = "writeVertex", at = @At("HEAD"), cancellable = true, remap = false)
private static void writeIrisVertex(long buffer, float x, float y, float z, int color, CallbackInfoReturnable<Long> cir) {
if (IrisApi.getInstance().isShaderPackInUse()) {
if (Iris.isPackInUseQuick()) {
CloudVertex.put(buffer, x, y, z, color, computedNormal);
cir.setReturnValue(buffer + 20L);
}
Expand All @@ -71,40 +70,40 @@ private static void computeNormal3D(VertexBufferWriter writer, int visibleFaces,

@ModifyArg(remap = false, method = "emitCellGeometry3D", at = @At(value = "INVOKE", target = "Lorg/lwjgl/system/MemoryStack;nmalloc(I)J"))
private static int allocateNewSize(int size) {
return IrisApi.getInstance().isShaderPackInUse() ? 480 : size;
return Iris.isPackInUseQuick() ? 480 : size;
}

@ModifyArg(method = "rebuildGeometry", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/Tesselator;begin(Lcom/mojang/blaze3d/vertex/VertexFormat$Mode;Lcom/mojang/blaze3d/vertex/VertexFormat;)Lcom/mojang/blaze3d/vertex/BufferBuilder;"), index = 1)
private static VertexFormat rebuild(VertexFormat p_350837_) {
return IrisApi.getInstance().isShaderPackInUse() ? IrisVertexFormats.CLOUDS : p_350837_;
return Iris.isPackInUseQuick() ? 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) {
if (IrisApi.getInstance().isShaderPackInUse()) {
return CloudVertex.FORMAT;
@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 (Iris.isPackInUseQuick()) {
return IrisVertexFormats.CLOUDS;
} else {
return ColorVertex.FORMAT;
}
}

@ModifyArg(remap = false, method = "emitCellGeometry2D", at = @At(value = "INVOKE", target = "Lorg/lwjgl/system/MemoryStack;nmalloc(I)J"))
private static int allocateNewSize2D(int size) {
return IrisApi.getInstance().isShaderPackInUse() ? 80 : size;
return Iris.isPackInUseQuick() ? 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) {
if (IrisApi.getInstance().isShaderPackInUse()) {
return CloudVertex.FORMAT;
@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 (Iris.isPackInUseQuick()) {
return IrisVertexFormats.CLOUDS;
} else {
return ColorVertex.FORMAT;
}
}

@Redirect(method = "render", at = @At(remap = false, value = "FIELD", target = "Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer;cachedGeometry:Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer$CloudGeometry;", ordinal = 0))
private CloudRenderer.@Nullable CloudGeometry changeGeometry(CloudRenderer instance) {
if (IrisApi.getInstance().isShaderPackInUse()) {
if (Iris.isPackInUseQuick()) {
return cachedGeometryIris;
} else {
return cachedGeometry;
Expand All @@ -113,7 +112,7 @@ private static VertexFormatDescription modifyArgIris2D(VertexFormatDescription v

@Redirect(method = "render", at = @At(remap = false, value = "FIELD", target = "Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer;cachedGeometry:Lnet/caffeinemc/mods/sodium/client/render/immediate/CloudRenderer$CloudGeometry;", ordinal = 1))
private void changeGeometry2(CloudRenderer instance, CloudRenderer.CloudGeometry value) {
if (IrisApi.getInstance().isShaderPackInUse()) {
if (Iris.isPackInUseQuick()) {
cachedGeometryIris = value;
} else {
cachedGeometry = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public class MixinRenderRegionArenas {
target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/vertex/format/ChunkMeshFormats;COMPACT:Lnet/caffeinemc/mods/sodium/client/render/chunk/vertex/format/ChunkVertexType;",
remap = false))
private ChunkVertexType iris$useExtendedStride() {
return WorldRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat() ? IrisModelVertexFormats.MODEL_VERTEX_XHFP : ChunkMeshFormats.COMPACT;
return WorldRenderingSettings.INSTANCE.getVertexFormat();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public class MixinRenderSectionManager {
at = @At(value = "INVOKE",
target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/DefaultChunkRenderer;<init>(Lnet/caffeinemc/mods/sodium/client/gl/device/RenderDevice;Lnet/caffeinemc/mods/sodium/client/render/chunk/vertex/format/ChunkVertexType;)V"))
private ChunkVertexType iris$useExtendedVertexFormat$1(ChunkVertexType vertexType) {
return WorldRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat() ? IrisModelVertexFormats.MODEL_VERTEX_XHFP : vertexType;
return WorldRenderingSettings.INSTANCE.getVertexFormat();
}

@ModifyArg(method = "<init>",
at = @At(value = "INVOKE",
target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/executor/ChunkBuilder;<init>(Lnet/minecraft/client/multiplayer/ClientLevel;Lnet/caffeinemc/mods/sodium/client/render/chunk/vertex/format/ChunkVertexType;)V"))
private ChunkVertexType iris$useExtendedVertexFormat$2(ChunkVertexType vertexType) {
return WorldRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat() ? IrisModelVertexFormats.MODEL_VERTEX_XHFP : vertexType;
return WorldRenderingSettings.INSTANCE.getVertexFormat();
}

@Redirect(method = "getSearchDistance", remap = false,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ private static void override(ShaderKey key, CallbackInfoReturnable<ShaderInstanc

@Redirect(method = "renderItemInHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ItemInHandRenderer;renderHandsWithItems(FLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/player/LocalPlayer;I)V"))
private void iris$disableVanillaHandRendering(ItemInHandRenderer itemInHandRenderer, float tickDelta, PoseStack poseStack, BufferSource bufferSource, LocalPlayer localPlayer, int light) {
if (IrisApi.getInstance().isShaderPackInUse()) {
if (Iris.isPackInUseQuick()) {
return;
}

Expand Down
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
@@ -1,6 +1,7 @@
package net.irisshaders.iris.mixin;

import com.mojang.blaze3d.vertex.PoseStack;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.api.v0.IrisApi;
import net.irisshaders.iris.pathways.HandRenderer;
import net.minecraft.client.player.AbstractClientPlayer;
Expand All @@ -17,7 +18,7 @@
public class MixinItemInHandRenderer {
@Inject(method = "renderArmWithItem", at = @At("HEAD"), cancellable = true)
private void iris$skipTranslucentHands(AbstractClientPlayer abstractClientPlayer, float f, float g, InteractionHand interactionHand, float h, ItemStack itemStack, float i, PoseStack poseStack, MultiBufferSource multiBufferSource, int j, CallbackInfo ci) {
if (IrisApi.getInstance().isShaderPackInUse()) {
if (Iris.isPackInUseQuick()) {
if (HandRenderer.INSTANCE.isRenderingSolid() && HandRenderer.INSTANCE.isHandTranslucent(interactionHand)) {
ci.cancel();
} else if (!HandRenderer.INSTANCE.isRenderingSolid() && !HandRenderer.INSTANCE.isHandTranslucent(interactionHand)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.irisshaders.iris.mixin;

import com.mojang.blaze3d.vertex.PoseStack;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.api.v0.IrisApi;
import net.minecraft.client.Camera;
import net.minecraft.client.DeltaTracker;
Expand Down Expand Up @@ -54,7 +55,7 @@ public abstract class MixinModelViewBobbing {

@Inject(method = "renderLevel", at = @At("HEAD"))
private void iris$saveShadersOn(DeltaTracker deltaTracker, CallbackInfo ci) {
areShadersOn = IrisApi.getInstance().isShaderPackInUse();
areShadersOn = Iris.isPackInUseQuick();
}

@ModifyArg(method = "renderLevel", index = 0,
Expand Down
Loading

0 comments on commit 9a4458b

Please sign in to comment.