diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index a4808ba3cd..9fb698c1fc 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -44,9 +44,9 @@ public class Buildscript extends SimpleFabricProject { static final boolean SODIUM = true; - static final boolean CUSTOM_SODIUM = false; + static final boolean CUSTOM_SODIUM = true; static final String MC_VERSION = "1.20.4"; - static final String customSodiumName = "sodium-fabric-mc23w45a-0.5.3git.86b69d2-dirty.jar"; + static final String customSodiumName = "sodium-fabric-mc1.20.3-0.5.5+git.d01d1e8.jar"; private static final String[] SOURCE_SETS = new String[] { "main", diff --git a/src/main/java/net/coderbot/iris/pipeline/SodiumTerrainPipeline.java b/src/main/java/net/coderbot/iris/pipeline/SodiumTerrainPipeline.java index f1efa8c5af..4ec5a131d1 100644 --- a/src/main/java/net/coderbot/iris/pipeline/SodiumTerrainPipeline.java +++ b/src/main/java/net/coderbot/iris/pipeline/SodiumTerrainPipeline.java @@ -3,7 +3,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.primitives.Ints; import me.jellysquid.mods.sodium.client.gl.shader.ShaderLoader; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ModelQuadFormat; import net.coderbot.iris.gl.blending.AlphaTest; import net.coderbot.iris.gl.blending.BlendModeOverride; import net.coderbot.iris.gl.blending.BufferBlendOverride; @@ -270,7 +270,7 @@ public SodiumTerrainPipeline(WorldRenderingPipeline parent, ProgramSet programSe private static final Supplier> translucentDefault = () -> Optional.of(AlphaTest.ALWAYS); private static final Supplier> shadowDefault = () -> Optional.of(AlphaTests.ONE_TENTH_ALPHA); - public void patchShaders(ChunkVertexType vertexType) { + public void patchShaders(ModelQuadFormat vertexType) { ShaderAttributeInputs inputs = new ShaderAttributeInputs(true, true, false, true, true); Optional terrainSolidSource = first(programSet.getGbuffersTerrainSolid(), programSet.getGbuffersTerrain(), programSet.getGbuffersTexturedLit(), programSet.getGbuffersTextured(), programSet.getGbuffersBasic()); diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java b/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java index f41bd8793b..46daa7679d 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/TransformPatcher.java @@ -253,8 +253,8 @@ public TranslationUnit parseTranslationUnit(Root rootInstance, String input) { } } else { // patch the version number to at least 330 - if (version.number < 330) { - versionStatement.version = Version.GLSL33; + if (version.number < 450) { + versionStatement.version = Version.GLSL45; } versionStatement.profile = Profile.CORE; diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/transformer/SodiumTransformer.java b/src/main/java/net/coderbot/iris/pipeline/transform/transformer/SodiumTransformer.java index 1ca0780d55..fd7bd593a7 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/transformer/SodiumTransformer.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/transformer/SodiumTransformer.java @@ -29,6 +29,7 @@ public static void transform( CommonTransformer.transform(t, tree, root, parameters, false); replaceMidTexCoord(t, tree, root, 1.0f / 65536.0f); + replaceMCEntity(t, tree, root); root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix0, "mat4(1.0)"); root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix1, "iris_LightmapTextureMatrix"); @@ -70,11 +71,11 @@ public static void transform( } else { root.replaceReferenceExpressions(t, "gl_Color", "vec4(1.0)"); } + root.replaceReferenceExpressions(t, "at_tangent", "iris_Tangent"); if (parameters.type.glShaderType == ShaderType.VERTEX) { if (parameters.inputs.hasNormal()) { root.rename("gl_Normal", "iris_Normal"); - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "in vec3 iris_Normal;"); } else { root.replaceReferenceExpressions(t, "gl_Normal", "vec3(0.0, 0.0, 1.0)"); } @@ -110,8 +111,8 @@ public static void transform( "uniform mat4 iris_ProjectionMatrix;", "uniform mat4 iris_ModelViewMatrix;", "uniform vec3 u_RegionOffset;", - // _draw_translation replaced with Chunks[_draw_id].offset.xyz - "vec4 getVertexPosition() { return vec4(_vert_position + u_RegionOffset + _get_draw_translation(_draw_id), 1.0); }"); + // _draw_translation replaced with Chunks[_mesh_id].offset.xyz + "vec4 getVertexPosition() { return vec4(_vert_position + _get_draw_translation(_mesh_id), 1.0); }"); root.replaceReferenceExpressions(t, "gl_Vertex", "getVertexPosition()"); // inject here so that _vert_position is available to the above. (injections @@ -135,33 +136,106 @@ public static void injectVertInit( TranslationUnit tree, Root root, SodiumParameters parameters) { - String separateAo = BlockRenderingSettings.INSTANCE.shouldUseSeparateAo() ? "a_Color" : "vec4(a_Color.rgb * a_Color.a, 1.0)"; + String separateAo = "vec4(((color.xyz >> (corner_index << 3)) & 0xFFu) / 255.0, unpackUnorm4x8(color.a).wzyx[corner_index])"; tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_FUNCTIONS, + """ + struct IrisQuad { + uvec3 position_hi; // offset: 0 size: 16 + uvec3 position_lo; // offset: 16 size: 16 + + uvec4 color; // offset: 32 size: 16 + + uvec2 tex_diffuse_hi; // offset: 48 size: 8 + uvec2 tex_diffuse_lo; // offset: 56 size: 8 + + uvec2 light; // offset: 64 size: 8 + + uint material; // offset: 72 size: 4 + uint mesh_id; // offset: 76 size: 4 + + uint midTexCoord; // offset: 80 size: 4 + uint normal; // offset: 84 size: 4 + uint tangent; // offset: 88 size: 4 + uint blockInfo; // offset: 92 size: 4 + // midBlock users mald for now + }; + """, + """ + layout(std430, binding = 15) buffer QuadBuffer { + IrisQuad ssbo_Quads[]; + }; + """, + """ + vec3 _unpack_position(int quad_index, int corner_index) { + return vec3( + ((ssbo_Quads[quad_index].position_lo >> (corner_index << 3)) & 0xFFu) | + (((ssbo_Quads[quad_index].position_hi >> (corner_index << 3)) & 0xFFu) << 8) + ) * 0.00048828125 - 8.0; + } + """, + """ + vec2 _unpack_texcoord(int quad_index, int corner_index) { + return vec2( + ((ssbo_Quads[quad_index].tex_diffuse_lo >> (corner_index << 3)) & 0xFFu) | + (((ssbo_Quads[quad_index].tex_diffuse_hi >> (corner_index << 3)) & 0xFFu) << 8) + ) / 65535.0; + } + """, + """ + const vec2 CORNERS[4] = vec2[] ( + vec2(0.0, 0.0), + vec2(1.0, 0.0), + vec2(1.0, 1.0), + vec2(0.0, 1.0) + ); + """, // translated from sodium's chunk_vertex.glsl "vec3 _vert_position;", "vec2 _vert_tex_diffuse_coord;", - "ivec2 _vert_tex_light_coord;", + "vec2 _vert_tex_light_coord;", "vec4 _vert_color;", - "uint _draw_id;", + "vec3 iris_Normal;", + "vec2 iris_Entity;", + "vec2 mc_midTexCoord;", + "vec4 iris_Tangent;", + "uint _mesh_id;", "const uint MATERIAL_USE_MIP_OFFSET = 0u;", "float _material_mip_bias(uint material) {\n" + " return ((material >> MATERIAL_USE_MIP_OFFSET) & 1u) != 0u ? 0.0f : -4.0f;\n" + "}", "void _vert_init() {" + - "_vert_position = (vec3(a_PosId.xyz) * 0.00048828125 + -8.0" - + ");" + - "_vert_tex_diffuse_coord = (a_TexCoord * 1.52587891E-5);" + - "_vert_tex_light_coord = a_LightCoord;" + + + "int quad_index = gl_VertexID >> 2;" + + "int corner_index = gl_VertexID & 3;" + + "int wtf = gl_VertexID % 4;" + + "vec2 v_RelCoord = CORNERS[corner_index];" + + "uvec4 color = ssbo_Quads[quad_index].color;" + + "vec4 light01 = unpackUnorm4x8(ssbo_Quads[quad_index].light[0]);" + // (c0.x, c0.y, c1.x, c1.y) + "vec4 light23 = unpackUnorm4x8(ssbo_Quads[quad_index].light[1]);" + // (c3.x, c3.y, c2.x, c2.y) + + """ + vec2 uv = mix( + mix(light01.xy, light01.zw, v_RelCoord.x), + mix(light23.zw, light23.xy, v_RelCoord.x), + v_RelCoord.y);""" + + + "_vert_tex_light_coord = clamp(uv, vec2(0.5 / 16.0), vec2(15.5 / 16.0));" + + "_vert_position = _unpack_position(quad_index, corner_index);" + + "_vert_tex_diffuse_coord = _unpack_texcoord(quad_index, corner_index);" + + "iris_Normal = unpackUnorm4x8(ssbo_Quads[quad_index].normal).xyz;" + + "iris_Tangent = unpackUnorm4x8(ssbo_Quads[quad_index].tangent);" + + "iris_Entity = vec2(ssbo_Quads[quad_index].blockInfo & 0xFFFF, ssbo_Quads[quad_index].blockInfo >> 16);" + + "mc_midTexCoord = unpackUnorm2x16(ssbo_Quads[quad_index].midTexCoord);" + "_vert_color = " + separateAo + ";" + - "_draw_id = (a_PosId.w >> 8u) & 0xFFu; }", + "_mesh_id = ssbo_Quads[quad_index].mesh_id; }", "uvec3 _get_relative_chunk_coord(uint pos) {\n" + " // Packing scheme is defined by LocalSectionIndex\n" + " return uvec3(pos) >> uvec3(5u, 0u, 2u) & uvec3(7u, 3u, 7u);\n" + "}", "vec3 _get_draw_translation(uint pos) {\n" + - " return _get_relative_chunk_coord(pos) * vec3(16.0f);\n" + - "}\n"); + " return u_RegionOffset + _get_relative_chunk_coord(pos) * vec3(16.0f);\n" + + "}"); addIfNotExists(root, t, tree, "a_PosId", Type.U32VEC4, StorageQualifier.StorageType.IN); addIfNotExists(root, t, tree, "a_TexCoord", Type.F32VEC2, StorageQualifier.StorageType.IN); addIfNotExists(root, t, tree, "a_Color", Type.F32VEC4, StorageQualifier.StorageType.IN); @@ -201,21 +275,72 @@ public static void replaceMidTexCoord(ASTParser t, case BOOL: return; case FLOAT32: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "float iris_MidTex = (mc_midTexCoord.x * " + textureScale + ").x;"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "float iris_MidTex;"); + tree.prependMainFunctionBody(t, "iris_MidTex = (mc_midTexCoord.x * " + textureScale + ").x;"); break; case F32VEC2: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec2 iris_MidTex = (mc_midTexCoord.xy * " + textureScale + ").xy;"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec2 iris_MidTex;"); + tree.prependMainFunctionBody(t, "iris_MidTex = (mc_midTexCoord.xy * " + textureScale + ").xy;"); break; case F32VEC3: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec3 iris_MidTex = vec3(mc_midTexCoord.xy * " + textureScale + ", 0.0);"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec3 iris_MidTex;"); + tree.prependMainFunctionBody(t, "iris_MidTex = vec3((mc_midTexCoord.xy * " + textureScale + ").xy, 0.0);"); break; case F32VEC4: - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec4 iris_MidTex = vec4(mc_midTexCoord.xy * " + textureScale + ", 0.0, 1.0);"); + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec4 iris_MidTex;"); + tree.prependMainFunctionBody(t, "iris_MidTex = vec4((mc_midTexCoord.xy * " + textureScale + ").xy, 0.0, 1.0);"); break; default: throw new IllegalStateException("Somehow got a midTexCoord that is *above* 4 dimensions???"); } - tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "in vec2 mc_midTexCoord;"); + } + + public static void replaceMCEntity(ASTParser t, + TranslationUnit tree, Root root) { + Type dimension = Type.BOOL; + for (Identifier id : root.identifierIndex.get("mc_Entity")) { + TypeAndInitDeclaration initDeclaration = (TypeAndInitDeclaration) id.getAncestor( + 2, 0, TypeAndInitDeclaration.class::isInstance); + if (initDeclaration == null) { + continue; + } + DeclarationExternalDeclaration declaration = (DeclarationExternalDeclaration) initDeclaration.getAncestor( + 1, 0, DeclarationExternalDeclaration.class::isInstance); + if (declaration == null) { + continue; + } + if (initDeclaration.getType().getTypeSpecifier() instanceof BuiltinNumericTypeSpecifier numeric) { + dimension = numeric.type; + + declaration.detachAndDelete(); + initDeclaration.detachAndDelete(); + id.detachAndDelete(); + break; + } + } + + switch (dimension) { + case BOOL: + return; + case FLOAT32: + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "float mc_Entity;"); + tree.prependMainFunctionBody(t, "mc_Entity = iris_Entity.x;"); + break; + case F32VEC2: + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec2 mc_Entity;"); + tree.prependMainFunctionBody(t, "mc_Entity = iris_Entity.xy;"); + break; + case F32VEC3: + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec3 mc_Entity;"); + tree.prependMainFunctionBody(t, "mc_Entity = vec3(iris_Entity.xy, 0.0);"); + break; + case F32VEC4: + tree.parseAndInjectNode(t, ASTInjectionPoint.BEFORE_DECLARATIONS, "vec4 mc_Entity;"); + tree.prependMainFunctionBody(t, "mc_Entity = vec4(iris_Entity.xy, 0.0, 1.0);"); + break; + default: + throw new IllegalStateException("Somehow got a midTexCoord that is *above* 4 dimensions???"); + } } } diff --git a/src/main/java/net/coderbot/iris/vertices/NormalHelper.java b/src/main/java/net/coderbot/iris/vertices/NormalHelper.java index 44aca7fff9..cb746dab37 100644 --- a/src/main/java/net/coderbot/iris/vertices/NormalHelper.java +++ b/src/main/java/net/coderbot/iris/vertices/NormalHelper.java @@ -85,6 +85,47 @@ public static void computeFaceNormal(@NotNull Vector3f saveTo, QuadView q) { saveTo.set(normX, normY, normZ); } + /** + * Computes the face normal of the given quad and saves it in the provided non-null vector. + * + *

Assumes counter-clockwise winding order, which is the norm. + * Expects convex quads with all points co-planar. + */ + public static int computeFaceNormalCompact(float x0, float y0, float z0, + float x1, float y1, float z1, + float x2, float y2, float z2, + float x3, float y3, float z3) { +// final Direction nominalFace = q.nominalFace(); +// +// if (GeometryHelper.isQuadParallelToFace(nominalFace, q)) { +// Vec3i vec = nominalFace.getVector(); +// saveTo.set(vec.getX(), vec.getY(), vec.getZ()); +// return; +// } + + + final float dx0 = x2 - x0; + final float dy0 = y2 - y0; + final float dz0 = z2 - z0; + final float dx1 = x3 - x1; + final float dy1 = y3 - y1; + final float dz1 = z3 - z1; + + float normX = dy0 * dz1 - dz0 * dy1; + float normY = dz0 * dx1 - dx0 * dz1; + float normZ = dx0 * dy1 - dy0 * dx1; + + float l = (float) Math.sqrt(normX * normX + normY * normY + normZ * normZ); + + if (l != 0) { + normX /= l; + normY /= l; + normZ /= l; + } + + return NormI8.pack(normX, normY, normZ, 0); + } + /** * Computes the face normal of the given quad with a flipped order and saves it in the provided non-null vector. * diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java index 56bcd1cd3e..1a0629ee4b 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java @@ -7,7 +7,7 @@ import me.jellysquid.mods.sodium.client.render.chunk.shader.ChunkShaderOptions; import me.jellysquid.mods.sodium.client.render.chunk.terrain.DefaultTerrainRenderPasses; import me.jellysquid.mods.sodium.client.render.chunk.terrain.TerrainRenderPass; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ModelQuadFormat; import net.coderbot.iris.Iris; import net.coderbot.iris.compat.sodium.impl.IrisChunkShaderBindingPoints; import net.coderbot.iris.gl.blending.AlphaTest; @@ -139,7 +139,7 @@ private List getBufferBlendOverride(IrisTerrainPass pass, S } @Nullable - private GlProgram createShader(IrisTerrainPass pass, SodiumTerrainPipeline pipeline, ChunkVertexType vertexType) { + private GlProgram createShader(IrisTerrainPass pass, SodiumTerrainPipeline pipeline, ModelQuadFormat vertexType) { GlShader vertShader = createVertexShader(pass, pipeline); GlShader geomShader = createGeometryShader(pass, pipeline); GlShader fragShader = createFragmentShader(pass, pipeline); @@ -225,7 +225,7 @@ private SodiumTerrainPipeline getSodiumTerrainPipeline() { } } - public void createShaders(SodiumTerrainPipeline pipeline, ChunkVertexType vertexType) { + public void createShaders(SodiumTerrainPipeline pipeline, ModelQuadFormat vertexType) { if (pipeline != null) { pipeline.patchShaders(vertexType); for (IrisTerrainPass pass : IrisTerrainPass.values()) { @@ -249,7 +249,7 @@ public void createShaders(SodiumTerrainPipeline pipeline, ChunkVertexType vertex } @Nullable - public GlProgram getProgramOverride(TerrainRenderPass pass, ChunkVertexType vertexType) { + public GlProgram getProgramOverride(TerrainRenderPass pass, ModelQuadFormat vertexType) { if (versionCounterForSodiumShaderReload != Iris.getPipelineManager().getVersionCounterForSodiumShaderReload()) { versionCounterForSodiumShaderReload = Iris.getPipelineManager().getVersionCounterForSodiumShaderReload(); deleteShaders(); diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/QuadViewTerrain.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/QuadViewTerrain.java deleted file mode 100644 index 3eeed94b06..0000000000 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/QuadViewTerrain.java +++ /dev/null @@ -1,65 +0,0 @@ -package net.coderbot.iris.compat.sodium.impl.vertex_format.terrain_xhfp; - -import net.coderbot.iris.vertices.QuadView; -import org.lwjgl.system.MemoryUtil; - -import java.nio.ByteBuffer; - -public abstract class QuadViewTerrain implements QuadView { - long writePointer; - int stride; - - @Override - public float x(int index) { - return XHFPModelVertexType.decodePosition(getShort(writePointer - stride * (3 - index))); - } - - @Override - public float y(int index) { - return XHFPModelVertexType.decodePosition(getShort(writePointer + 2 - stride * (3 - index))); - } - - @Override - public float z(int index) { - return XHFPModelVertexType.decodePosition(getShort(writePointer + 4 - stride * (3 - index))); - } - - @Override - public float u(int index) { - return XHFPModelVertexType.decodeBlockTexture(getShort(writePointer + 12 - stride * (3 - index))); - } - - @Override - public float v(int index) { - return XHFPModelVertexType.decodeBlockTexture(getShort(writePointer + 14 - stride * (3 - index))); - } - - abstract short getShort(long writePointer); - - public static class QuadViewTerrainUnsafe extends QuadViewTerrain { - public void setup(long writePointer, int stride) { - this.writePointer = writePointer; - this.stride = stride; - } - - @Override - short getShort(long writePointer) { - return MemoryUtil.memGetShort(writePointer); - } - } - - public static class QuadViewTerrainNio extends QuadViewTerrain { - private ByteBuffer buffer; - - public void setup(ByteBuffer buffer, int writePointer, int stride) { - this.buffer = buffer; - this.writePointer = writePointer; - this.stride = stride; - } - - @Override - short getShort(long writePointer) { - return buffer.getShort((int) writePointer); - } - } -} diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPEncoder.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPEncoder.java new file mode 100644 index 0000000000..1965528c17 --- /dev/null +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPEncoder.java @@ -0,0 +1,131 @@ +package net.coderbot.iris.compat.sodium.impl.vertex_format.terrain_xhfp; + +import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.Material; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ModelQuadEncoder; +import net.caffeinemc.mods.sodium.api.util.ColorABGR; +import net.coderbot.iris.compat.sodium.impl.block_context.BlockContextHolder; +import net.coderbot.iris.compat.sodium.impl.block_context.ContextAwareVertexWriter; +import net.coderbot.iris.vertices.NormI8; +import net.coderbot.iris.vertices.NormalHelper; +import org.lwjgl.system.MemoryUtil; + +public class XHFPEncoder implements ModelQuadEncoder, ContextAwareVertexWriter { + + private BlockContextHolder contextHolder; + private boolean flipUpcomingNormal; + + private static final int POSITION_MAX_VALUE = 65536; + private static final int TEXTURE_MAX_VALUE = 65536; + + private static final float MODEL_ORIGIN = 8.0f; + private static final float MODEL_SCALE = 32.0f; + + @Override + public long write(long ptr, Material material, Vertex[] vertices, int sectionIndex) { + MemoryUtil.memSet(ptr, 0, XHFPModelVertexType.STRIDE); + + MemoryUtil.memPutInt(ptr + 0, packU16x2_hi(encodePosition(vertices[3].x), encodePosition(vertices[2].x), encodePosition(vertices[1].x), encodePosition(vertices[0].x))); + MemoryUtil.memPutInt(ptr + 4, packU16x2_hi(encodePosition(vertices[3].y), encodePosition(vertices[2].y), encodePosition(vertices[1].y), encodePosition(vertices[0].y))); + MemoryUtil.memPutInt(ptr + 8, packU16x2_hi(encodePosition(vertices[3].z), encodePosition(vertices[2].z), encodePosition(vertices[1].z), encodePosition(vertices[0].z))); + + MemoryUtil.memPutInt(ptr + 16, packU16x2_lo(encodePosition(vertices[3].x), encodePosition(vertices[2].x), encodePosition(vertices[1].x), encodePosition(vertices[0].x))); + MemoryUtil.memPutInt(ptr + 20, packU16x2_lo(encodePosition(vertices[3].y), encodePosition(vertices[2].y), encodePosition(vertices[1].y), encodePosition(vertices[0].y))); + MemoryUtil.memPutInt(ptr + 24, packU16x2_lo(encodePosition(vertices[3].z), encodePosition(vertices[2].z), encodePosition(vertices[1].z), encodePosition(vertices[0].z))); + + MemoryUtil.memPutInt(ptr + 32, packU8x4(ColorABGR.unpackRed(vertices[0].color), ColorABGR.unpackRed(vertices[1].color), ColorABGR.unpackRed(vertices[2].color), ColorABGR.unpackRed(vertices[3].color))); + MemoryUtil.memPutInt(ptr + 36, packU8x4(ColorABGR.unpackGreen(vertices[0].color), ColorABGR.unpackGreen(vertices[1].color), ColorABGR.unpackGreen(vertices[2].color), ColorABGR.unpackGreen(vertices[3].color))); + MemoryUtil.memPutInt(ptr + 40, packU8x4(ColorABGR.unpackBlue(vertices[0].color), ColorABGR.unpackBlue(vertices[1].color), ColorABGR.unpackBlue(vertices[2].color), ColorABGR.unpackBlue(vertices[3].color))); + MemoryUtil.memPutInt(ptr + 44, packU8x4(ColorABGR.unpackAlpha(vertices[0].color), ColorABGR.unpackAlpha(vertices[1].color), ColorABGR.unpackAlpha(vertices[2].color), ColorABGR.unpackAlpha(vertices[3].color))); + + MemoryUtil.memPutInt(ptr + 48, packU16x2_hi(encodeTexture(vertices[3].u), encodeTexture(vertices[2].u), encodeTexture(vertices[1].u), encodeTexture(vertices[0].u))); + MemoryUtil.memPutInt(ptr + 52, packU16x2_hi(encodeTexture(vertices[3].v), encodeTexture(vertices[2].v), encodeTexture(vertices[1].v), encodeTexture(vertices[0].v))); + + MemoryUtil.memPutInt(ptr + 56, packU16x2_lo(encodeTexture(vertices[3].u), encodeTexture(vertices[2].u), encodeTexture(vertices[1].u), encodeTexture(vertices[0].u))); + MemoryUtil.memPutInt(ptr + 60, packU16x2_lo(encodeTexture(vertices[3].v), encodeTexture(vertices[2].v), encodeTexture(vertices[1].v), encodeTexture(vertices[0].v))); + + MemoryUtil.memPutInt(ptr + 64, packU16x2(encodeLight(vertices[0].light), encodeLight(vertices[1].light))); + MemoryUtil.memPutInt(ptr + 68, packU16x2(encodeLight(vertices[2].light), encodeLight(vertices[3].light))); + + MemoryUtil.memPutInt(ptr + 72, material.bits()); + MemoryUtil.memPutInt(ptr + 76, sectionIndex); + + float midU = (vertices[0].u + vertices[1].u + vertices[2].u + vertices[3].u) * 0.25f; + float midV = (vertices[0].v + vertices[1].v + vertices[2].v + vertices[3].v) * 0.25f; + + MemoryUtil.memPutShort(ptr + 80, (short) encodeTexture(midU)); + MemoryUtil.memPutShort(ptr + 82, (short) encodeTexture(midV)); + int normal = NormalHelper.computeFaceNormalCompact(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); + MemoryUtil.memPutInt(ptr + 84, normal); + MemoryUtil.memPutInt(ptr + 88, NormalHelper.computeTangent(NormI8.unpackX(normal), NormI8.unpackY(normal), NormI8.unpackZ(normal), + 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 + )); + + MemoryUtil.memPutInt(ptr + 92, packU16x2(contextHolder.blockId, contextHolder.renderType)); + + // TODO MemoryUtil.memPutInt(ptr + 36, contextHolder.ignoreMidBlock ? 0 : ExtendedDataHelper.computeMidBlock(vertex.x, vertex.y, vertex.z, contextHolder.localPosX, contextHolder.localPosY, contextHolder.localPosZ)); + return ptr + XHFPModelVertexType.STRIDE; + } + + + private static int encodeLight(int light) { + return ((light >> 0) & 0xFF) | + ((light >> 16) & 0xFF) << 8; + } + + private static int packU16x2(int a, int b) { + return ((a & 0xFFFF) << 0) | ((b & 0xFFFF) << 16); + } + + private static int packU16x2_hi(int x, int y, int w, int z) { + return (((x & 0xFF00) >> 8) << 24) | + (((y & 0xFF00) >> 8) << 16) | + (((w & 0xFF00) >> 8) << 8) | + (((z & 0xFF00) >> 8) << 0); + } + + private static int packU16x2_lo(int x, int y, int w, int z) { + return ((x & 0x00FF) << 24) | + ((y & 0x00FF) << 16) | + ((w & 0x00FF) << 8) | + ((z & 0x00FF) << 0); + } + + private static int packU8x4(int x, int y, int w, int z) { + return ((x & 0xFF) << 24) | + ((y & 0xFF) << 16) | + ((w & 0xFF) << 8) | + ((z & 0xFF) << 0); + } + + + private static int encodePosition(float value) { + return (int) ((MODEL_ORIGIN + value) * (POSITION_MAX_VALUE / MODEL_SCALE)); + } + + private static int encodeBlockLight(int light) { + return (light >> 0) & 0xFF; + } + + private static int encodeSkyLight(int light) { + return (light >> 16) & 0xFF; + } + + private static int encodeTexture(float value) { + return (int) (Math.min(0.99999997F, value) * TEXTURE_MAX_VALUE); + } + + + + + @Override + public void iris$setContextHolder(BlockContextHolder holder) { + contextHolder = holder; + } + + @Override + public void flipUpcomingQuadNormal() { + flipUpcomingNormal = true; + } +} diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java index 827aab09fa..4ebc322c31 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPModelVertexType.java @@ -1,65 +1,25 @@ package net.coderbot.iris.compat.sodium.impl.vertex_format.terrain_xhfp; -import me.jellysquid.mods.sodium.client.gl.attribute.GlVertexAttributeFormat; -import me.jellysquid.mods.sodium.client.gl.attribute.GlVertexFormat; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkMeshAttribute; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; -import net.coderbot.iris.compat.sodium.impl.vertex_format.IrisChunkMeshAttributes; -import net.coderbot.iris.compat.sodium.impl.vertex_format.IrisGlVertexAttributeFormat; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ModelQuadEncoder; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ModelQuadFormat; +import net.caffeinemc.mods.sodium.api.util.ColorABGR; +import net.coderbot.iris.compat.sodium.impl.block_context.BlockContextHolder; +import net.coderbot.iris.compat.sodium.impl.block_context.ContextAwareVertexWriter; +import net.coderbot.iris.vertices.NormI8; +import net.coderbot.iris.vertices.NormalHelper; +import org.lwjgl.system.MemoryUtil; -/** - * 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(ChunkMeshAttribute.class, STRIDE) - .addElement(IrisChunkMeshAttributes.POSITION_MATERIAL_MESH, 0, GlVertexAttributeFormat.UNSIGNED_SHORT, 4, false, true) - .addElement(IrisChunkMeshAttributes.COLOR_SHADE, 8, GlVertexAttributeFormat.UNSIGNED_BYTE, 4, true, false) - .addElement(IrisChunkMeshAttributes.BLOCK_TEXTURE, 12, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, false) - .addElement(IrisChunkMeshAttributes.LIGHT_TEXTURE, 16, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, true) - .addElement(IrisChunkMeshAttributes.MID_TEX_COORD, 20, GlVertexAttributeFormat.UNSIGNED_SHORT, 2, false, false) - .addElement(IrisChunkMeshAttributes.TANGENT, 24, IrisGlVertexAttributeFormat.BYTE, 4, true, false) - .addElement(IrisChunkMeshAttributes.NORMAL, 28, IrisGlVertexAttributeFormat.BYTE, 3, true, false) - .addElement(IrisChunkMeshAttributes.BLOCK_ID, 32, IrisGlVertexAttributeFormat.SHORT, 2, false, false) - .addElement(IrisChunkMeshAttributes.MID_BLOCK, 36, IrisGlVertexAttributeFormat.BYTE, 3, false, false) - .addElement(ChunkMeshAttribute.VERTEX_DATA, 40, IrisGlVertexAttributeFormat.BYTE, 0, false, false) - .build(); +public class XHFPModelVertexType implements ModelQuadFormat { - private static final int POSITION_MAX_VALUE = 65536; - private static final int TEXTURE_MAX_VALUE = 65536; - - private static final float MODEL_ORIGIN = 8.0f; - private static final float MODEL_RANGE = 32.0f; - private static final float MODEL_SCALE = MODEL_RANGE / POSITION_MAX_VALUE; - - private static final float MODEL_SCALE_INV = POSITION_MAX_VALUE / MODEL_RANGE; - - private static final float TEXTURE_SCALE = (1.0f / TEXTURE_MAX_VALUE); + public static final int STRIDE = 96; @Override - public GlVertexFormat getVertexFormat() { - return VERTEX_FORMAT; + public ModelQuadEncoder getEncoder() { + return new XHFPEncoder(); } @Override - public ChunkVertexEncoder getEncoder() { - return new XHFPTerrainVertex(); - } - - static short encodeBlockTexture(float value) { - return (short) (Math.min(0.99999997F, value) * TEXTURE_MAX_VALUE); - } - - static float decodeBlockTexture(short raw) { - return (raw & 0xFFFF) * TEXTURE_SCALE; - } - - static short encodePosition(float v) { - return (short) ((MODEL_ORIGIN + v) * MODEL_SCALE_INV); - } - - static float decodePosition(short raw) { - return (raw & 0xFFFF) * MODEL_SCALE - MODEL_ORIGIN; + public int getStride() { + return STRIDE; } } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPTerrainVertex.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPTerrainVertex.java deleted file mode 100644 index c29be96ab5..0000000000 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/vertex_format/terrain_xhfp/XHFPTerrainVertex.java +++ /dev/null @@ -1,165 +0,0 @@ -package net.coderbot.iris.compat.sodium.impl.vertex_format.terrain_xhfp; - -import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.Material; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder; -import net.coderbot.iris.compat.sodium.impl.block_context.BlockContextHolder; -import net.coderbot.iris.compat.sodium.impl.block_context.ContextAwareVertexWriter; -import net.coderbot.iris.vertices.NormI8; -import org.joml.Vector3f; -import net.coderbot.iris.vertices.ExtendedDataHelper; -import net.coderbot.iris.vertices.NormalHelper; -import org.lwjgl.system.MemoryUtil; - -import static net.coderbot.iris.compat.sodium.impl.vertex_format.terrain_xhfp.XHFPModelVertexType.STRIDE; - -public class XHFPTerrainVertex implements ChunkVertexEncoder, ContextAwareVertexWriter { - private final QuadViewTerrain.QuadViewTerrainUnsafe quad = new QuadViewTerrain.QuadViewTerrainUnsafe(); - private final Vector3f normal = new Vector3f(); - - private BlockContextHolder contextHolder; - - private int vertexCount; - private float uSum; - private float vSum; - private boolean flipUpcomingNormal; - - // TODO: FIX - - /*@Override - public void copyQuadAndFlipNormal() { - ensureCapacity(4); - - MemoryUtil.memCopy(this.writePointer - STRIDE * 4, this.writePointer, STRIDE * 4); - - // Now flip vertex normals - int packedNormal = MemoryUtil.memGetInt(this.writePointer + 32); - int inverted = NormalHelper.invertPackedNormal(packedNormal); - - MemoryUtil.memPutInt(this.writePointer + 32, inverted); - MemoryUtil.memPutInt(this.writePointer + 32 + STRIDE, inverted); - MemoryUtil.memPutInt(this.writePointer + 32 + STRIDE * 2, inverted); - MemoryUtil.memPutInt(this.writePointer + 32 + STRIDE * 3, inverted); - - // We just wrote 4 vertices, advance by 4 - for (int i = 0; i < 4; i++) { - this.advance(); - } - - // Ensure vertices are flushed - this.flush(); - }*/ - - @Override - public void iris$setContextHolder(BlockContextHolder holder) { - this.contextHolder = holder; - } - - @Override - public void flipUpcomingQuadNormal() { - flipUpcomingNormal = true; - } - - @Override - public long write(long ptr, - Material material, Vertex vertex, int chunkId) { - uSum += vertex.u; - vSum += vertex.v; - vertexCount++; - - MemoryUtil.memPutShort(ptr + 0L, XHFPModelVertexType.encodePosition(vertex.x)); - MemoryUtil.memPutShort(ptr + 2L, XHFPModelVertexType.encodePosition(vertex.y)); - MemoryUtil.memPutShort(ptr + 4L, XHFPModelVertexType.encodePosition(vertex.z)); - MemoryUtil.memPutByte(ptr + 6L, (byte) material.bits()); - MemoryUtil.memPutByte(ptr + 7L, (byte) chunkId); - - MemoryUtil.memPutInt(ptr + 8, vertex.color); - - MemoryUtil.memPutShort(ptr + 12, XHFPModelVertexType.encodeBlockTexture(vertex.u)); - MemoryUtil.memPutShort(ptr + 14, XHFPModelVertexType.encodeBlockTexture(vertex.v)); - - MemoryUtil.memPutInt(ptr + 16, vertex.light); - - MemoryUtil.memPutShort(ptr + 32, contextHolder.blockId); - MemoryUtil.memPutShort(ptr + 34, contextHolder.renderType); - MemoryUtil.memPutInt(ptr + 36, contextHolder.ignoreMidBlock ? 0 : ExtendedDataHelper.computeMidBlock(vertex.x, vertex.y, vertex.z, contextHolder.localPosX, contextHolder.localPosY, contextHolder.localPosZ)); - - if (vertexCount == 4) { - vertexCount = 0; - - // FIXME - // The following logic is incorrect because OpenGL denormalizes shorts by dividing by 65535. The atlas is - // based on power-of-two values and so a normalization factor that is not a power of two causes the values - // used in the shader to be off by enough to cause visual errors. These are most noticeable on 1.18 with POM - // on block edges. - // - // The only reliable way that this can be fixed is to apply the same shader transformations to midTexCoord - // as Sodium does to the regular texture coordinates - dividing them by the correct power-of-two value inside - // of the shader instead of letting OpenGL value normalization do the division. However, this requires - // fragile patching that is not yet possible. - // - // As a temporary solution, the normalized shorts have been replaced with regular floats, but this takes up - // an extra 4 bytes per vertex. - - // NB: Be careful with the math here! A previous bug was caused by midU going negative as a short, which - // was sign-extended into midTexCoord, causing midV to have garbage (likely NaN data). If you're touching - // this code, be aware of that, and don't introduce those kinds of bugs! - // - // Also note that OpenGL takes shorts in the range of [0, 65535] and transforms them linearly to [0.0, 1.0], - // so multiply by 65535, not 65536. - // - // TODO: Does this introduce precision issues? Do we need to fall back to floats here? This might break - // with high resolution texture packs. -// int midU = (int)(65535.0F * Math.min(uSum * 0.25f, 1.0f)) & 0xFFFF; -// int midV = (int)(65535.0F * Math.min(vSum * 0.25f, 1.0f)) & 0xFFFF; -// int midTexCoord = (midV << 16) | midU; - - uSum *= 0.25f; - vSum *= 0.25f; - - short midU = XHFPModelVertexType.encodeBlockTexture(uSum); - short midV = XHFPModelVertexType.encodeBlockTexture(vSum); - - MemoryUtil.memPutShort(ptr + 20, midU); - MemoryUtil.memPutShort(ptr + 20 - STRIDE, midU); - MemoryUtil.memPutShort(ptr + 20 - STRIDE * 2, midU); - MemoryUtil.memPutShort(ptr + 20 - STRIDE * 3, midU); - - MemoryUtil.memPutShort(ptr + 22, midV); - MemoryUtil.memPutShort(ptr + 22 - STRIDE, midV); - MemoryUtil.memPutShort(ptr + 22 - STRIDE * 2, midV); - MemoryUtil.memPutShort(ptr + 22 - STRIDE * 3, midV); - - uSum = 0; - vSum = 0; - - // normal computation - // Implementation based on the algorithm found here: - // https://github.com/IrisShaders/ShaderDoc/blob/master/vertex-format-extensions.md#surface-normal-vector - - quad.setup(ptr, STRIDE); - if (flipUpcomingNormal) { - NormalHelper.computeFaceNormalFlipped(normal, quad); - flipUpcomingNormal = false; - } else { - NormalHelper.computeFaceNormal(normal, quad); - } - int packedNormal = NormI8.pack(normal); - - - - MemoryUtil.memPutInt(ptr + 28, packedNormal); - MemoryUtil.memPutInt(ptr + 28 - STRIDE, packedNormal); - MemoryUtil.memPutInt(ptr + 28 - STRIDE * 2, packedNormal); - MemoryUtil.memPutInt(ptr + 28 - STRIDE * 3, packedNormal); - - int tangent = NormalHelper.computeTangent(normal.x, normal.y, normal.z, quad); - - MemoryUtil.memPutInt(ptr + 24, tangent); - MemoryUtil.memPutInt(ptr + 24 - STRIDE, tangent); - MemoryUtil.memPutInt(ptr + 24 - STRIDE * 2, tangent); - MemoryUtil.memPutInt(ptr + 24 - STRIDE * 3, tangent); - } - - return ptr + STRIDE; - } -} diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinBakedChunkModelBuilder.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinBakedChunkModelBuilder.java index 468b56f3b3..0e103b7f9a 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinBakedChunkModelBuilder.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinBakedChunkModelBuilder.java @@ -13,18 +13,18 @@ public class MixinBakedChunkModelBuilder implements ContextAwareVertexWriter { @Shadow @Final - private ChunkMeshBufferBuilder[] vertexBuffers; + private ChunkMeshBufferBuilder[] meshBuffers; @Override public void iris$setContextHolder(BlockContextHolder holder) { - for (ChunkMeshBufferBuilder builder : this.vertexBuffers) { + for (ChunkMeshBufferBuilder builder : this.meshBuffers) { ((ContextAwareVertexWriter) builder).iris$setContextHolder(holder); } } @Override public void flipUpcomingQuadNormal() { - for (ChunkMeshBufferBuilder builder : this.vertexBuffers) { + for (ChunkMeshBufferBuilder builder : this.meshBuffers) { ((ContextAwareVertexWriter) builder).flipUpcomingQuadNormal(); } } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkBuildBuffers.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkBuildBuffers.java index 7086c55537..baab326152 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkBuildBuffers.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkBuildBuffers.java @@ -6,7 +6,8 @@ import me.jellysquid.mods.sodium.client.render.chunk.compile.ChunkBuildBuffers; import me.jellysquid.mods.sodium.client.render.chunk.compile.buffers.BakedChunkModelBuilder; import me.jellysquid.mods.sodium.client.render.chunk.terrain.TerrainRenderPass; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ModelQuadFormat; +import net.coderbot.iris.Iris; import net.coderbot.iris.block_rendering.BlockRenderingSettings; import net.coderbot.iris.compat.sodium.impl.block_context.BlockContextHolder; import net.coderbot.iris.compat.sodium.impl.block_context.ChunkBuildBuffersExt; @@ -33,7 +34,7 @@ public class MixinChunkBuildBuffers implements ChunkBuildBuffersExt { private BlockContextHolder contextHolder; @Inject(method = "", at = @At("RETURN"), remap = false) - private void iris$onConstruct(ChunkVertexType vertexType, CallbackInfo ci) { + private void iris$onConstruct(ModelQuadFormat vertexType, CallbackInfo ci) { Object2IntMap blockStateIds = BlockRenderingSettings.INSTANCE.getBlockStateIds(); if (blockStateIds != null) { @@ -43,12 +44,11 @@ public class MixinChunkBuildBuffers implements ChunkBuildBuffersExt { } } - @Inject(method = "", remap = false, at = @At(value = "TAIL", remap = false)) - private void iris$redirectWriterCreation(ChunkVertexType vertexType, CallbackInfo ci) { + @Inject(method = "", remap = false, at = @At(value = "TAIL")) + private void iris$redirectWriterCreation(ModelQuadFormat vertexType, CallbackInfo ci) { for (BakedChunkModelBuilder builder : this.builders.values()) { - if (builder instanceof ContextAwareVertexWriter) { - ((ContextAwareVertexWriter) builder).iris$setContextHolder(contextHolder); - } + ((ContextAwareVertexWriter) builder).iris$setContextHolder(contextHolder); + } } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkRenderRebuildTask.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkRenderRebuildTask.java index 6e2ece1bad..f27b7add22 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkRenderRebuildTask.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkRenderRebuildTask.java @@ -11,7 +11,7 @@ import me.jellysquid.mods.sodium.client.render.chunk.compile.tasks.ChunkBuilderMeshingTask; import me.jellysquid.mods.sodium.client.render.chunk.data.BuiltSectionInfo; import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.DefaultMaterials; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ModelQuadEncoder; import me.jellysquid.mods.sodium.client.util.task.CancellationToken; import me.jellysquid.mods.sodium.client.world.WorldSlice; import net.coderbot.iris.block_rendering.BlockRenderingSettings; @@ -36,7 +36,7 @@ */ @Mixin(ChunkBuilderMeshingTask.class) public class MixinChunkRenderRebuildTask { - private ChunkVertexEncoder.Vertex[] vertices = ChunkVertexEncoder.Vertex.uninitializedQuad(); + private ModelQuadEncoder.Vertex[] vertices = ModelQuadEncoder.Vertex.uninitializedQuad(); @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(value = "INVOKE", target = "net/minecraft/world/level/block/state/BlockState.getRenderShape()" + @@ -63,7 +63,7 @@ public class MixinChunkRenderRebuildTask { vertices[i].color = 0; vertices[i].light = blockState.getLightEmission() << 4 | blockState.getLightEmission() << 20; } - buildBuffers.getVertexBuffer(ModelQuadFacing.UNASSIGNED).push(vertices, DefaultMaterials.CUTOUT); + buildBuffers.getMeshBuffer(ModelQuadFacing.UNASSIGNED).push(vertices, DefaultMaterials.CUTOUT); ((ChunkBuildBuffersExt) buffers).iris$ignoreMidBlock(false); return; } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkVertexBufferBuilder.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkVertexBufferBuilder.java index 14980c96cf..9df20261a9 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkVertexBufferBuilder.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/block_id/MixinChunkVertexBufferBuilder.java @@ -1,7 +1,7 @@ package net.coderbot.iris.compat.sodium.mixin.block_id; import me.jellysquid.mods.sodium.client.render.chunk.vertex.builder.ChunkMeshBufferBuilder; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ModelQuadEncoder; import net.coderbot.iris.compat.sodium.impl.block_context.BlockContextHolder; import net.coderbot.iris.compat.sodium.impl.block_context.ContextAwareVertexWriter; import org.spongepowered.asm.mixin.Final; @@ -12,7 +12,7 @@ public class MixinChunkVertexBufferBuilder implements ContextAwareVertexWriter { @Shadow @Final - private ChunkVertexEncoder encoder; + private ModelQuadEncoder encoder; @Override public void iris$setContextHolder(BlockContextHolder holder) { diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/directional_shading/MixinSmoothLightPipeline.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/directional_shading/MixinSmoothLightPipeline.java index 0d65071bfe..a947c5483e 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/directional_shading/MixinSmoothLightPipeline.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/directional_shading/MixinSmoothLightPipeline.java @@ -11,8 +11,9 @@ @Mixin(SmoothLightPipeline.class) public class MixinSmoothLightPipeline { - @Inject(method = "applySidedBrightness", at = @At("HEAD"), cancellable = true) + //@Inject(method = "applySidedBrightness", at = @At("HEAD"), cancellable = true) private void iris$disableDirectionalShading(QuadLightData out, Direction face, boolean shade, CallbackInfo ci) { + // TODO Sodium if (BlockRenderingSettings.INSTANCE.shouldDisableDirectionalShading()) { ci.cancel(); } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinFluidRenderer.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinFluidRenderer.java index 564c1d2f3c..04885812ef 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinFluidRenderer.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/separate_ao/MixinFluidRenderer.java @@ -8,7 +8,6 @@ import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.DefaultMaterials; import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.Material; import me.jellysquid.mods.sodium.client.render.chunk.vertex.builder.ChunkMeshBufferBuilder; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder; import me.jellysquid.mods.sodium.client.world.WorldSlice; import net.coderbot.iris.block_rendering.BlockRenderingSettings; import net.coderbot.iris.compat.sodium.impl.block_context.ContextAwareVertexWriter; diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinShaderChunkRenderer.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinShaderChunkRenderer.java index 08908c5c52..4e6c044deb 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinShaderChunkRenderer.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/shader_overrides/MixinShaderChunkRenderer.java @@ -11,7 +11,7 @@ import me.jellysquid.mods.sodium.client.render.chunk.ShaderChunkRenderer; import me.jellysquid.mods.sodium.client.render.chunk.shader.ChunkShaderInterface; import me.jellysquid.mods.sodium.client.render.chunk.terrain.TerrainRenderPass; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ModelQuadFormat; import net.coderbot.iris.Iris; import net.coderbot.iris.compat.sodium.impl.shader_overrides.IrisChunkShaderInterface; import net.coderbot.iris.compat.sodium.impl.shader_overrides.ShaderChunkRendererExt; @@ -50,10 +50,10 @@ public class MixinShaderChunkRenderer implements ShaderChunkRendererExt { @Shadow(remap = false) @Final - protected ChunkVertexType vertexType; + protected ModelQuadFormat vertexType; @Inject(method = "", at = @At("RETURN"), remap = false) - private void iris$onInit(RenderDevice device, ChunkVertexType vertexType, CallbackInfo ci) { + private void iris$onInit(RenderDevice device, ModelQuadFormat vertexType, CallbackInfo ci) { irisChunkProgramOverrides = new IrisChunkProgramOverrides(); } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinModelVertexType.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinModelVertexType.java index e37b2bad7b..9ea885f2cf 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinModelVertexType.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinModelVertexType.java @@ -1,6 +1,6 @@ package net.coderbot.iris.compat.sodium.mixin.vertex_format; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ModelQuadEncoder; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; @@ -49,6 +49,6 @@ * which might take a while. Then, once those steps are available, use the debugger * to its fullest extent.

*/ -@Mixin(ChunkVertexType.class) +@Mixin(ModelQuadEncoder.class) public interface MixinModelVertexType { } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRegionChunkRenderer.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRegionChunkRenderer.java index 3ab5cf1e6a..240f19f509 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRegionChunkRenderer.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRegionChunkRenderer.java @@ -7,7 +7,8 @@ import me.jellysquid.mods.sodium.client.gl.tessellation.TessellationBinding; import me.jellysquid.mods.sodium.client.render.chunk.DefaultChunkRenderer; import me.jellysquid.mods.sodium.client.render.chunk.ShaderChunkRenderer; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ModelQuadEncoder; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ModelQuadFormat; import net.coderbot.iris.block_rendering.BlockRenderingSettings; import net.coderbot.iris.compat.sodium.impl.IrisChunkShaderBindingPoints; import net.coderbot.iris.compat.sodium.impl.vertex_format.IrisChunkMeshAttributes; @@ -24,37 +25,7 @@ @Mixin(DefaultChunkRenderer.class) public abstract class MixinRegionChunkRenderer extends ShaderChunkRenderer { - public MixinRegionChunkRenderer(RenderDevice device, ChunkVertexType vertexType) { + public MixinRegionChunkRenderer(RenderDevice device, ModelQuadFormat vertexType) { super(device, vertexType); } - - @Redirect(remap = false, method = "createRegionTessellation", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/gl/tessellation/TessellationBinding;forVertexBuffer(Lme/jellysquid/mods/sodium/client/gl/buffer/GlBuffer;[Lme/jellysquid/mods/sodium/client/gl/attribute/GlVertexAttributeBinding;)Lme/jellysquid/mods/sodium/client/gl/tessellation/TessellationBinding;")) - private TessellationBinding iris$onInit(GlBuffer buffer, GlVertexAttributeBinding[] attributes) { - if (!BlockRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat()) { - return TessellationBinding.forVertexBuffer(buffer, attributes); - } - - attributes = new GlVertexAttributeBinding[]{ - new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.ATTRIBUTE_POSITION_ID, - vertexFormat.getAttribute(IrisChunkMeshAttributes.POSITION_MATERIAL_MESH)), - new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.ATTRIBUTE_COLOR, - vertexFormat.getAttribute(IrisChunkMeshAttributes.COLOR_SHADE)), - new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.ATTRIBUTE_BLOCK_TEXTURE, - vertexFormat.getAttribute(IrisChunkMeshAttributes.BLOCK_TEXTURE)), - new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.ATTRIBUTE_LIGHT_TEXTURE, - vertexFormat.getAttribute(IrisChunkMeshAttributes.LIGHT_TEXTURE)), - new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.MID_BLOCK, - vertexFormat.getAttribute(IrisChunkMeshAttributes.MID_BLOCK)), - new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.BLOCK_ID, - vertexFormat.getAttribute(IrisChunkMeshAttributes.BLOCK_ID)), - new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.MID_TEX_COORD, - vertexFormat.getAttribute(IrisChunkMeshAttributes.MID_TEX_COORD)), - new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.TANGENT, - vertexFormat.getAttribute(IrisChunkMeshAttributes.TANGENT)), - new GlVertexAttributeBinding(IrisChunkShaderBindingPoints.NORMAL, - vertexFormat.getAttribute(IrisChunkMeshAttributes.NORMAL)) - }; - - return TessellationBinding.forVertexBuffer(buffer, attributes); - } } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRenderRegionArenas.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRenderRegionArenas.java index 5af9efd746..44cfe2710c 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRenderRegionArenas.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRenderRegionArenas.java @@ -1,21 +1,22 @@ package net.coderbot.iris.compat.sodium.mixin.vertex_format; import me.jellysquid.mods.sodium.client.render.chunk.region.RenderRegion; +import me.jellysquid.mods.sodium.client.render.chunk.region.RenderRegionManager; import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkMeshFormats; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ModelQuadFormat; import net.coderbot.iris.block_rendering.BlockRenderingSettings; import net.coderbot.iris.compat.sodium.impl.vertex_format.IrisModelVertexFormats; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -@Mixin(RenderRegion.DeviceResources.class) +@Mixin(RenderRegionManager.class) public class MixinRenderRegionArenas { - @Redirect(method = "", remap = false, + @Redirect(method = "uploadMeshes(Lme/jellysquid/mods/sodium/client/gl/device/CommandList;Lme/jellysquid/mods/sodium/client/render/chunk/region/RenderRegion;Ljava/util/Collection;)V", remap = false, at = @At(value = "FIELD", - target = "Lme/jellysquid/mods/sodium/client/render/chunk/vertex/format/ChunkMeshFormats;COMPACT:Lme/jellysquid/mods/sodium/client/render/chunk/vertex/format/ChunkVertexType;", + target = "Lme/jellysquid/mods/sodium/client/render/chunk/vertex/format/ChunkMeshFormats;DEFAULT:Lme/jellysquid/mods/sodium/client/render/chunk/vertex/format/ModelQuadFormat;", remap = false)) - private ChunkVertexType iris$useExtendedStride() { - return BlockRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat() ? IrisModelVertexFormats.MODEL_VERTEX_XHFP : ChunkMeshFormats.COMPACT; + private ModelQuadFormat iris$useExtendedStride() { + return BlockRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat() ? IrisModelVertexFormats.MODEL_VERTEX_XHFP : ChunkMeshFormats.DEFAULT; } } diff --git a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRenderSectionManager.java b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRenderSectionManager.java index b59f9afb66..7e63205a63 100644 --- a/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRenderSectionManager.java +++ b/src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/mixin/vertex_format/MixinRenderSectionManager.java @@ -1,7 +1,7 @@ package net.coderbot.iris.compat.sodium.mixin.vertex_format; import me.jellysquid.mods.sodium.client.render.chunk.RenderSectionManager; -import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; +import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ModelQuadFormat; import net.coderbot.iris.Iris; import net.coderbot.iris.block_rendering.BlockRenderingSettings; import net.coderbot.iris.compat.sodium.impl.vertex_format.IrisModelVertexFormats; @@ -13,15 +13,15 @@ public class MixinRenderSectionManager { @ModifyArg(method = "", remap = false, at = @At(value = "INVOKE", - target = "Lme/jellysquid/mods/sodium/client/render/chunk/DefaultChunkRenderer;(Lme/jellysquid/mods/sodium/client/gl/device/RenderDevice;Lme/jellysquid/mods/sodium/client/render/chunk/vertex/format/ChunkVertexType;)V")) - private ChunkVertexType iris$useExtendedVertexFormat$1(ChunkVertexType vertexType) { + target = "Lme/jellysquid/mods/sodium/client/render/chunk/DefaultChunkRenderer;(Lme/jellysquid/mods/sodium/client/gl/device/RenderDevice;Lme/jellysquid/mods/sodium/client/render/chunk/vertex/format/ModelQuadFormat;)V")) + private ModelQuadFormat iris$useExtendedVertexFormat$1(ModelQuadFormat vertexType) { return BlockRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat() ? IrisModelVertexFormats.MODEL_VERTEX_XHFP : vertexType; } @ModifyArg(method = "", at = @At(value = "INVOKE", - target = "Lme/jellysquid/mods/sodium/client/render/chunk/compile/executor/ChunkBuilder;(Lnet/minecraft/client/multiplayer/ClientLevel;Lme/jellysquid/mods/sodium/client/render/chunk/vertex/format/ChunkVertexType;)V")) - private ChunkVertexType iris$useExtendedVertexFormat$2(ChunkVertexType vertexType) { + target = "Lme/jellysquid/mods/sodium/client/render/chunk/compile/executor/ChunkBuilder;(Lnet/minecraft/client/multiplayer/ClientLevel;Lme/jellysquid/mods/sodium/client/render/chunk/vertex/format/ModelQuadFormat;)V")) + private ModelQuadFormat iris$useExtendedVertexFormat$2(ModelQuadFormat vertexType) { return BlockRenderingSettings.INSTANCE.shouldUseExtendedVertexFormat() ? IrisModelVertexFormats.MODEL_VERTEX_XHFP : vertexType; } }