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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.mojang.blaze3d.systems.RenderSystem;
import org.polyfrost.polyblur.client.PolyBlurConfig;
import org.polyfrost.polyblur.client.blur.FrameClock;
//? if >=1.21.5
import org.polyfrost.polyblur.client.blur.BlurSettings;
import org.polyfrost.polyblur.client.blur.phosphor.PhosphorBlur;
//? if >1.21.5
import org.polyfrost.polyblur.client.blur.phosphor.HybridHandPhosphor;
Expand Down Expand Up @@ -90,7 +92,7 @@ public class Mixin_ApplyPhosphorBlur {
//?} elif >1.21.5 && <26.2 {
//?} elif =1.21.5 {

/*if (useMotion && !PolyBlurConfig.INSTANCE.getVelocityBuffer()) MotionBlur.render(this.minecraft.getMainRenderTarget(), this.resourcePool);
/*if (useMotion && !BlurSettings.getVelocityBuffer()) MotionBlur.render(this.minecraft.getMainRenderTarget(), this.resourcePool);
*///?} else {
/*if (useMotion) MotionBlur.render(this.minecraft.getMainRenderTarget(), this.resourcePool);
else PhosphorBlur.render(this.minecraft.getMainRenderTarget(), this.resourcePool);
Expand Down Expand Up @@ -130,7 +132,7 @@ public class Mixin_ApplyPhosphorBlur {
//?}
if (blurType != 1) return;
if (!PolyBlurConfig.INSTANCE.getBlurHand()) return;
if (PolyBlurConfig.INSTANCE.getVelocityBuffer()) {
if (BlurSettings.getVelocityBuffer()) {
if (!WorldCamera.INSTANCE.getVelocitySettled()) {
MotionBlurReproject.render(target);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.joml.Matrix4f;
import org.joml.Vector4f;
import org.polyfrost.polyblur.client.PolyBlurConfig;
import org.polyfrost.polyblur.client.blur.BlurSettings;
import org.polyfrost.polyblur.client.blur.motion.HybridWorldPass;
import org.polyfrost.polyblur.client.blur.motion.MotionBlur;
import org.polyfrost.polyblur.client.blur.motion.MotionBlurReproject;
Expand All @@ -34,6 +35,7 @@
import org.joml.Matrix4fc;
import org.joml.Vector4f;
import org.polyfrost.polyblur.client.PolyBlurConfig;
import org.polyfrost.polyblur.client.blur.BlurSettings;
import org.polyfrost.polyblur.client.blur.motion.HybridWorldPass;
import org.polyfrost.polyblur.client.blur.motion.MotionBlur;
import org.polyfrost.polyblur.client.blur.motion.MotionBlurReproject;
Expand All @@ -57,6 +59,7 @@
import net.minecraft.client.renderer.GameRenderer;
import org.joml.Matrix4f;
import org.polyfrost.polyblur.client.PolyBlurConfig;
import org.polyfrost.polyblur.client.blur.BlurSettings;
import org.polyfrost.polyblur.client.blur.motion.MotionBlurReproject;
import org.polyfrost.polyblur.client.blur.motion.MotionVelocityPass;
import org.polyfrost.polyblur.client.blur.motion.ResourcePoolHolder;
Expand Down Expand Up @@ -99,7 +102,7 @@ public class Mixin_CaptureWorldMatrices {
if (blurType != 1) {
return;
}
if (PolyBlurConfig.INSTANCE.getVelocityBuffer() && !WorldCamera.INSTANCE.getVelocitySettled()) {
if (BlurSettings.getVelocityBuffer() && !WorldCamera.INSTANCE.getVelocitySettled()) {
MotionVelocityPass.run(Minecraft.getInstance().getMainRenderTarget());
// Hand sharp -> blur pre-hand. (1.21.5 global blur stays post-GUI.)
if (!PolyBlurConfig.INSTANCE.getBlurHand()) {
Expand Down Expand Up @@ -210,7 +213,7 @@ public class Mixin_CaptureWorldMatrices {
}

if (blurType == 2) {
if (PolyBlurConfig.INSTANCE.getVelocityBuffer()) {
if (BlurSettings.getVelocityBuffer()) {
HybridWorldPass.run(Minecraft.getInstance().getMainRenderTarget());
} else {
CrossFrameResourcePool pool = ResourcePoolHolder.INSTANCE.getPool();
Expand All @@ -226,14 +229,14 @@ public class Mixin_CaptureWorldMatrices {
return;
}

if (PolyBlurConfig.INSTANCE.getVelocityBuffer()) {
if (BlurSettings.getVelocityBuffer()) {
if (!WorldCamera.INSTANCE.getVelocitySettled()) {
MotionVelocityPass.run(Minecraft.getInstance().getMainRenderTarget());
}
}

if (!PolyBlurConfig.INSTANCE.getBlurHand()) {
if (PolyBlurConfig.INSTANCE.getVelocityBuffer()) {
if (BlurSettings.getVelocityBuffer()) {
if (!WorldCamera.INSTANCE.getVelocitySettled()) {
MotionBlurReproject.render(Minecraft.getInstance().getMainRenderTarget());
}
Expand Down Expand Up @@ -273,13 +276,14 @@ public class Mixin_CaptureWorldMatrices {
}

if (blurType == 2) {
if (PolyBlurConfig.INSTANCE.getVelocityBuffer()) {
if (BlurSettings.getVelocityBuffer()) {
HybridWorldPass.run(mainTarget);
} else {
CrossFrameResourcePool pool = ResourcePoolHolder.INSTANCE.getPool();
if (pool != null) {
MotionBlur.render(mainTarget, pool);
}
WorldSnapshotTracker.INSTANCE.capture(mainTarget);
}
return;
}
Expand All @@ -288,14 +292,14 @@ public class Mixin_CaptureWorldMatrices {
return;
}

if (PolyBlurConfig.INSTANCE.getVelocityBuffer()) {
if (BlurSettings.getVelocityBuffer()) {
if (!WorldCamera.INSTANCE.getVelocitySettled()) {
MotionVelocityPass.run(mainTarget);
}
}

if (!PolyBlurConfig.INSTANCE.getBlurHand()) {
if (PolyBlurConfig.INSTANCE.getVelocityBuffer()) {
if (BlurSettings.getVelocityBuffer()) {
if (!WorldCamera.INSTANCE.getVelocitySettled()) {
MotionBlurReproject.render(mainTarget);
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/org/polyfrost/polyblur/client/blur/BlurSettings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.polyfrost.polyblur.client.blur

//? if >=1.21.5 {
import org.polyfrost.polyblur.client.PolyBlurConfig
import org.polyfrost.polyblur.client.compat.IrisCompat

object BlurSettings {
@JvmStatic
val velocityBuffer: Boolean
get() = PolyBlurConfig.velocityBuffer && !IrisCompat.shadersActive
}
//?}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ object FrameClock {
var dt = 1f / REF_FPS
private set

var frame = 0L
private set

val timeScale: Float
get() = (1f / REF_FPS) / dt

Expand All @@ -16,6 +19,7 @@ object FrameClock {

@JvmStatic
fun tick() {
frame++
val now = System.nanoTime()
if (lastNs != 0L) {
dt = ((now - lastNs) / 1_000_000_000.0).toFloat().coerceIn(0.001f, 0.1f)
Expand Down
39 changes: 39 additions & 0 deletions src/main/kotlin/org/polyfrost/polyblur/client/compat/IrisCompat.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.polyfrost.polyblur.client.compat

import org.polyfrost.polyblur.client.blur.FrameClock
import java.lang.reflect.Method

object IrisCompat {
private val probe: Probe? by lazy { resolve() }

private var cachedFrame = -1L
private var cached = false

@JvmStatic
val shadersActive: Boolean
get() {
val probe = probe ?: return false
val frame = FrameClock.frame
if (frame != cachedFrame) {
cached = probe.query()
cachedFrame = frame
}
return cached
}

private fun resolve(): Probe? = try {
val apiClass = Class.forName("net.irisshaders.iris.api.v0.IrisApi")
val instance = apiClass.getMethod("getInstance").invoke(null)
Probe(apiClass.getMethod("isShaderPackInUse"), instance)
} catch (_: Throwable) {
null
}

private class Probe(private val method: Method, private val instance: Any) {
fun query(): Boolean = try {
method.invoke(instance) as Boolean
} catch (_: Throwable) {
false
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"depends": {
"minecraft": "${minecraft_version_range}",
"fabricloader": ">=${loader_version}",
"fabric-language-kotlin": "*"
"fabric-language-kotlin": "*",
"oneconfigv1": "*"
}
}