Skip to content

Commit

Permalink
new: add moulberry mb blur
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Aug 16, 2022
1 parent bcbc72b commit 3772e11
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod_name = PolyBlur
mod_id = polyblur
mod_version = 1.0.0-alpha2
mod_version = 1.0.0-alpha3

essential.defaults.loom=0

Expand Down
86 changes: 86 additions & 0 deletions src/main/java/cc/polyfrost/polyblur/blurs/moulberry/MBBlur.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package cc.polyfrost.polyblur.blurs.moulberry;

import cc.polyfrost.polyblur.PolyBlur;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.shader.Framebuffer;
import org.lwjgl.opengl.GL11;

/**
* @author Moulberry
*/
public class MBBlur {
public static final MBBlur instance = new MBBlur();
private Framebuffer blurBufferMain = null;
private Framebuffer blurBufferInto = null;

public void doBlur() {
if (!OpenGlHelper.isFramebufferEnabled() || PolyBlur.instance.config.blurMode != 2 || !PolyBlur.instance.config.enabled) {
return;
}
int width = Minecraft.getMinecraft().getFramebuffer().framebufferWidth;
int height = Minecraft.getMinecraft().getFramebuffer().framebufferHeight;
GlStateManager.matrixMode(5889);
GlStateManager.loadIdentity();
GlStateManager.ortho(0.0, width, height, 0.0, 1000.0, 3000.0);
GlStateManager.matrixMode(5888);
GlStateManager.loadIdentity();
GlStateManager.translate(0.0f, 0.0f, -2000.0f);
this.blurBufferMain = checkFramebufferSizes(this.blurBufferMain, width, height);
this.blurBufferInto = checkFramebufferSizes(this.blurBufferInto, width, height);
this.blurBufferInto.framebufferClear();
this.blurBufferInto.bindFramebuffer(true);
OpenGlHelper.glBlendFunc(770, 771, 1, 1);
GlStateManager.disableLighting();
GlStateManager.disableFog();
GlStateManager.disableBlend();
Minecraft.getMinecraft().getFramebuffer().bindFramebufferTexture();
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
drawTexturedRectNoBlend(0.0f, 0.0f, width, height, 0.0f, 1.0f, 0.0f, 1.0f, 9728);
GlStateManager.enableBlend();
this.blurBufferMain.bindFramebufferTexture();
GlStateManager.color(1.0f, 1.0f, 1.0f, Math.min(0.1f + (PolyBlur.instance.config.strength * 0.1f), 0.9F));
drawTexturedRectNoBlend(0.0f, 0.0f, width, height, 0.0f, 1.0f, 1.0f, 0.0f, 9728);
Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(true);
this.blurBufferInto.bindFramebufferTexture();
GlStateManager.color(1.0f, 1.0f, 1.0f, Math.min(0.1f + (PolyBlur.instance.config.strength * 0.1f), 0.9F) + 1.0F);
GlStateManager.enableBlend();
OpenGlHelper.glBlendFunc(770, 771, 1, 771);
drawTexturedRectNoBlend(0.0f, 0.0f, width, height, 0.0f, 1.0f, 0.0f, 1.0f, 9728);
Framebuffer swap = this.blurBufferMain;
this.blurBufferMain = this.blurBufferInto;
this.blurBufferInto = swap;
}

private static Framebuffer checkFramebufferSizes(Framebuffer framebuffer, int width, int height) {
if (framebuffer == null || framebuffer.framebufferWidth != width || framebuffer.framebufferHeight != height) {
if (framebuffer == null) {
framebuffer = new Framebuffer(width, height, true);
} else {
framebuffer.createBindFramebuffer(width, height);
}
framebuffer.setFramebufferFilter(9728);
}
return framebuffer;
}

private static void drawTexturedRectNoBlend(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax, int filter) {
GlStateManager.enableTexture2D();
GL11.glTexParameteri(3553, 10241, filter);
GL11.glTexParameteri(3553, 10240, filter);
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX);
worldrenderer.pos(x, y + height, 0.0).tex(uMin, vMax).endVertex();
worldrenderer.pos(x + width, y + height, 0.0).tex(uMax, vMax).endVertex();
worldrenderer.pos(x + width, y, 0.0).tex(uMax, vMin).endVertex();
worldrenderer.pos(x, y, 0.0).tex(uMin, vMin).endVertex();
tessellator.draw();
GL11.glTexParameteri(3553, 10241, 9728);
GL11.glTexParameteri(3553, 10240, 9728);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class PolyBlurConfig extends Config {

@Info(
text = "Phosphor blur will ONLY work if either Fast Render is disabled or Force Disable Fast Render is enabled.",
text = "Phosphor / Moulberry blur will ONLY work if either Fast Render is disabled or Force Disable Fast Render is enabled.",
size = 2,
type = InfoType.WARNING
)
Expand All @@ -28,7 +28,8 @@ public class PolyBlurConfig extends Config {
name = "Blur Mode",
options = {
"Monkey Blur",
"Phosphor Blur"
"Phosphor Blur",
"Moulberry Blur"
}
)
public int blurMode = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cc.polyfrost.polyblur.mixin;

import cc.polyfrost.polyblur.blurs.monkey.MonkeyBlur;
import cc.polyfrost.polyblur.blurs.moulberry.MBBlur;
import net.minecraft.client.renderer.EntityRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -23,5 +24,6 @@ private void setupCamera(int pass, float partialTicks, long finishTimeNano, Call
@Inject(method = {"renderWorldPass"}, at = @At(value = "CONSTANT", args = "stringValue=hand"))
private void onRenderWorldEnd(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) {
MonkeyBlur.instance.endFrame();
MBBlur.instance.doBlur();
}
}

0 comments on commit 3772e11

Please sign in to comment.