Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion root.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ preprocess {
fabric12103.link(fabric12100)
neoForge12100.link(fabric12100)
forge12100.link(fabric12100)
fabric12100.link(fabric12006)
fabric12100.link(fabric12006, file("versions/1.21-1.20.6.txt"))
neoForge12006.link(fabric12006)
forge12006.link(fabric12006)
fabric12006.link(fabric12004)
Expand Down
41 changes: 38 additions & 3 deletions src/main/kotlin/gg/essential/universal/shader/ShaderTransformer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ package gg.essential.universal.shader
//$$ import gg.essential.universal.standalone.render.VertexFormat
//#else
import net.minecraft.client.renderer.vertex.VertexFormat
import net.minecraft.client.renderer.vertex.VertexFormatElement

//#if MC >= 26.2
//$$ import com.mojang.blaze3d.GpuFormat
//#endif
//#endif

internal class ShaderTransformer(private val vertexFormat: VertexFormat?, private val targetVersion: Int) {
Expand Down Expand Up @@ -55,12 +60,19 @@ internal class ShaderTransformer(private val vertexFormat: VertexFormat?, privat
}
}
if (vert) {
//#if STANDALONE
//$$ fun uvVecType(index: Int) = "vec2"
//#else
fun uvVecType(index: Int) =
if (vertexFormat?.uvIsFloat(index) ?: true) "vec2" else "ivec2"
//#endif

val newAttributes = mutableListOf<Pair<String, String>>()
replaceAttribute(newAttributes, "gl_Vertex", "vec3", "uc_Position", replacement = "vec4(uc_Position, 1.0)")
replaceAttribute(newAttributes, "gl_Color", "vec4")
replaceAttribute(newAttributes, "gl_MultiTexCoord0.st", "vec2", "uc_UV0")
replaceAttribute(newAttributes, "gl_MultiTexCoord1.st", "vec2", "uc_UV1")
replaceAttribute(newAttributes, "gl_MultiTexCoord2.st", "vec2", "uc_UV2")
replaceAttribute(newAttributes, "gl_MultiTexCoord0.st", uvVecType(0), "uc_UV0")
replaceAttribute(newAttributes, "gl_MultiTexCoord1.st", uvVecType(1), "uc_UV1")
replaceAttribute(newAttributes, "gl_MultiTexCoord2.st", uvVecType(2), "uc_UV2")

if (vertexFormat != null) {
//#if MC>=11700 && !STANDALONE
Expand Down Expand Up @@ -147,6 +159,29 @@ internal class ShaderTransformer(private val vertexFormat: VertexFormat?, privat
}
}

//#if !STANDALONE
private fun VertexFormat.uvIsFloat(i: Int): Boolean =
//#if MC >= 26.2
//$$ this.getElement("UV$i")
//#elseif MC >= 26.1
//$$ this.elements.getOrNull(this.elementAttributeNames.indexOf("UV$i"))
//#else
this.elements
.asSequence()
.filter { it.usage == VertexFormatElement.EnumUsage.UV }
.elementAtOrNull(i)
//#endif
?.isFloat()
?: true

private fun VertexFormatElement.isFloat() =
//#if MC >= 26.2
//$$ this.format == GpuFormat.RG16_FLOAT || this.format == GpuFormat.RG32_FLOAT
//#else
this.type == VertexFormatElement.EnumType.FLOAT
//#endif
//#endif

internal enum class UniformType(val typeName: String, val glslName: String, val default: IntArray) {
Int1("int", "int", intArrayOf(0)),
Float1("float", "float", intArrayOf(0)),
Expand Down
2 changes: 2 additions & 0 deletions versions/1.21-1.20.6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
net.minecraft.client.render.VertexFormatElement type() getComponentType()
net.minecraft.client.render.VertexFormatElement usage() getType()
2 changes: 2 additions & 0 deletions versions/1.21.5-1.21.4.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
com.mojang.blaze3d.vertex.VertexFormat net.minecraft.client.render.VertexFormat
com.mojang.blaze3d.vertex.VertexFormat getElementAttributeNames() getAttributeNames()
com.mojang.blaze3d.vertex.VertexFormatElement net.minecraft.client.render.VertexFormatElement
com.mojang.blaze3d.vertex.VertexFormatElement$Type net.minecraft.client.render.VertexFormatElement$ComponentType
com.mojang.blaze3d.opengl.GlStateManager com.mojang.blaze3d.platform.GlStateManager
Loading