Skip to content

Commit 49e3a06

Browse files
authored
URenderPipeline: Fix incorrect blend state on 1.17 - 1.20.6
The blend state passed to `UShader.fromLegacyShader`, which we ignore explicitly via `skipBlendState` on versions prior to 1.17, can still get applied by MC's shader class on 1.17 - 1.20.6 and we can't easily disable/overwrite that because it happens far down the draw method call. As such, we must pass the correct blend state to it, otherwise it'll sometimes disable blending when we want it enabled. This does not affect 1.21+ because MC's shader class no longer cares about the blend state on those versions. Additionally, this issue is masked by the fact that the caching in MC's GlBlendState class is horribly broken in multiple ways, so often it wouldn't actually apply at all, thereby making this issue inconsistent even on 1.17 - 1.20.6. Linear: EM-3163 GitHub: #100
1 parent 6829f15 commit 49e3a06

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/main/kotlin/gg/essential/universal/render/URenderPipeline.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.lwjgl.opengl.GL11
88

99
//#if STANDALONE
1010
//$$ import gg.essential.universal.shader.GlShader
11+
//$$ import gg.essential.universal.shader.UShader
1112
//$$ import gg.essential.universal.standalone.render.DefaultShader
1213
//$$ import gg.essential.universal.standalone.render.VertexFormat
1314
//$$ import gg.essential.universal.vertex.UBuiltBufferInternal
@@ -31,6 +32,7 @@ import net.minecraft.util.ResourceLocation
3132
//$$ import org.apache.commons.codec.digest.DigestUtils
3233
//$$ import java.util.function.BiFunction
3334
//#else
35+
import gg.essential.universal.shader.UShader
3436
import gg.essential.universal.vertex.UBuiltBufferInternal
3537
import net.minecraft.client.renderer.WorldVertexBufferUploader
3638
//#endif
@@ -104,7 +106,7 @@ class URenderPipeline private constructor(
104106
}
105107

106108
internal fun bind() {
107-
shader?.bind()
109+
shader?.bind(glState.blendState)
108110
}
109111

110112
internal fun unbind() {
@@ -207,15 +209,19 @@ class URenderPipeline private constructor(
207209

208210
private sealed interface ShaderSupplier {
209211
//#if MC<12105 || STANDALONE
210-
fun bind()
212+
fun bind(blendState: BlendState)
211213
fun unbind()
212214
//#endif
213215

214216
class LegacySource(val vertexFormat: VertexFormat, val vertSource: String, val fragSource: String) : ShaderSupplier {
215217
//#if MC<12105 || STANDALONE
216-
val shader by lazy { gg.essential.universal.shader.UShader.fromLegacyShader(vertSource, fragSource, BlendState.DISABLED, vertexFormat) }
218+
lateinit var shader: UShader
219+
220+
override fun bind(blendState: BlendState) {
221+
if (!::shader.isInitialized) {
222+
shader = UShader.fromLegacyShader(vertSource, fragSource, blendState, vertexFormat)
223+
}
217224

218-
override fun bind() {
219225
//#if MC>=12102 && !STANDALONE
220226
//$$ RenderSystem.setShader((shader as MCShader).mc)
221227
//#elseif MC>=11700 && !STANDALONE
@@ -242,7 +248,7 @@ class URenderPipeline private constructor(
242248
//$$ class Mc(val vert: Identifier, val frag: Identifier, val samplers: List<String>, val uniforms: Map<String, UniformType>) : ShaderSupplier
243249
//#else
244250
//$$ class Mc(val shader: Supplier<Shader>) : ShaderSupplier {
245-
//$$ override fun bind() {
251+
//$$ override fun bind(blendState: BlendState) {
246252
//#if MC>=12102
247253
//$$ RenderSystem.setShader(shader.get())
248254
//#else

0 commit comments

Comments
 (0)