diff --git a/common/src/main/java/net/irisshaders/iris/Iris.java b/common/src/main/java/net/irisshaders/iris/Iris.java index b7027c99e5..b8e0a0e0bc 100644 --- a/common/src/main/java/net/irisshaders/iris/Iris.java +++ b/common/src/main/java/net/irisshaders/iris/Iris.java @@ -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. * diff --git a/common/src/main/java/net/irisshaders/iris/compat/dh/DHCompatInternal.java b/common/src/main/java/net/irisshaders/iris/compat/dh/DHCompatInternal.java index 6f304135e9..0481e99e44 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/dh/DHCompatInternal.java +++ b/common/src/main/java/net/irisshaders/iris/compat/dh/DHCompatInternal.java @@ -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 { diff --git a/common/src/main/java/net/irisshaders/iris/compat/dh/IrisGenericRenderProgram.java b/common/src/main/java/net/irisshaders/iris/compat/dh/IrisGenericRenderProgram.java index 367b896fde..bf5dc8b525 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/dh/IrisGenericRenderProgram.java +++ b/common/src/main/java/net/irisshaders/iris/compat/dh/IrisGenericRenderProgram.java @@ -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; @@ -267,7 +268,7 @@ public void bindVertexBuffer(int i) { @Override public boolean overrideThisFrame() { - return IrisApi.getInstance().isShaderPackInUse(); + return Iris.isPackInUseQuick(); } @Override diff --git a/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java b/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java index 3d5e8ece6f..9cdec9f665 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java +++ b/common/src/main/java/net/irisshaders/iris/compat/dh/LodRendererEvents.java @@ -85,7 +85,7 @@ private static void setupSetDeferredBeforeRenderingEvent() { @Override public void beforeRender(DhApiCancelableEventParam 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); } }; @@ -365,7 +365,7 @@ private static void setupBeforeApplyShaderEvent() { DhApiBeforeApplyShaderRenderEvent beforeApplyShaderEvent = new DhApiBeforeApplyShaderRenderEvent() { @Override public void beforeRender(DhApiCancelableEventParam event) { - if (IrisApi.getInstance().isShaderPackInUse()) { + if (Iris.isPackInUseQuick()) { DHCompatInternal instance = getInstance(); OverrideInjector.INSTANCE.unbind(IDhApiShadowCullingFrustum.class, (IDhApiOverrideable) ShadowRenderer.FRUSTUM); diff --git a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderRegionArenas.java b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderRegionArenas.java index 1326d92fbb..2b105b80d7 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderRegionArenas.java +++ b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderRegionArenas.java @@ -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(); } } diff --git a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderSectionManager.java b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderSectionManager.java index fcae907507..0fb85ecbbd 100644 --- a/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderSectionManager.java +++ b/common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinRenderSectionManager.java @@ -17,14 +17,14 @@ public class MixinRenderSectionManager { at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/DefaultChunkRenderer;(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 = "", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/compile/executor/ChunkBuilder;(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, diff --git a/common/src/main/java/net/irisshaders/iris/mixin/MixinGameRenderer.java b/common/src/main/java/net/irisshaders/iris/mixin/MixinGameRenderer.java index e43f150ee3..e815862174 100644 --- a/common/src/main/java/net/irisshaders/iris/mixin/MixinGameRenderer.java +++ b/common/src/main/java/net/irisshaders/iris/mixin/MixinGameRenderer.java @@ -484,7 +484,7 @@ private static void override(ShaderKey key, CallbackInfoReturnable framebuffers = new EnumMap<>(Pass.class); private final EnumMap> shaders = new EnumMap<>(Pass.class); + private boolean hasBlockId; + private boolean hasMidUv; + private boolean hasNormal; + private boolean hasTangent; + private boolean hasMidBlock; + public SodiumPrograms(IrisRenderingPipeline pipeline, ProgramSet programSet, ProgramFallbackResolver resolver, RenderTargets renderTargets, Supplier shadowRenderTargets, CustomUniforms customUniforms) { @@ -60,6 +70,8 @@ public SodiumPrograms(IrisRenderingPipeline pipeline, ProgramSet programSet, Pro GlProgram shader = createShader(pipeline, pass, source, alphaTest, customUniforms, flipState, createGlShaders(pass.name().toLowerCase(Locale.ROOT), transformed)); shaders.put(pass, shader); } + + WorldRenderingSettings.INSTANCE.setVertexFormat(FormatAnalyzer.createFormat(hasBlockId, hasNormal, hasMidUv, hasTangent, hasMidBlock)); } private AlphaTest getAlphaTest(Pass pass, ProgramSource source) { @@ -75,7 +87,7 @@ private Map transformShaders(ProgramSource source, Alph source.getTessControlSource().orElse(null), source.getTessEvalSource().orElse(null), source.getFragmentSource().orElse(null), - alphaTest, IrisModelVertexFormats.MODEL_VERTEX_XHFP, + alphaTest, programSet.getPackDirectives().getTextureMap()); ShaderPrinter.printProgram("sodium_" + source.getName()).addSources(transformed).print(); @@ -160,6 +172,13 @@ private GlProgram buildProgram(GlProgram.Builder builder, .link((shader) -> { int handle = ((GlObject) shader).handle(); GLDebug.nameObject(GL43C.GL_PROGRAM, handle, "sodium-terrain-" + pass.toString().toLowerCase(Locale.ROOT)); + + if (!hasNormal) hasNormal = GL43C.glGetAttribLocation(handle, "iris_Normal") != -1; + if (!hasMidBlock) hasMidBlock = GL43C.glGetAttribLocation(handle, "at_midBlock") != -1; + if (!hasBlockId) hasBlockId = GL43C.glGetAttribLocation(handle, "mc_Entity") != -1; + if (!hasMidUv) hasMidUv = GL43C.glGetAttribLocation(handle, "mc_midTexCoord") != -1; + if (!hasTangent) hasTangent = GL43C.glGetAttribLocation(handle, "at_tangent") != -1; + return new SodiumShader(pipeline, pass, shader, handle, source.getDirectives().getBlendModeOverride(), createBufferBlendOverrides(source), customUniforms, flipState, alphaTest.reference(), containsTessellation); diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/TransformPatcher.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/TransformPatcher.java index 45ac978cad..d40dbdcf6c 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/TransformPatcher.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/TransformPatcher.java @@ -328,10 +328,10 @@ public TextureStage getTextureStage() { } public static Map patchSodium(String name, String vertex, String geometry, String tessControl, String tessEval, String fragment, - AlphaTest alpha, ChunkVertexType vertexType, + AlphaTest alpha, Object2ObjectMap, String> textureMap) { return transform(name, vertex, geometry, tessControl, tessEval, fragment, - new SodiumParameters(Patch.SODIUM, textureMap, alpha, vertexType)); + new SodiumParameters(Patch.SODIUM, textureMap, alpha)); } public static Map patchComposite( diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/SodiumParameters.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/SodiumParameters.java index 7b12b63548..cecd59351d 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/SodiumParameters.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/parameter/SodiumParameters.java @@ -9,7 +9,6 @@ import net.irisshaders.iris.shaderpack.texture.TextureStage; public class SodiumParameters extends Parameters { - public final ChunkVertexType vertexType; // WARNING: adding new fields requires updating hashCode and equals methods! // DO NOT include this field in hashCode or equals, it's mutable! @@ -18,9 +17,8 @@ public class SodiumParameters extends Parameters { public SodiumParameters(Patch patch, Object2ObjectMap, String> textureMap, - AlphaTest alpha, ChunkVertexType vertexType) { + AlphaTest alpha) { super(patch, textureMap); - this.vertexType = vertexType; this.alpha = alpha; } @@ -35,15 +33,11 @@ public TextureStage getTextureStage() { return TextureStage.GBUFFERS_AND_SHADOW; } - public ChunkVertexType getVertexType() { - return vertexType; - } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + ((vertexType == null) ? 0 : vertexType.hashCode()); result = prime * result + ((alpha == null) ? 0 : alpha.hashCode()); return result; } @@ -57,11 +51,6 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) return false; SodiumParameters other = (SodiumParameters) obj; - if (vertexType == null) { - if (other.vertexType != null) - return false; - } else if (!vertexType.equals(other.vertexType)) - return false; if (alpha == null) { return other.alpha == null; } else return alpha.equals(other.alpha); diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumTransformer.java b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumTransformer.java index e4bf4f6e0c..3540d1be0c 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumTransformer.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/transform/transformer/SodiumTransformer.java @@ -51,7 +51,7 @@ public static void transform( root.rename("gl_Color", "_vert_color"); - if (parameters.type.glShaderType == ShaderType.VERTEX) { + if (parameters.type.glShaderType == ShaderType.VERTEX && root.identifierIndex.has("gl_Normal")) { root.rename("gl_Normal", "iris_Normal"); tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "in vec3 iris_Normal;"); } diff --git a/common/src/main/java/net/irisshaders/iris/shaderpack/materialmap/WorldRenderingSettings.java b/common/src/main/java/net/irisshaders/iris/shaderpack/materialmap/WorldRenderingSettings.java index aa1dcafda8..80b05f375c 100644 --- a/common/src/main/java/net/irisshaders/iris/shaderpack/materialmap/WorldRenderingSettings.java +++ b/common/src/main/java/net/irisshaders/iris/shaderpack/materialmap/WorldRenderingSettings.java @@ -2,6 +2,8 @@ import it.unimi.dsi.fastutil.objects.Object2IntFunction; import it.unimi.dsi.fastutil.objects.Object2IntMap; +import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkMeshFormats; +import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; @@ -20,9 +22,9 @@ public class WorldRenderingSettings { private boolean disableDirectionalShading; private boolean hasVillagerConversionId; private boolean useSeparateAo; - private boolean useExtendedVertexFormat; private boolean separateEntityDraws; private boolean voxelizeLightBlocks; + private ChunkVertexType chunkVertexFormat; public WorldRenderingSettings() { reloadRequired = false; @@ -31,7 +33,7 @@ public WorldRenderingSettings() { ambientOcclusionLevel = 1.0F; disableDirectionalShading = false; useSeparateAo = false; - useExtendedVertexFormat = false; + chunkVertexFormat = ChunkMeshFormats.COMPACT; separateEntityDraws = false; voxelizeLightBlocks = false; hasVillagerConversionId = false; @@ -132,17 +134,17 @@ public void setUseSeparateAo(boolean useSeparateAo) { this.useSeparateAo = useSeparateAo; } - public boolean shouldUseExtendedVertexFormat() { - return useExtendedVertexFormat; + public ChunkVertexType getVertexFormat() { + return chunkVertexFormat; } - public void setUseExtendedVertexFormat(boolean useExtendedVertexFormat) { - if (useExtendedVertexFormat == this.useExtendedVertexFormat) { + public void setVertexFormat(ChunkVertexType chunkVertexFormat) { + if (chunkVertexFormat == this.chunkVertexFormat) { return; } this.reloadRequired = true; - this.useExtendedVertexFormat = useExtendedVertexFormat; + this.chunkVertexFormat = chunkVertexFormat; } public boolean shouldVoxelizeLightBlocks() { diff --git a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/FormatAnalyzer.java b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/FormatAnalyzer.java new file mode 100644 index 0000000000..4973c1fcce --- /dev/null +++ b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/FormatAnalyzer.java @@ -0,0 +1,109 @@ +package net.irisshaders.iris.vertices.sodium.terrain; + +import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap; +import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap; +import net.caffeinemc.mods.sodium.client.gl.attribute.GlVertexFormat; +import net.caffeinemc.mods.sodium.client.render.chunk.shader.ChunkShaderBindingPoints; +import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkMeshFormats; +import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; +import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.impl.DefaultChunkMeshAttributes; + +public class FormatAnalyzer { + private static final Byte2ObjectMap classMap = new Byte2ObjectOpenHashMap<>(); + + static { + classMap.put((byte) 0, ChunkMeshFormats.COMPACT); + } + + public static ChunkVertexType createFormat(boolean blockId, boolean normal, boolean midUV, boolean tangent, boolean midBlock) { + byte key = 0; + if (blockId) { + key |= 1; + } + if (normal) { + key |= 2; + } + if (midUV) { + key |= 4; + } + if (tangent) { + key |= 8; + } + if (midBlock) { + key |= 16; + } + + if (classMap.containsKey(key)) { + return classMap.get(key); + } + + int offset = 20; // Normal Sodium stuff + + int blockIdOffset, normalOffset, tangentOffset, midUvOffset, midBlockOffset; + + if (blockId) { + blockIdOffset = offset; + offset += 4; + } else { + blockIdOffset = 0; + } + + if (normal) { + normalOffset = offset; + offset += 4; + } else { + normalOffset = 0; + } + + if (midUV) { + midUvOffset = offset; + offset += 4; + } else { + midUvOffset = 0; + } + + if (tangent) { + tangentOffset = offset; + offset += 4; + } else { + tangentOffset = 0; + } + + if (midBlock) { + midBlockOffset = offset; + offset += 4; + } else { + midBlockOffset = 0; + } + + 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.COLOR, ChunkShaderBindingPoints.ATTRIBUTE_COLOR, 8) + .addElement(DefaultChunkMeshAttributes.TEXTURE, ChunkShaderBindingPoints.ATTRIBUTE_TEXTURE, 12) + .addElement(DefaultChunkMeshAttributes.LIGHT_MATERIAL_INDEX, ChunkShaderBindingPoints.ATTRIBUTE_LIGHT_MATERIAL_INDEX, 16); + + if (blockId) { + VERTEX_FORMAT.addElement(IrisChunkMeshAttributes.BLOCK_ID, 11, blockIdOffset); + } + + if (normal) { + VERTEX_FORMAT.addElement(IrisChunkMeshAttributes.NORMAL, 10, normalOffset); + } + + if (midUV) { + VERTEX_FORMAT.addElement(IrisChunkMeshAttributes.MID_TEX_COORD, 12, midUvOffset); + } + + if (tangent) { + VERTEX_FORMAT.addElement(IrisChunkMeshAttributes.TANGENT, 13, tangentOffset); + } + + if (midBlock) { + VERTEX_FORMAT.addElement(IrisChunkMeshAttributes.MID_BLOCK, 14, midBlockOffset); + } + + + return classMap.computeIfAbsent(key, k -> new XHFPModelVertexType(VERTEX_FORMAT.build(), blockIdOffset, normalOffset, tangentOffset, midUvOffset, midBlockOffset)); + } +} diff --git a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/IrisModelVertexFormats.java b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/IrisModelVertexFormats.java index ebaf99d816..c77e88e336 100644 --- a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/IrisModelVertexFormats.java +++ b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/IrisModelVertexFormats.java @@ -3,5 +3,4 @@ import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; public class IrisModelVertexFormats { - public static final ChunkVertexType MODEL_VERTEX_XHFP = new XHFPModelVertexType(); } diff --git a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPModelVertexType.java b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPModelVertexType.java index 6328026df1..1b8b51f4bb 100644 --- a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPModelVertexType.java +++ b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPModelVertexType.java @@ -5,25 +5,30 @@ import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder; import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.impl.DefaultChunkMeshAttributes; +import net.irisshaders.iris.vertices.NormI8; +import net.irisshaders.iris.vertices.NormalHelper; +import net.minecraft.util.Mth; +import org.joml.Vector3f; /** * Like HFPModelVertexType, but extended to support Iris. The extensions aren't particularly efficient right now. */ public class XHFPModelVertexType implements ChunkVertexType { - public static final int STRIDE = 40; - - public static final GlVertexFormat VERTEX_FORMAT = GlVertexFormat.builder(STRIDE) - .addElement(DefaultChunkMeshAttributes.POSITION_HI, ChunkShaderBindingPoints.ATTRIBUTE_POSITION_HI, 0) - .addElement(DefaultChunkMeshAttributes.POSITION_LO, ChunkShaderBindingPoints.ATTRIBUTE_POSITION_LO, 4) - .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) - .addElement(IrisChunkMeshAttributes.MID_TEX_COORD, 12, 20) - .addElement(IrisChunkMeshAttributes.TANGENT, 13, 24) - .addElement(IrisChunkMeshAttributes.NORMAL, 10, 28) - .addElement(IrisChunkMeshAttributes.BLOCK_ID, 11, 32) - .addElement(IrisChunkMeshAttributes.MID_BLOCK, 14, 36) - .build(); + private final GlVertexFormat format; + private final int normalOffset; + private final int blockIdOffset; + private final int tangentOffset; + private final int midBlockOffset; + private final int midUvOffset; + + public XHFPModelVertexType(GlVertexFormat format, int blockIdOffset, int normalOffset, int tangentOffset, int midUvOffset, int midBlockOffset) { + this.format = format; + this.blockIdOffset = blockIdOffset; + this.normalOffset = normalOffset; + this.tangentOffset = tangentOffset; + this.midUvOffset = midUvOffset; + this.midBlockOffset = midBlockOffset; + } private static final int POSITION_MAX_VALUE = 65536; private static final int TEXTURE_MAX_VALUE = 32768; @@ -43,11 +48,11 @@ public static int encodeOld(float u, float v) { @Override public GlVertexFormat getVertexFormat() { - return VERTEX_FORMAT; + return format; } @Override public ChunkVertexEncoder getEncoder() { - return new XHFPTerrainVertex(); + return new XHFPTerrainVertex(blockIdOffset, normalOffset, tangentOffset, midUvOffset, midBlockOffset, format.getStride()); } } diff --git a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPTerrainVertex.java b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPTerrainVertex.java index b1ff6a8949..44b4cf0890 100644 --- a/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPTerrainVertex.java +++ b/common/src/main/java/net/irisshaders/iris/vertices/sodium/terrain/XHFPTerrainVertex.java @@ -18,8 +18,23 @@ public class XHFPTerrainVertex implements ChunkVertexEncoder, VertexEncoderInter private static final float MODEL_ORIGIN = 8.0f; private static final float MODEL_RANGE = 32.0f; private final Vector3f normal = new Vector3f(); + private final int blockIdOffset; + private final int normalOffset; + private final int tangentOffset; + private final int midBlockOffset; + private final int midUvOffset; + private final int stride; private BlockContextHolder contextHolder; + public XHFPTerrainVertex(int blockIdOffset, int normalOffset, int tangentOffset, int midUvOffset, int midBlockOffset, int stride) { + this.blockIdOffset = blockIdOffset; + this.normalOffset = normalOffset; + this.tangentOffset = tangentOffset; + this.midUvOffset = midUvOffset; + this.midBlockOffset = midBlockOffset; + this.stride = stride; + } + private static int packPositionHi(int x, int y, int z) { return (x >>> 10 & 1023) << 0 | (y >>> 10 & 1023) << 10 | (z >>> 10 & 1023) << 20; } @@ -93,22 +108,29 @@ public long write(long ptr, texCentroidU *= (1.0f / 4.0f); texCentroidV *= (1.0f / 4.0f); int midUV = XHFPModelVertexType.encodeOld(texCentroidU, texCentroidV); - NormalHelper.computeFaceNormalManual(normal, vertices[0].x, vertices[0].y, vertices[0].z, - vertices[1].x, vertices[1].y, vertices[1].z, - vertices[2].x, vertices[2].y, vertices[2].z, - vertices[3].x, vertices[3].y, vertices[3].z); - int packedNormal = NormI8.pack(normal); - int tangent = NormalHelper.computeTangent(normal.x, normal.y, normal.z, - vertices[0].x, vertices[0].y, vertices[0].z, vertices[0].u, vertices[0].v, - vertices[1].x, vertices[1].y, vertices[1].z, vertices[1].u, vertices[1].v, - vertices[2].x, vertices[2].y, vertices[2].z, vertices[2].u, vertices[2].v); - - if (tangent == -1) { - // Try calculating the second triangle + int packedNormal = 0; + if (normalOffset != 0 || tangentOffset != 0) { + NormalHelper.computeFaceNormalManual(normal, vertices[0].x, vertices[0].y, vertices[0].z, + vertices[1].x, vertices[1].y, vertices[1].z, + vertices[2].x, vertices[2].y, vertices[2].z, + vertices[3].x, vertices[3].y, vertices[3].z); + packedNormal = NormI8.pack(normal); + } + int tangent = 0; + + if (tangentOffset != 0) { tangent = NormalHelper.computeTangent(normal.x, normal.y, normal.z, - vertices[2].x, vertices[2].y, vertices[2].z, vertices[2].u, vertices[2].v, - vertices[3].x, vertices[3].y, vertices[3].z, vertices[3].u, vertices[3].v, - vertices[0].x, vertices[0].y, vertices[0].z, vertices[0].u, vertices[0].v); + vertices[0].x, vertices[0].y, vertices[0].z, vertices[0].u, vertices[0].v, + vertices[1].x, vertices[1].y, vertices[1].z, vertices[1].u, vertices[1].v, + vertices[2].x, vertices[2].y, vertices[2].z, vertices[2].u, vertices[2].v); + + if (tangent == -1) { + // Try calculating the second triangle + tangent = NormalHelper.computeTangent(normal.x, normal.y, normal.z, + vertices[2].x, vertices[2].y, vertices[2].z, vertices[2].u, vertices[2].v, + vertices[3].x, vertices[3].y, vertices[3].z, vertices[3].u, vertices[3].v, + vertices[0].x, vertices[0].y, vertices[0].z, vertices[0].u, vertices[0].v); + } } for (int i = 0; i < 4; i++) { @@ -129,16 +151,28 @@ public long write(long ptr, MemoryUtil.memPutInt(ptr + 12L, packTexture(u, v)); MemoryUtil.memPutInt(ptr + 16L, packLightAndData(light, material, section)); - MemoryUtil.memPutShort(ptr + 32, contextHolder.getBlockId()); - MemoryUtil.memPutShort(ptr + 34, contextHolder.getRenderType()); - MemoryUtil.memPutInt(ptr + 36, contextHolder.ignoreMidBlock() ? 0 : ExtendedDataHelper.computeMidBlock(vertex.x, vertex.y, vertex.z, contextHolder.getLocalPosX(), contextHolder.getLocalPosY(), contextHolder.getLocalPosZ())); - MemoryUtil.memPutByte(ptr + 39, contextHolder.getBlockEmission()); + if (blockIdOffset != 0) { + MemoryUtil.memPutShort(ptr + blockIdOffset, contextHolder.getBlockId()); + MemoryUtil.memPutShort(ptr + blockIdOffset + 2, contextHolder.getRenderType()); + } + + if (midBlockOffset != 0) { + MemoryUtil.memPutInt(ptr + midBlockOffset, contextHolder.ignoreMidBlock() ? 0 : ExtendedDataHelper.computeMidBlock(vertex.x, vertex.y, vertex.z, contextHolder.getLocalPosX(), contextHolder.getLocalPosY(), contextHolder.getLocalPosZ())); + MemoryUtil.memPutByte(ptr + midBlockOffset + 3, contextHolder.getBlockEmission()); + } + + if (midUvOffset != 0) { + MemoryUtil.memPutInt(ptr + midUvOffset, midUV); + } - MemoryUtil.memPutInt(ptr + 20, midUV); - MemoryUtil.memPutInt(ptr + 28, packedNormal); - MemoryUtil.memPutInt(ptr + 24, tangent); + if (normalOffset != 0) { + MemoryUtil.memPutInt(ptr + normalOffset, packedNormal); + } + if (tangentOffset != 0) { + MemoryUtil.memPutInt(ptr + tangentOffset, tangent); + } - ptr += XHFPModelVertexType.STRIDE; + ptr += stride; } return ptr; diff --git a/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderFlame.java b/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderFlame.java index 3b4ec841d4..7e3928ac15 100644 --- a/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderFlame.java +++ b/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderFlame.java @@ -29,7 +29,7 @@ public class MixinRenderFlame { "render(Lmekanism/common/entity/EntityFlame;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V" }, at = @At(value = "FIELD", target = "Lmekanism/client/render/MekanismRenderType;FLAME:Ljava/util/function/Function;")) private Function doNotSwitchShaders() { - if (IrisApi.getInstance().isShaderPackInUse()) { + if (Iris.isPackInUseQuick()) { return LightningHandler.MEKANISM_FLAME; } else { return (Function) MEKANISM_FLAME; diff --git a/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderMekasuit.java b/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderMekasuit.java index e95b74ebe0..c03d3f1fc1 100644 --- a/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderMekasuit.java +++ b/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinRenderMekasuit.java @@ -28,7 +28,7 @@ public class MixinRenderMekasuit { "Lmekanism/client/render/armor/MekaSuitArmor;render(Lnet/minecraft/client/model/HumanoidModel;Lnet/minecraft/client/renderer/MultiBufferSource;Lcom/mojang/blaze3d/vertex/PoseStack;IILmekanism/common/lib/Color;ZLnet/minecraft/world/entity/LivingEntity;Ljava/util/Map;Z)V" }, at = @At(value = "FIELD", target = "Lmekanism/client/render/MekanismRenderType;MEKASUIT:Lnet/minecraft/client/renderer/RenderType;")) private RenderType doNotSwitchShaders() { - if (IrisApi.getInstance().isShaderPackInUse() && ImmediateState.isRenderingLevel) { + if (Iris.isPackInUseQuick() && ImmediateState.isRenderingLevel) { return LightningHandler.MEKASUIT; } else { return (RenderType) MEKASUIT; diff --git a/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinVBOIE.java b/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinVBOIE.java index 4a89ed562a..bd508519e1 100644 --- a/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinVBOIE.java +++ b/neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinVBOIE.java @@ -1,5 +1,6 @@ package net.irisshaders.iris.mixin.forge; +import net.irisshaders.iris.Iris; import net.irisshaders.iris.api.v0.IrisApi; import net.irisshaders.iris.pipeline.programs.FallbackShader; import net.irisshaders.iris.pipeline.programs.ShaderAccess; @@ -17,7 +18,7 @@ public class MixinVBOIE { @Overwrite public static ShaderInstance getVboShader() { - if (!IrisApi.getInstance().isShaderPackInUse()) { + if (!Iris.isPackInUseQuick()) { return vboShader; } else { ShaderInstance shader = ShaderAccess.getIEVBOShader();