Search in sources :

Example 1 with Framebuffer

use of meteordevelopment.meteorclient.renderer.Framebuffer in project meteor-client by MeteorDevelopment.

the class Blur method onRenderAfterWorld.

private void onRenderAfterWorld() {
    // Enable / disable with fading
    boolean shouldRender = shouldRender();
    long time = System.currentTimeMillis();
    if (enabled) {
        if (!shouldRender) {
            if (fadeEndAt == -1)
                fadeEndAt = System.currentTimeMillis() + fadeTime.get();
            if (time >= fadeEndAt) {
                enabled = false;
                fadeEndAt = -1;
            }
        }
    } else {
        if (shouldRender) {
            enabled = true;
            fadeEndAt = System.currentTimeMillis() + fadeTime.get();
        }
    }
    if (!enabled)
        return;
    // Initialize shader and framebuffer if running for the first time
    if (shader == null) {
        shader = new Shader("blur.vert", "blur.frag");
        fbo1 = new Framebuffer();
        fbo2 = new Framebuffer();
    }
    // Prepare stuff for rendering
    int sourceTexture = mc.getFramebuffer().getColorAttachment();
    shader.bind();
    shader.set("u_Size", mc.getWindow().getFramebufferWidth(), mc.getWindow().getFramebufferHeight());
    shader.set("u_Texture", 0);
    // Update progress
    double progress = 1;
    if (time < fadeEndAt) {
        if (shouldRender)
            progress = 1 - (fadeEndAt - time) / fadeTime.get().doubleValue();
        else
            progress = (fadeEndAt - time) / fadeTime.get().doubleValue();
    } else {
        fadeEndAt = -1;
    }
    // Render the blur
    shader.set("u_Radius", Math.floor(radius.get() * progress));
    PostProcessRenderer.beginRender();
    fbo1.bind();
    GL.bindTexture(sourceTexture);
    shader.set("u_Direction", 1.0, 0.0);
    PostProcessRenderer.render();
    if (mode.get() == Mode.Fancy)
        fbo2.bind();
    else
        fbo2.unbind();
    GL.bindTexture(fbo1.texture);
    shader.set("u_Direction", 0.0, 1.0);
    PostProcessRenderer.render();
    if (mode.get() == Mode.Fancy) {
        fbo1.bind();
        GL.bindTexture(fbo2.texture);
        shader.set("u_Direction", 1.0, 0.0);
        PostProcessRenderer.render();
        fbo2.unbind();
        GL.bindTexture(fbo1.texture);
        shader.set("u_Direction", 0.0, 1.0);
        PostProcessRenderer.render();
    }
    PostProcessRenderer.endRender();
}
Also used : Framebuffer(meteordevelopment.meteorclient.renderer.Framebuffer) Shader(meteordevelopment.meteorclient.renderer.Shader)

Aggregations

Framebuffer (meteordevelopment.meteorclient.renderer.Framebuffer)1 Shader (meteordevelopment.meteorclient.renderer.Shader)1