Skip to content

Commit

Permalink
Fix entities disappearing with MonkeyBlur
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Jun 30, 2024
1 parent d5fe6af commit 0c3ed9b
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 20 deletions.
13 changes: 4 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
id("org.polyfrost.defaults.java")
id("org.polyfrost.defaults.loom")
id("com.github.johnrengelman.shadow")
id("net.kyori.blossom") version "1.3.1"
id("net.kyori.blossom") version "1.3.2"
id("signing")
java
}
Expand All @@ -23,11 +23,6 @@ val mod_version: String by project
val mod_id: String by project
val mod_archives_name: String by project

// Sets up the variables for when we preprocess to other Minecraft versions.
preprocess {
vars.put("MODERN", if (project.platform.mcMinor >= 16) 1 else 0)
}

// Replaces the variables in `ExampleMod.java` to the ones specified in `gradle.properties`.
blossom {
replaceToken("@VER@", mod_version)
Expand Down Expand Up @@ -94,14 +89,14 @@ repositories {
// Configures the libraries/dependencies for your mod.
dependencies {
// Adds the OneConfig library, so we can develop with it.
modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.1-alpha+")
modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.2-alpha+")

modRuntimeOnly("me.djtheredstoner:DevAuth-${if (platform.isFabric) "fabric" else if (platform.isLegacyForge) "forge-legacy" else "forge-latest"}:1.1.2")

// If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier.
if (platform.isLegacyForge) {
compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT")
shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+")
shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta17")
}
}

Expand Down Expand Up @@ -168,7 +163,7 @@ tasks {
// Configures our shadow/shade configuration, so we can
// include some dependencies within our mod jar file.
named<ShadowJar>("shadowJar") {
archiveClassifier.set("dev") // TODO: machete gets confused by the `dev` prefix.
archiveClassifier.set("dev")
configurations = listOf(shade)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
relocate("ofconfig.", "")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod_version = 1.0.0
mod_archives_name=PolyBlur

# Gradle Configuration -- DO NOT TOUCH THESE VALUES.
polyfrost.defaults.loom=1
polyfrost.defaults.loom=3
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureoncommand=true
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions root.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
kotlin("jvm") version "1.8.22" apply false
kotlin("jvm") version "1.9.10" apply false
id("org.polyfrost.multi-version.root")
id("com.github.johnrengelman.shadow") version "7.1.2" apply false
id("com.github.johnrengelman.shadow") version "8.1.1" apply false
}

preprocess {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pluginManagement {
maven("https://repo.polyfrost.org/releases") // Adds the Polyfrost maven repository to get Polyfrost Gradle Toolkit
}
plugins {
val pgtVersion = "0.2.9" // Sets the default versions for Polyfrost Gradle Toolkit
val pgtVersion = "0.6.2" // Sets the default versions for Polyfrost Gradle Toolkit
id("org.polyfrost.multi-version.root") version pgtVersion
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/polyfrost/polyblur/blurs/monkey/MonkeyBlur.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void startFrame() {
previousCameraPosZ = cameraPosZ;

bindFb();
clearFb();
}

public void endFrame() {
Expand Down Expand Up @@ -107,6 +108,8 @@ public void endFrame() {
}
if (!isEnabled()) return;

//mc.renderGlobal.renderEntityOutlineFramebuffer();

unbindFb();

if (monkeyblurShader == null) {
Expand Down Expand Up @@ -143,7 +146,14 @@ public void bindFb() {
frameBuffer = new MonkeyBuffer(mc.displayWidth, mc.displayHeight);
}
OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, frameBuffer.framebufferObject);
frameBuffer.clear();
}

public void clearFb() {
if (!isEnabled()) return;

if (frameBuffer != null) {
frameBuffer.clear();
}
}

public void unbindFb() {
Expand Down Expand Up @@ -225,7 +235,7 @@ static void invertMat4(FloatBuffer in, FloatBuffer out) {
}

public boolean isEnabled() {
return OpenGlHelper.framebufferSupported && PolyBlur.instance.config.enabled && PolyBlur.instance.config.blurMode == 0 && !changedPerspective && !OFConfig.isShaders();
return OpenGlHelper.framebufferSupported && PolyBlur.instance != null && PolyBlur.instance.config.enabled && PolyBlur.instance.config.blurMode == 0 && !changedPerspective && !OFConfig.isShaders();
}

public void outputFb(int width, int height, int texture) {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/polyfrost/polyblur/mixin/RenderGlobalMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.polyfrost.polyblur.mixin;

import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.culling.ICamera;
import net.minecraft.entity.Entity;
import org.polyfrost.polyblur.blurs.monkey.MonkeyBlur;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(RenderGlobal.class)
public abstract class RenderGlobalMixin {

@Inject(method = "renderEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/shader/Framebuffer;bindFramebuffer(Z)V", ordinal = 1, shift = At.Shift.AFTER))
private void onRenderEntitiesPre(Entity renderViewEntity, ICamera camera, float partialTicks, CallbackInfo ci) {
MonkeyBlur.instance.bindFb();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.polyfrost.polyblur.mixin;

import org.polyfrost.polyblur.blurs.monkey.MonkeyBlur;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Pseudo
@Mixin(targets = "codes.biscuit.skyblockaddons.features.EntityOutlines.EntityOutlineRenderer")
public class SBAEntityOutlineRendererMixin {

@Dynamic("SBA")
@Inject(method = "renderEntityOutlines", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/shader/Framebuffer;bindFramebuffer(Z)V", ordinal = 3, shift = At.Shift.AFTER, remap = true), remap = false)
private void onRenderEntityOutlinesPre(CallbackInfo ci) {
MonkeyBlur.instance.bindFb();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.polyfrost.polyblur.mixin;

import org.polyfrost.polyblur.blurs.monkey.MonkeyBlur;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Pseudo
@Mixin(targets = "at.hannibal2.skyhanni.utils.EntityOutlineRenderer")
public class SkyHanniEntityOutlineRendererMixin {

@Dynamic("SkyHanni")
@Inject(method = "renderEntityOutlines", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/shader/Framebuffer;bindFramebuffer(Z)V", ordinal = 3, shift = At.Shift.AFTER, remap = true), remap = false)
private void onRenderEntityOutlinesPre(CallbackInfo ci) {
MonkeyBlur.instance.bindFb();
}
}
6 changes: 3 additions & 3 deletions src/main/resources/assets/polyblur/shaders/monkeyblur.frag
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ float maxDepth(vec2 texcoord, sampler2D tex) {

for (int x = -2; x < 3; x++) {
for (int y = -2; y < 3; y++) {
float d = texture2D(tex, texcoord + t * vec2(x, y)).x;
float d = texture2D(tex, texcoord + t * vec2(float(x), float(y))).x;
depth = max(depth, d);
}
}
Expand Down Expand Up @@ -58,11 +58,11 @@ void main() {
vel = vel / (1.0 + length(vel)) * strength * 0.01;
vec2 coord = texcoord.st + vel;

int count = 1;
float count = 1;
for (int i = 0; i < 30; ++i, coord += vel) {
if (coord.s > 1.0 || coord.t > 1.0 || coord.s < 0.0 || coord.t < 0.0) break;
color += texture2D(texture, coord).xyz;
++count;
count += 1;
}
color /= count;

Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/mixins.polyblur.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"EntityRendererMixin_PhosphorBlur",
"MinecraftMixin",
"OptifineConfigMixin",
"ShaderGroupAccessor"
"RenderGlobalMixin",
"SBAEntityOutlineRendererMixin",
"ShaderGroupAccessor",
"SkyHanniEntityOutlineRendererMixin"
]
}

0 comments on commit 0c3ed9b

Please sign in to comment.