Skip to content

Commit

Permalink
Final touches (hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Sep 15, 2024
1 parent b3d9009 commit c5ec134
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 35 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ 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-snapshot+mc1.21-local.jar" }
val SODIUM_FILE by extra { "sodium-LOADER-0.6.0-beta.2+mc1.21.1.jar" }

// https://semver.org/
val MOD_VERSION by extra { "1.8.0-beta.2" }
val MOD_VERSION by extra { "1.8.0-beta.4" }

allprojects {
apply(plugin = "java")
Expand Down
17 changes: 15 additions & 2 deletions common/src/main/java/net/irisshaders/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import net.minecraft.network.chat.HoverEvent;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.system.Configuration;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -100,6 +101,7 @@ public class Iris {
private static String IRIS_VERSION;
private static UpdateChecker updateChecker;
private static boolean fallback;
private static boolean loadShaderPackWhenPossible;

static {
if (!BuildConfig.ACTIVATE_RENDERDOC && IrisPlatformHelpers.getInstance().isDevelopmentEnvironment() && System.getProperty("user.name").contains("ims") && Util.getPlatform() == Util.OS.LINUX) {
Expand All @@ -124,7 +126,9 @@ public static void onRenderSystemInit() {
VertexSerializerRegistry.instance().registerSerializer(DefaultVertexFormat.NEW_ENTITY, IrisVertexFormats.ENTITY, new ModelToEntityVertexSerializer());

// Only load the shader pack when we can access OpenGL
loadShaderpack();
if (!IrisPlatformHelpers.getInstance().isModLoaded("distanthorizons")) {
loadShaderpack();
}
}

public static void duringRenderSystemInit() {
Expand All @@ -149,6 +153,11 @@ public static void onLoadingComplete() {
}

public static void handleKeybinds(Minecraft minecraft) {
if (loadShaderPackWhenPossible) {
loadShaderPackWhenPossible = false;
Iris.loadShaderpack();
}

if (reloadKeybind.consumeClick()) {
try {
reload();
Expand Down Expand Up @@ -720,7 +729,11 @@ public static boolean isPackInUseQuick() {
return getPipelineManager().getPipelineNullable() instanceof IrisRenderingPipeline;
}

/**
public static void loadShaderpackWhenPossible() {
loadShaderPackWhenPossible = true;
}

/**
* 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 @@ -55,6 +55,8 @@ public static void setupEventHandlers() {
public void afterDistantHorizonsInit(DhApiEventParam<Void> event) {
Iris.logger.info("DH Ready, binding Iris event handlers...");

Iris.loadShaderpackWhenPossible();

setupSetDeferredBeforeRenderingEvent();
setupReconnectDepthTextureEvent();
setupGenericEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ 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;JILcom/mojang/blaze3d/vertex/VertexFormat;)V"), index = 3)
@ModifyArg(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 IrisVertexFormats.CLOUDS;
Expand All @@ -92,7 +92,7 @@ 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;JILcom/mojang/blaze3d/vertex/VertexFormat;)V"), index = 3)
@ModifyArg(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 IrisVertexFormats.CLOUDS;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.irisshaders.iris.compat.sodium.mixin;

import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import com.mojang.blaze3d.vertex.PoseStack;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import net.caffeinemc.mods.sodium.client.render.SodiumWorldRenderer;
Expand All @@ -8,6 +9,7 @@
import net.irisshaders.iris.shadows.ShadowRenderingState;
import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderBuffers;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
Expand Down Expand Up @@ -67,7 +69,7 @@ public class MixinSodiumWorldRenderer {
ShadowRenderingState.setBlockEntityRenderFunction((shadowRenderer, bufferSource, modelView, camera, cameraX, cameraY, cameraZ, tickDelta, hasEntityFrustum, lightsOnly) -> {
renderLightsOnly = lightsOnly;

SodiumWorldRenderer.instance().renderBlockEntities(modelView, bufferSource, ((LevelRendererAccessor) Minecraft.getInstance().levelRenderer).getDestructionProgress(), camera, tickDelta);
SodiumWorldRenderer.instance().renderBlockEntities(modelView, bufferSource, ((LevelRendererAccessor) Minecraft.getInstance().levelRenderer).getDestructionProgress(), camera, tickDelta, null);

int finalBeList = beList;

Expand All @@ -78,7 +80,7 @@ public class MixinSodiumWorldRenderer {
}

@Inject(method = "renderBlockEntity", at = @At("HEAD"), cancellable = true)
private static void checkRenderShadow(PoseStack matrices, RenderBuffers bufferBuilders, Long2ObjectMap<SortedSet<BlockDestructionProgress>> blockBreakingProgressions, float tickDelta, MultiBufferSource.BufferSource immediate, double x, double y, double z, BlockEntityRenderDispatcher dispatcher, BlockEntity entity, CallbackInfo ci) {
private static void checkRenderShadow(PoseStack matrices, RenderBuffers bufferBuilders, Long2ObjectMap<SortedSet<BlockDestructionProgress>> blockBreakingProgressions, float tickDelta, MultiBufferSource.BufferSource immediate, double x, double y, double z, BlockEntityRenderDispatcher dispatcher, BlockEntity entity, LocalPlayer player, LocalBooleanRef isGlowing, CallbackInfo ci) {
if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) {
if (renderLightsOnly && entity.getBlockState().getLightEmission() == 0) {
ci.cancel();
Expand Down
16 changes: 0 additions & 16 deletions common/src/main/java/net/irisshaders/iris/helpers/StringPair.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,4 @@
* An absurdly simple class for storing pairs of strings because Java lacks pair / tuple types.
*/
public record StringPair(String key, String value) {
public StringPair(@NotNull String key, @NotNull String value) {
this.key = Objects.requireNonNull(key);
this.value = Objects.requireNonNull(value);
}

@Override
@NotNull
public String key() {
return key;
}

@Override
@NotNull
public String value() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ private GlProgram<ChunkShaderInterface> buildProgram(GlProgram.Builder builder,
Supplier<ImmutableSet<Integer>> flipState,
boolean containsTessellation) {
return builder
.bindAttribute("a_PositionHi", ChunkShaderBindingPoints.ATTRIBUTE_POSITION_HI)
.bindAttribute("a_PositionLo", ChunkShaderBindingPoints.ATTRIBUTE_POSITION_LO)
.bindAttribute("a_Position", ChunkShaderBindingPoints.ATTRIBUTE_POSITION)
.bindAttribute("a_Color", ChunkShaderBindingPoints.ATTRIBUTE_COLOR)
.bindAttribute("a_TexCoord", ChunkShaderBindingPoints.ATTRIBUTE_TEXTURE)
.bindAttribute("a_LightAndData", ChunkShaderBindingPoints.ATTRIBUTE_LIGHT_MATERIAL_INDEX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ public static void injectVertInit(
"uint _draw_id;",
"const uint MATERIAL_USE_MIP_OFFSET = 0u;",
"""
uvec3 _deinterleave_u20x3(uint packed_hi, uint packed_lo) {
uvec3 hi = (uvec3(packed_hi) >> uvec3(0u, 10u, 20u)) & 0x3FFu;
uvec3 lo = (uvec3(packed_lo) >> uvec3(0u, 10u, 20u)) & 0x3FFu;
uvec3 _deinterleave_u20x3(uvec2 data) {
uvec3 hi = (uvec3(data.x) >> uvec3(0u, 10u, 20u)) & 0x3FFu;
uvec3 lo = (uvec3(data.y) >> uvec3(0u, 10u, 20u)) & 0x3FFu;
return (hi << 10u) | lo;
}
Expand All @@ -154,7 +154,7 @@ vec2 _get_texcoord_bias() {
" return ((material >> MATERIAL_USE_MIP_OFFSET) & 1u) != 0u ? 0.0f : -4.0f;\n" +
"}",
"void _vert_init() {" +
"_vert_position = ((_deinterleave_u20x3(a_PositionHi, a_PositionLo) * VERTEX_SCALE) + VERTEX_OFFSET);" +
"_vert_position = ((_deinterleave_u20x3(a_Position) * VERTEX_SCALE) + VERTEX_OFFSET);" +
"_vert_tex_diffuse_coord = _get_texcoord() + _get_texcoord_bias();" +
"_vert_tex_light_coord = vec2(a_LightAndData.xy);" +
"_vert_color = a_Color;" +
Expand All @@ -167,8 +167,7 @@ vec2 _get_texcoord_bias() {
"vec3 _get_draw_translation(uint pos) {\n" +
" return _get_relative_chunk_coord(pos) * vec3(16.0f);\n" +
"}\n");
addIfNotExists(root, t, tree, "a_PositionHi", Type.UINT32, StorageQualifier.StorageType.IN);
addIfNotExists(root, t, tree, "a_PositionLo", Type.UINT32, StorageQualifier.StorageType.IN);
addIfNotExists(root, t, tree, "a_Position", Type.U32VEC2, StorageQualifier.StorageType.IN);
addIfNotExists(root, t, tree, "a_TexCoord", Type.U32VEC2, StorageQualifier.StorageType.IN);
addIfNotExists(root, t, tree, "a_Color", Type.F32VEC4, StorageQualifier.StorageType.IN);
addIfNotExists(root, t, tree, "a_LightAndData", Type.U32VEC4, StorageQualifier.StorageType.IN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public static ChunkVertexType createFormat(boolean blockId, boolean normal, bool
}

GlVertexFormat.Builder VERTEX_FORMAT = GlVertexFormat.builder(offset)
.addElement(DefaultChunkMeshAttributes.POSITION_HI, ChunkShaderBindingPoints.ATTRIBUTE_POSITION_HI, 0)
.addElement(DefaultChunkMeshAttributes.POSITION_LO, ChunkShaderBindingPoints.ATTRIBUTE_POSITION_LO, 4)
.addElement(DefaultChunkMeshAttributes.POSITION, ChunkShaderBindingPoints.ATTRIBUTE_POSITION, 0)
.addElement(DefaultChunkMeshAttributes.COLOR, ChunkShaderBindingPoints.ATTRIBUTE_COLOR, 8)
.addElement(DefaultChunkMeshAttributes.TEXTURE, ChunkShaderBindingPoints.ATTRIBUTE_TEXTURE, 12)
.addElement(DefaultChunkMeshAttributes.LIGHT_MATERIAL_INDEX, ChunkShaderBindingPoints.ATTRIBUTE_LIGHT_MATERIAL_INDEX, 16);
Expand Down
1 change: 0 additions & 1 deletion fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ loom {
configName = "Fabric Client"
ideConfigGenerated(true)
runDir("run")
environmentVariable("LD_PRELOAD", "/usr/lib/librenderdoc.so")
}
named("server") {
server()
Expand Down

0 comments on commit c5ec134

Please sign in to comment.