From 02992196fcc19f8d5e127e050efbe68d97a49cce Mon Sep 17 00:00:00 2001 From: winterflyt <36+winterflyt@noreply.skidsolutions.xyz> Date: Mon, 30 Nov 2026 06:13:54 +0200 Subject: [PATCH] Upload files to "src/openonyx/render" --- src/openonyx/render/RenderTarget.java | 102 ++++++++ src/openonyx/render/ScissorStack.java | 198 ++++++++++++++ src/openonyx/render/SkyboxRenderer.java | 233 +++++++++++++++++ src/openonyx/render/TextureFilter.java | 199 ++++++++++++++ src/openonyx/render/TrailShader.java | 331 ++++++++++++++++++++++++ 5 files changed, 1063 insertions(+) create mode 100644 src/openonyx/render/RenderTarget.java create mode 100644 src/openonyx/render/ScissorStack.java create mode 100644 src/openonyx/render/SkyboxRenderer.java create mode 100644 src/openonyx/render/TextureFilter.java create mode 100644 src/openonyx/render/TrailShader.java diff --git a/src/openonyx/render/RenderTarget.java b/src/openonyx/render/RenderTarget.java new file mode 100644 index 0000000..40395f4 --- /dev/null +++ b/src/openonyx/render/RenderTarget.java @@ -0,0 +1,102 @@ +package openonyx.render; + +import java.nio.ByteBuffer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.texture.TextureUtil; +import org.lwjgl.opengl.GL11; + +public final class RenderTarget { + private int I; + private int d; + private int i; + private int f = -1; + private final boolean H; + private int e; + + public int getHeight() { + return this.d; + } + + public void bindAndClear() { + this.bind(); + GlStateManager.clearColor(0.0F, 0.0F, 0.0F, 0.0F); + GlStateManager.clearDepth(1.0); + GlStateManager.clear(this.H ? 16640 : 16384); + } + + public int getTexture() { + return this.f; + } + + public void bind() { + OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, this.I); + GlStateManager.viewport(0, 0, this.e, this.d); + } + + public RenderTarget(boolean bl) { + this.I = -1; + this.i = -1; + this.H = bl; + } + + public int getWidth() { + return this.e; + } + + public boolean resize(int i, int j) { + ix = Math.max(1, ix); + j = Math.max(1, j); + if (this.f != -1 && this.e == ix && this.d == j) { + return false; + } + + this.delete(); + this.f = TextureUtil.glGenTextures(); + GlStateManager.bindTexture(this.f); + GL11.glTexImage2D(3553, 0, 32856, ix, j, 0, 6408, 5121, (ByteBuffer)null); + GL11.glTexParameteri(3553, 10241, 9729); + GL11.glTexParameteri(3553, 10240, 9729); + GL11.glTexParameteri(3553, 10242, 33071); + GL11.glTexParameteri(3553, 10243, 33071); + this.I = OpenGlHelper.glGenFramebuffers(); + OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, this.I); + OpenGlHelper.glFramebufferTexture2D(OpenGlHelper.GL_FRAMEBUFFER, OpenGlHelper.GL_COLOR_ATTACHMENT0, 3553, this.f, 0); + if (this.H) { + this.i = OpenGlHelper.glGenRenderbuffers(); + OpenGlHelper.glBindRenderbuffer(OpenGlHelper.GL_RENDERBUFFER, this.i); + OpenGlHelper.glRenderbufferStorage(OpenGlHelper.GL_RENDERBUFFER, 33190, ix, j); + OpenGlHelper.glFramebufferRenderbuffer(OpenGlHelper.GL_FRAMEBUFFER, OpenGlHelper.GL_DEPTH_ATTACHMENT, OpenGlHelper.GL_RENDERBUFFER, this.i); + } + + int k = OpenGlHelper.glCheckFramebufferStatus(OpenGlHelper.GL_FRAMEBUFFER); + OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, 0); + if (k != OpenGlHelper.GL_FRAMEBUFFER_COMPLETE) { + this.delete(); + throw new IllegalStateException(new StringBuilder().insert(0, "Could not create a hand effect target, status ").append(k).toString()); + } else { + this.e = ix; + this.d = j; + return true; + } + } + + public void delete() { + if (this.I != -1) { + OpenGlHelper.glDeleteFramebuffers(this.I); + this.I = -1; + } + + if (this.i != -1) { + OpenGlHelper.glDeleteRenderbuffers(this.i); + this.i = -1; + } + + if (this.f != -1) { + TextureUtil.deleteTexture(this.f); + this.f = -1; + } + + this.d = this.e = 0; + } +} diff --git a/src/openonyx/render/ScissorStack.java b/src/openonyx/render/ScissorStack.java new file mode 100644 index 0000000..da7350a --- /dev/null +++ b/src/openonyx/render/ScissorStack.java @@ -0,0 +1,198 @@ +package openonyx.render; + +import java.nio.FloatBuffer; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.GL11; + +public final class ScissorStack { + private static final float[] D; + private static final int[] c; + private static final FloatBuffer FLOAT_BUFFER = BufferUtils.createFloatBuffer(16); + private static float k; + private static float g; + private static final float[] M; + private static boolean L; + private static final float j = 1.0E-4F; + private static final float[] m; + private static boolean h; + private static final float[] l; + private static final FloatBuffer FLOAT_BUFFER2 = BufferUtils.createFloatBuffer(16); + private static final float[] d; + private static float i; + private static final float[] f; + private static float H; + private static final float[] e; + + static { + float[] fx = new float[6]; + boolean bl = true; + fx[0] = -1.8F; + fx[1] = -1.8F; + fx[2] = -1.8F; + fx[3] = 1.8F; + fx[4] = 1.8F; + fx[5] = 1.8F; + e = fx; + fx = new float[6]; + bl = true; + fx[0] = -0.62F; + fx[1] = -0.12F; + fx[2] = -0.25F; + fx[3] = -0.13F; + fx[4] = 0.87F; + fx[5] = 0.25F; + d = fx; + fx = new float[6]; + bl = true; + fx[0] = -0.62F; + fx[1] = -0.58F; + fx[2] = -0.6F; + fx[3] = -0.13F; + fx[4] = 0.83F; + fx[5] = 0.6F; + m = fx; + int[] ix = new int[24]; + bl = true; + ix[0] = 0; + ix[1] = 1; + ix[2] = 2; + ix[3] = 3; + ix[4] = 4; + ix[5] = 5; + ix[6] = 6; + ix[7] = 7; + ix[8] = 0; + ix[9] = 2; + ix[10] = 1; + ix[11] = 3; + ix[12] = 4; + ix[13] = 6; + ix[14] = 5; + ix[15] = 7; + ix[16] = 0; + ix[17] = 4; + ix[18] = 1; + ix[19] = 5; + ix[20] = 2; + ix[21] = 6; + ix[22] = 3; + ix[23] = 7; + c = ix; + fx = new float[8]; + bl = true; + f = fx; + fx = new float[8]; + bl = true; + M = fx; + fx = new float[8]; + bl = true; + D = fx; + fx = new float[8]; + bl = true; + l = fx; + } + + private static void L(float[] f) { + float[] gx = fx; + FLOAT_BUFFER2.clear(); + FLOAT_BUFFER.clear(); + GL11.glGetFloat(2982, FLOAT_BUFFER2); + GL11.glGetFloat(2983, FLOAT_BUFFER); + int o = 0; + + for (int u = o; u < 8; u = o) { + float hx = gx[(o & 1) == 0 ? 0 : 3]; + float ix = gx[(o & 2) == 0 ? 1 : 4]; + float jx = gx[(o & 4) == 0 ? 2 : 5]; + float kx = FLOAT_BUFFER2.get(0) * hx + FLOAT_BUFFER2.get(4) * ix + FLOAT_BUFFER2.get(8) * jx + FLOAT_BUFFER2.get(12); + float lx = FLOAT_BUFFER2.get(1) * hx + FLOAT_BUFFER2.get(5) * ix + FLOAT_BUFFER2.get(9) * jx + FLOAT_BUFFER2.get(13); + float mx = FLOAT_BUFFER2.get(2) * hx + FLOAT_BUFFER2.get(6) * ix + FLOAT_BUFFER2.get(10) * jx + FLOAT_BUFFER2.get(14); + f[o] = FLOAT_BUFFER.get(0) * kx + FLOAT_BUFFER.get(4) * lx + FLOAT_BUFFER.get(8) * mx + FLOAT_BUFFER.get(12); + M[o] = FLOAT_BUFFER.get(1) * kx + FLOAT_BUFFER.get(5) * lx + FLOAT_BUFFER.get(9) * mx + FLOAT_BUFFER.get(13); + float n = FLOAT_BUFFER.get(2) * kx + FLOAT_BUFFER.get(6) * lx + FLOAT_BUFFER.get(10) * mx + FLOAT_BUFFER.get(14); + D[o] = FLOAT_BUFFER.get(3) * kx + FLOAT_BUFFER.get(7) * lx + FLOAT_BUFFER.get(11) * mx + FLOAT_BUFFER.get(15); + int v = o; + float w = n + D[o]; + o++; + l[v] = w; + } + + for (int t = p = 0; t < 8; t = ++p) { + if (l[p] >= 0.0F) { + L(f[p], M[p], D[p]); + } + } + + for (byte cx = b = 0; cx < c.length; cx = b) { + int q = c[b]; + int r = c[b + 1]; + if (l[q] >= 0.0F != l[r] >= 0.0F) { + float s = l[q] / (l[q] - l[r]); + L(f[q] + (f[r] - f[q]) * s, M[q] + (M[r] - M[q]) * s, D[q] + (D[r] - D[q]) * s); + } + + b += 2; + } + } + + public static void D() { + h = false; + } + + public static void d() { + if (L) { + L = false; + GL11.glDisable(3089); + } + } + + public static void L(float f, int i, int j) { + if (h) { + int lx = Math.clamp((int)Math.floor(k * ix - fx), 0, ix); + int kx = Math.clamp((int)Math.floor(i * jx - fx), 0, jx); + ix = Math.clamp((int)Math.ceil(g * ix + fx), lx, ix); + jx = Math.clamp((int)Math.ceil(H * jx + fx), kx, jx); + if (ix > lx && jx > kx) { + GL11.glEnable(3089); + GL11.glScissor(lx, kx, ix - lx, jx - kx); + L = true; + } + } + } + + private static void L(float f, float g, float h) { + if (hx > 1.0E-4F) { + float ix = fx / hx * 0.5F + 0.5F; + gx = gx / hx * 0.5F + 0.5F; + if (Float.isFinite(ix) && Float.isFinite(gx)) { + if (h) { + k = Math.min(k, ix); + i = Math.min(i, gx); + g = Math.max(g, ix); + H = Math.max(H, gx); + } else { + k = ix; + i = gx; + g = ix; + H = gx; + h = true; + } + } + } + } + + public static void L() { + L(e); + } + + private ScissorStack() { + } + + public static boolean L() { + return h; + } + + public static void L(boolean bl) { + L(bl ? m : d); + } +} diff --git a/src/openonyx/render/SkyboxRenderer.java b/src/openonyx/render/SkyboxRenderer.java new file mode 100644 index 0000000..52f8a66 --- /dev/null +++ b/src/openonyx/render/SkyboxRenderer.java @@ -0,0 +1,233 @@ +package openonyx.render; + +import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.shader.Framebuffer; +import openonyx.core.MinecraftAccess; +import openonyx.core.OnyxClient; +import openonyx.features.render.Skybox; +import openonyx.render.group_p.ShaderProgram; +import openonyx.theme.internal.ColorUtils; +import org.lwjgl.opengl.GL11; + +public final class SkyboxRenderer implements MinecraftAccess { + private static final int g = 5889; + private static boolean M; + private static int L; + private static boolean j = true; + private static final int m = 5888; + private static final int h = 24; + private static final int l = 48; + private static boolean I = true; + private static final float d = 16.0F; + private static boolean i; + private static ShaderProgram shaderProgram; + private static ShaderProgram shaderProgram2; + private static final RenderTarget RENDER_TARGET = new RenderTarget(false); + + private static void D() { + if (L == 0) { + L = GLAllocation.generateDisplayLists(1); + GL11.glNewList(L, 4864); + GL11.glBegin(4); + d(); + GL11.glEnd(); + GL11.glEndList(); + } + + GL11.glCallList(L); + } + + private static void d() { + int ix; + for (int u = ix = 0; u < 24; u = ++ix) { + float f = (float)(Math.PI * ix / 24.0 - (Math.PI / 2)); + float gx = (float)(Math.PI * (ix + 1) / 24.0 - (Math.PI / 2)); + float hx = (float)Math.sin(f); + f = (float)Math.cos(f); + float jx = (float)Math.sin(gx); + gx = (float)Math.cos(gx); + + int k; + for (int t = k = 0; t < 48; t = k) { + float lx = (float)((Math.PI * 2) * k / 48.0); + float mx = (float)((Math.PI * 2) * (k + 1) / 48.0); + float n = (float)Math.cos(lx); + lx = (float)Math.sin(lx); + float o = (float)Math.cos(mx); + mx = (float)Math.sin(mx); + float p = f * n; + float q = f * lx; + float r = f * o; + float s = f * mx; + n = gx * n; + lx = gx * lx; + o = gx * o; + mx = gx * mx; + L(p, hx, q); + L(n, jx, lx); + L(o, jx, mx); + L(p, hx, q); + L(o, jx, mx); + k++; + L(r, hx, s); + } + } + } + + private static void L(Skybox skybox) { + Skybox skybox1 = skybox; + int ix = skybox1.D(); + GlStateManager.pushMatrix(); + GlStateManager.disableTexture2D(); + GlStateManager.disableLighting(); + GlStateManager.disableAlpha(); + GlStateManager.disableBlend(); + GlStateManager.disableFog(); + GlStateManager.depthMask(false); + GlStateManager.disableCull(); + shaderProgram.use(); + shaderProgram.setUniform4f("uColorModulator", ColorUtils.red(ix) / 255.0F, ColorUtils.green(ix) / 255.0F, ColorUtils.blue(ix) / 255.0F, skybox1.h()); + shaderProgram.setUniform3f("uParams", skybox1.L(), skybox1.d(), skybox1.F()); + shaderProgram.setUniform4f("uKnobs", skybox1.L(), skybox1.I(), skybox1.k(), skybox1.i()); + shaderProgram.setUniform1f("uStrikeGlow", skybox1.D()); + shaderProgram.setUniform4f("uFogColor", 0.0F, 0.0F, 0.0F, 0.0F); + D(); + ShaderProgram.unbind(); + GlStateManager.enableCull(); + GlStateManager.depthMask(true); + GlStateManager.enableFog(); + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + GlStateManager.enableLighting(); + GlStateManager.popMatrix(); + } + + private static void L(float f, float g, float h) { + GL11.glVertex3f(f * 16.0F, gx * 16.0F, hx * 16.0F); + } + + private static boolean L(Skybox skybox) { + Skybox skybox1 = skybox; + float f = skybox1.d(); + if (!j || f >= 0.999F) { + return false; + } + + if (OpenGlHelper.isFramebufferEnabled() && OpenGlHelper.shadersSupported) { + Framebuffer framebuffer; + if ((framebuffer = mc.getFramebuffer()) != null && framebuffer.framebufferWidth > 0 && framebuffer.framebufferHeight > 0) { + if (!M) { + M = true; + shaderProgram2 = ShaderProgram.load("onyx_sky_blit", "onyx_post", "onyx_hand_blit"); + } + + if (shaderProgram2 != null && shaderProgram2.isLoaded()) { + try { + RENDER_TARGET.resize(Math.round(framebuffer.framebufferWidth * f), Math.round(framebuffer.framebufferHeight * f)); + } catch (Throwable throwable) { + j = false; + RENDER_TARGET.delete(); + OnyxClient.LOGGER.warn("Skybox is falling back to full resolution", throwable); + return false; + } + + RENDER_TARGET.bindAndClear(); + L(skybox1); + framebuffer.bindFramebuffer(false); + GlStateManager.viewport(0, 0, framebuffer.framebufferWidth, framebuffer.framebufferHeight); + L(); + return true; + } else { + j = false; + return false; + } + } else { + return false; + } + } else { + return false; + } + } + + private SkyboxRenderer() { + } + + public static boolean L() { + if (I && OnyxClient.moduleManager != null) { + Skybox skybox = OnyxClient.moduleManager.skybox; + if (!OnyxClient.moduleManager.skybox.F()) { + return false; + } + + if (!i) { + i = true; + shaderProgram = ShaderProgram.load("onyx_sky"); + } + + if (shaderProgram != null && shaderProgram.isLoaded()) { + try { + if (!L(skybox)) { + L(skybox); + } + + return true; + } catch (Throwable throwable) { + I = false; + RENDER_TARGET.delete(); + OnyxClient.LOGGER.warn("Custom skybox unavailable", throwable); + return false; + } + } else { + return false; + } + } else { + return false; + } + } + + private static void L() { + GlStateManager.matrixMode(5889); + GlStateManager.pushMatrix(); + GlStateManager.loadIdentity(); + GL11.glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); + GlStateManager.matrixMode(5888); + GlStateManager.pushMatrix(); + GlStateManager.loadIdentity(); + GlStateManager.disableAlpha(); + GlStateManager.disableDepth(); + GlStateManager.depthMask(false); + GlStateManager.disableLighting(); + GlStateManager.disableFog(); + GlStateManager.enableTexture2D(); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 771); + GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); + GlStateManager.bindTexture(RENDER_TARGET.getTexture()); + shaderProgram2.use(); + shaderProgram2.setUniform1i("Sampler0", 0); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glBegin(7); + GL11.glTexCoord2f(0.0F, 0.0F); + GL11.glVertex2f(0.0F, 0.0F); + GL11.glTexCoord2f(1.0F, 0.0F); + GL11.glVertex2f(1.0F, 0.0F); + GL11.glTexCoord2f(1.0F, 1.0F); + GL11.glVertex2f(1.0F, 1.0F); + GL11.glTexCoord2f(0.0F, 1.0F); + GL11.glVertex2f(0.0F, 1.0F); + GL11.glEnd(); + ShaderProgram.unbind(); + GlStateManager.matrixMode(5889); + GlStateManager.popMatrix(); + GlStateManager.matrixMode(5888); + GlStateManager.popMatrix(); + GlStateManager.disableBlend(); + GlStateManager.depthMask(true); + GlStateManager.enableDepth(); + GlStateManager.enableAlpha(); + GlStateManager.enableFog(); + GlStateManager.resetColor(); + } +} diff --git a/src/openonyx/render/TextureFilter.java b/src/openonyx/render/TextureFilter.java new file mode 100644 index 0000000..b0505e1 --- /dev/null +++ b/src/openonyx/render/TextureFilter.java @@ -0,0 +1,199 @@ +package openonyx.render; + +import java.nio.ByteBuffer; +import java.util.HashSet; +import java.util.Set; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.GL11; + +public enum TextureFilter { + SMOOTH, + MINIFIED, + PIXELS; + + private static final Set INTEGERS = new HashSet<>(); + private static final Set INTEGERS2 = new HashSet<>(); + + private static boolean d() { + int i = L(0, 4096); + int j = L(0, 4097); + int k = L(0, 4099); + if (i > 0 && j > 0) { + int l = 0; + + while (i > 1 || j > 1) { + i = Math.max(1, i / 2); + l++; + j = Math.max(1, j / 2); + if (L(l, 4096) != i) { + return false; + } + + if (L(l, 4097) != j) { + return false; + } + + if (L(l, 4099) != k) { + return false; + } + } + + return GL11.glGetTexParameteri(3553, 33085) >= l && GL11.glGetTexParameterf(3553, 33083) >= l; + } else { + return false; + } + } + + private static int L(int i, int j) { + return GL11.glGetTexLevelParameteri(3553, i, j); + } + + float L() { + return this == PIXELS ? 0.01F : 0.5F; + } + + public static void d(int i) { + INTEGERS.remove(i); + INTEGERS2.remove(i); + } + + void L(int i) { + if (this != PIXELS) { + GL11.glTexParameteri(3553, 10241, i); + GL11.glTexParameteri(3553, 10240, i); + } + } + + private static byte[] L(byte[] b, int i, int j, int k, int l) { + byte[] d = b; + byte[] e = new byte[k * l * 4]; + byte f = 1; + byte[] c = e; + + int m; + int n; + for (int y = m = 0; y < l; y = ++m) { + for (int z = n = 0; z < k; z = n) { + int o = 0; + int p = 0; + int q = 0; + int x = 0; + int r = 0; + + int s; + for (int ba = s = 0; ba < 2; ba = ++s) { + int t; + int u; + if ((t = m * 2 + s) < j) { + for (int bb = u = 0; bb < 2; bb = ++u) { + int v; + if ((v = n * 2 + u) < i) { + v = (t * i + v) * 4; + int w = d[v + 3] & 255; + o += (d[v] & 255) * w; + p += (d[v + 1] & 255) * w; + q += (d[v + 2] & 255) * w; + r++; + x += w; + } + } + } + } + + s = (m * k + n) * 4; + c[s] = (byte)(x == 0 ? 0 : o / x); + c[s + 1] = (byte)(x == 0 ? 0 : p / x); + c[s + 2] = (byte)(x == 0 ? 0 : q / x); + int bc = s + 3; + f = (byte)(r == 0 ? 0 : x / r); + n++; + c[bc] = f; + } + } + + return c; + } + + private static void L() { + int i = L(0, 4096); + int j = L(0, 4097); + int k = L(0, 4099); + if (i > 0 && j > 0 && k > 0) { + ByteBuffer byteBuffer = BufferUtils.createByteBuffer(i * j * 4); + GL11.glGetTexImage(3553, 0, 6408, 5121, byteBuffer); + byte[] c = new byte[i * j * 4]; + boolean bl = true; + byte[] b = c; + byteBuffer.get(b); + int n = 0; + int o = i; + + while (o > 1 || j > 1) { + int l = Math.max(1, i / 2); + int m = Math.max(1, j / 2); + b = L(b, i, j, l, m); + n++; + i = l; + j = m; + ByteBuffer byteBuffer1 = BufferUtils.createByteBuffer(b.length); + o = i; + byteBuffer1.put(b).flip(); + GL11.glTexImage2D(3553, n, k, i, j, 0, 6408, 5121, byteBuffer1); + } + + GL11.glTexParameteri(3553, 33085, n); + GL11.glTexParameterf(3553, 33082, 0.0F); + GL11.glTexParameterf(3553, 33083, n); + } + } + + int L() { + if (this == PIXELS) { + return 9728; + } + + if (this == MINIFIED && L()) { + GL11.glTexParameteri(3553, 10241, 9987); + } else { + GL11.glTexParameteri(3553, 10241, 9729); + } + + GL11.glTexParameteri(3553, 10240, 9729); + return 9728; + } + + private static boolean L() { + int i; + if ((i = GL11.glGetInteger(32873)) <= 0 || INTEGERS2.contains(i)) { + return false; + } + + if (INTEGERS.contains(i) && L(1, 4096) > 0) { + return true; + } + + INTEGERS.remove(i); + if (!d()) { + L(); + } + + if (d()) { + INTEGERS.add(i); + return true; + } else { + GL11.glTexParameteri(3553, 33085, 0); + GL11.glTexParameterf(3553, 33083, 0.0F); + INTEGERS2.add(i); + return false; + } + } + + private static TextureFilter[] L() { + TextureFilter[] textureFilters = new TextureFilter[3]; + boolean bl = true; + textureFilters[0] = PIXELS; + textureFilters[1] = SMOOTH; + textureFilters[2] = MINIFIED; + return textureFilters; + } +} diff --git a/src/openonyx/render/TrailShader.java b/src/openonyx/render/TrailShader.java new file mode 100644 index 0000000..3bd3f58 --- /dev/null +++ b/src/openonyx/render/TrailShader.java @@ -0,0 +1,331 @@ +package openonyx.render; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.shader.Framebuffer; +import net.minecraft.item.ItemSword; +import net.minecraft.util.MathHelper; +import net.minecraft.util.Vec3; +import openonyx.core.MinecraftAccess; +import openonyx.core.OnyxClient; +import openonyx.features.render.SmokeEffect; +import openonyx.render.group_p.ShaderProgram; +import openonyx.theme.internal.ColorUtils; +import org.lwjgl.opengl.GL11; + +public final class TrailShader implements MinecraftAccess { + private static ShaderProgram x; + private static ShaderProgram shaderProgram; + private static float y; + private static long n; + private static float Y; + private static final int r = 36; + private static ShaderProgram shaderProgram2; + private static ShaderProgram shaderProgram3; + private static boolean V; + private static final float R = 3.0F; + private static float p; + private static final float t = 0.25F; + private static float b; + private static final RenderTarget RENDER_TARGET = new RenderTarget(false); + private static float F; + private static boolean G; + private static float A = 1.0F; + private static float K; + private static final RenderTarget RENDER_TARGET2 = new RenderTarget(false); + private static final RenderTarget RENDER_TARGET3 = new RenderTarget(false); + private static final long J = System.nanoTime(); + private static ShaderProgram shaderProgram4; + private static final float c = 2.0F; + private static boolean a; + private static final double k = 3600.0; + private static ShaderProgram shaderProgram5; + private static float M; + private static ShaderProgram shaderProgram6; + private static float j; + private static final RenderTarget RENDER_TARGET4 = new RenderTarget(false); + private static float h = 0.016666668F; + private static final RenderTarget RENDER_TARGET5 = new RenderTarget(false); + private static long I; + private static final RenderTarget RENDER_TARGET6 = new RenderTarget(false); + private static final RenderTarget RENDER_TARGET7 = new RenderTarget(false); + private static final int f = 64; + private static final long H = 250L; + private static Vec3 vec3 = new Vec3(0.0, 0.0, 0.0); + + private static void L(RenderTarget renderTarget, RenderTarget renderTarget1) { + renderTarget1.bind(); + HandMaskShader.L(0, renderTarget.getTexture()); + shaderProgram.use(); + shaderProgram.setUniform1i("Sampler0", 0); + shaderProgram.setUniform2f("uSourceSize", renderTarget.getWidth(), renderTarget.getHeight()); + shaderProgram.setUniform2f("uOutSize", renderTarget1.getWidth(), renderTarget1.getHeight()); + HandMaskShader.L(); + } + + static void L() { + n = 0L; + I = 0L; + V = false; + vec3 = new Vec3(0.0, 0.0, 0.0); + p = 0.0F; + F = 0.0F; + j = 0.0F; + RENDER_TARGET6.delete(); + RENDER_TARGET2.delete(); + RENDER_TARGET7.delete(); + RENDER_TARGET4.delete(); + RENDER_TARGET5.delete(); + RENDER_TARGET3.delete(); + RENDER_TARGET.delete(); + } + + private static boolean d() { + if (!G) { + G = true; + shaderProgram2 = ShaderProgram.load("onyx_trail_mask", "onyx_post", "onyx_trail_mask"); + shaderProgram = ShaderProgram.load("onyx_trail_near", "onyx_post", "onyx_trail_near"); + shaderProgram3 = ShaderProgram.load("onyx_trail_step", "onyx_post", "onyx_trail_step"); + shaderProgram6 = ShaderProgram.load("onyx_trail_down", "onyx_post", "onyx_trail_down"); + x = ShaderProgram.load("onyx_trail_up", "onyx_post", "onyx_trail_up"); + shaderProgram5 = ShaderProgram.load("onyx_trail_smoke", "onyx_post", "onyx_trail_smoke"); + shaderProgram4 = ShaderProgram.load("onyx_hand_blit", "onyx_post", "onyx_hand_blit"); + } + + return L(shaderProgram2) && L(shaderProgram) && L(shaderProgram3) && L(shaderProgram6) && L(x) && L(shaderProgram5) && L(shaderProgram4); + } + + private static void L(ShaderProgram shaderProgram, RenderTarget renderTarget, RenderTarget renderTarget1) { + renderTarget1.bind(); + HandMaskShader.L(0, renderTarget.getTexture()); + shaderProgramx.use(); + shaderProgramx.setUniform1i("Sampler0", 0); + HandMaskShader.L(); + } + + private static void d(Minecraft minecraft, float f) { + y = 0.0F; + Y = 0.0F; + if (minecraft.getRenderViewEntity() != null && WorldToScreen.L()) { + float g = minecraft.getRenderViewEntity().prevRotationYaw + + (minecraft.getRenderViewEntity().rotationYaw - minecraft.getRenderViewEntity().prevRotationYaw) * fx; + fx = minecraft.getRenderViewEntity().prevRotationPitch + + (minecraft.getRenderViewEntity().rotationPitch - minecraft.getRenderViewEntity().prevRotationPitch) * fx; + Vec3 vec3x = WorldToScreen.getVec3(); + if (V) { + float hx = WorldToScreen.d(); + float i = WorldToScreen.L(); + y = (float)Math.toRadians(MathHelper.wrapAngleTo180_float(g - M)) * hx * 0.5F; + Y = -((float)Math.toRadians(fx - b)) * i * 0.5F; + Vec3 vec31 = vec3x.subtract(vec3); + Vec3 vec32 = L(g, fx); + Vec3 vec33 = L(g); + y = y + (float)vec31.dotProduct(vec33) * hx * 0.5F / 2.0F; + Y = Y + (float)vec31.dotProduct(vec33.crossProduct(vec32)) * i * 0.5F / 2.0F; + y = Math.clamp(y, -0.25F, 0.25F); + Y = Math.clamp(Y, -0.25F, 0.25F); + } + + M = g; + b = fx; + vec3 = vec3x; + V = true; + } else { + V = false; + } + } + + private static boolean L(ShaderProgram shaderProgram) { + return shaderProgramx != null && shaderProgramx.isLoaded(); + } + + private static void L(ShaderProgram shaderProgram, RenderTarget renderTarget, RenderTarget renderTarget1, float f) { + renderTarget1.bind(); + HandMaskShader.L(0, renderTarget.getTexture()); + shaderProgramx.use(); + shaderProgramx.setUniform1i("Sampler0", 0); + shaderProgramx.setUniform2f("uSourceSize", renderTarget.getWidth(), renderTarget.getHeight()); + shaderProgramx.setUniform1f("uBlur", fx); + HandMaskShader.L(); + } + + static void L(RenderTarget renderTarget, Framebuffer framebuffer, SmokeEffect smokeEffect, int i, float f, int j, int k, float g) { + RenderTarget renderTarget1 = renderTarget; + if (d()) { + Minecraft minecraft = MinecraftAccess.mc; + long l; + boolean bl = (l = System.currentTimeMillis()) - n > 250L; + n = l; + L(minecraft, g); + int m = renderTarget1.getWidth(); + int nx = renderTarget1.getHeight(); + boolean bl1 = bl + | RENDER_TARGET6.resize(jx, kx) + | RENDER_TARGET2.resize(m, nx) + | RENDER_TARGET7.resize(64, 36) + | RENDER_TARGET4.resize(m, nx) + | RENDER_TARGET5.resize(m, nx) + | RENDER_TARGET3.resize(m, nx) + | RENDER_TARGET.resize(m, nx); + HandMaskShader.L(0, RENDER_TARGET6.getTexture()); + GL11.glCopyTexSubImage2D(3553, 0, 0, 0, 0, 0, jx, kx); + HandMaskShader.d(); + L(shaderProgram2, renderTarget1, RENDER_TARGET2); + L(RENDER_TARGET2, RENDER_TARGET7); + L(smokeEffect, i, fx, bl1, jx, kx); + L(shaderProgram4, RENDER_TARGET5, RENDER_TARGET4); + float hx = Math.max(1.0F, 1.0F + smokeEffect.trailBlur.getFloat()) * smokeEffect.L(); + L(shaderProgram6, RENDER_TARGET5, RENDER_TARGET3, hx); + L(shaderProgram6, RENDER_TARGET3, RENDER_TARGET, hx * 2.0F); + L(x, RENDER_TARGET, RENDER_TARGET3, hx * 2.0F); + L(x, RENDER_TARGET3, RENDER_TARGET, hx); + L(smokeEffect, framebuffer, jx, kx); + HandMaskShader.L(framebuffer); + } + } + + private static void L(SmokeEffect smokeEffect, Framebuffer framebuffer, int i, int j) { + framebuffer.bindFramebuffer(false); + GlStateManager.viewport(0, 0, i, jx); + HandMaskShader.L(0, RENDER_TARGET6.getTexture()); + HandMaskShader.L(1, RENDER_TARGET.getTexture()); + HandMaskShader.L(2, RENDER_TARGET2.getTexture()); + shaderProgram5.use(); + shaderProgram5.setUniform1i("SceneSampler", 0); + shaderProgram5.setUniform1i("SmokeSampler", 1); + shaderProgram5.setUniform1i("MaskSampler", 2); + float fx = smokeEffect.smoke.getFloat(); + if (L()) { + fx *= 0.4F; + } else if (a) { + fx *= 0.55F; + } + + shaderProgram5.setUniform2f("uMaskSize", RENDER_TARGET2.getWidth(), RENDER_TARGET2.getHeight()); + shaderProgram5.setUniform4f("uSmokeParams", smokeEffect.intensity.getFloat(), smokeEffect.handSoftness.getFloat(), smokeEffect.handBlur.getFloat(), fx); + shaderProgram5.setUniform4f("uSmokeExtra", p, 0.0F, 0.0F, 0.0F); + HandMaskShader.L(); + } + + private static Vec3 L(float f, float g) { + double d = Math.toRadians(fx); + double e; + double hx = Math.cos(e = Math.toRadians(g)); + return new Vec3(-Math.sin(d) * hx, -Math.sin(e), Math.cos(d) * hx); + } + + private TrailShader() { + } + + private static float L() { + return (float)((System.nanoTime() - J) / 1.0E9 % 3600.0); + } + + private static void L(SmokeEffect smokeEffect, int i, float f, boolean bl, int m, int n) { + SmokeEffect smokeEffect1 = smokeEffect; + RENDER_TARGET5.bind(); + HandMaskShader.L(0, RENDER_TARGET4.getTexture()); + HandMaskShader.L(1, RENDER_TARGET6.getTexture()); + HandMaskShader.L(2, RENDER_TARGET2.getTexture()); + HandMaskShader.L(3, RENDER_TARGET7.getTexture()); + shaderProgram3.use(); + shaderProgram3.setUniform1i("PrevSampler", 0); + shaderProgram3.setUniform1i("SceneSampler", 1); + shaderProgram3.setUniform1i("MaskSampler", 2); + shaderProgram3.setUniform1i("NearSampler", 3); + shaderProgram3.setUniform2f("uOutSize", RENDER_TARGET5.getWidth(), RENDER_TARGET5.getHeight()); + boolean bl1 = L(); + float jx = smokeEffect1.trailFade.getFloat(); + float g = smokeEffect1.smoke.getFloat(); + float hx = smokeEffect1.length.getFloat(); + if (bl1) { + jx = Math.min(jx, 0.72F); + g *= 0.4F; + hx *= 0.4F; + } else if (a) { + jx = Math.min(jx, 0.8F); + g *= 0.55F; + hx *= 0.55F; + } + + shaderProgram3.setUniform4f("uTrailMotion", L(), smokeEffect1.intensity.getFloat(), smokeEffect1.speed.getFloat(), hx); + shaderProgram3.setUniform4f("uTrailShape", smokeEffect1.trailSoftness.getFloat(), smokeEffect1.trailBlur.getFloat(), g, p); + shaderProgram3.setUniform4f("uTrailSwing", jx, F, A, K); + float kx; + float l; + if (bl) { + kx = 1.0F; + l = fx; + } else { + kx = 0.0F; + l = fx; + } + + shaderProgram3.setUniform4f("uTrailCamera", y, Y, kx, l); + shaderProgram3.setUniform4f("uTrailTiming", h, smokeEffect1.L(), j, 0.0F); + shaderProgram3.setUniform4f("uGlowColor", ColorUtils.red(i) / 255.0F, ColorUtils.green(i) / 255.0F, ColorUtils.blue(i) / 255.0F, 1.0F); + HandMaskShader.L(); + HandMaskShader.L(3, 0); + } + + private static void L(Minecraft minecraft, float f) { + Minecraft minecraft1 = minecraft; + long l = System.currentTimeMillis(); + float nx = I > 0L ? (float)(l - I) / 1000.0F : 0.016666668F; + I = l; + if (nx <= 0.0F || nx > 0.05F) { + nx = h; + } + + float o = Math.clamp(nx, 0.0069444445F, 0.033333335F); + h = h + (o - h) * 0.1F; + float px = h; + EntityPlayerSP entityPlayerSP = minecraft1.thePlayer; + boolean bl = minecraft1.thePlayer != null + && entityPlayerSP.isBlocking() + && entityPlayerSP.getHeldItem() != null + && entityPlayerSP.getHeldItem().getItem() instanceof ItemSword; + boolean bl1 = entityPlayerSP != null && entityPlayerSP.isSwingInProgress && !bl; + a = bl1; + float hx = entityPlayerSP != null ? Math.clamp(entityPlayerSP.getSwingProgress(fx), 0.0F, 1.0F) : 0.0F; + float i = L() ? 0.3F : 0.5F; + float jx = entityPlayerSP == null + ? 0.0F + : (float)Math.min( + 1.0, + Math.sqrt( + entityPlayerSP.motionX * entityPlayerSP.motionX + + entityPlayerSP.motionY * entityPlayerSP.motionY + + entityPlayerSP.motionZ * entityPlayerSP.motionZ + ) + * 2.2 + ); + float kx = bl1 ? (1.0F - Math.min(1.0F, hx)) * i : 0.0F; + float m = entityPlayerSP != null && entityPlayerSP.isUsingItem() && !bl ? 0.55F + Math.min(0.45F, entityPlayerSP.getItemInUseDuration() * 0.06F) : 0.0F; + float g = Math.max(Math.max(kx, m), jx); + p = p + (g - p) * (1.0F - (float)Math.exp(-px * 6.0)); + K = entityPlayerSP == null ? 0.0F : 1.0F; + Minecraft minecraft2; + if (bl1) { + j = hx; + F = (float)Math.sin(Math.PI * hx) * i; + A = 1.0F; + minecraft2 = minecraft1; + } else { + F = Math.max(0.0F, F - px * 3.0F); + minecraft2 = minecraft1; + } + + d(minecraft2, fx); + } + + private static boolean L() { + return OnyxClient.moduleManager != null && OnyxClient.moduleManager.killAura.isEnabled() && OnyxClient.moduleManager.killAura.getTarget() != null; + } + + private static Vec3 L(float f) { + double d = Math.toRadians(fx); + return new Vec3(-Math.cos(d), 0.0, -Math.sin(d)); + } +}