Search in sources :

Example 1 with Framebuffer

use of mathax.client.renderer.Framebuffer in project Client by MatHax.

the class Background 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;
    switch(backgroundMode.get()) {
        case Blur:
            // Initialize shader and framebuffer if running for the first time
            if (shader == null) {
                shader = new Shader("background/blur.vert", "background/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(blurRadius.get() * progress));
            PostProcessRenderer.beginRender();
            fbo1.bind();
            GL.bindTexture(sourceTexture);
            shader.set("u_Direction", 1.0, 0.0);
            PostProcessRenderer.render();
            if (blurMode.get() == BlurMode.Fancy)
                fbo2.bind();
            else
                fbo2.unbind();
            GL.bindTexture(fbo1.texture);
            shader.set("u_Direction", 0.0, 1.0);
            PostProcessRenderer.render();
            if (blurMode.get() == BlurMode.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(mathax.client.renderer.Framebuffer) Shader(mathax.client.renderer.Shader)

Aggregations

Framebuffer (mathax.client.renderer.Framebuffer)1 Shader (mathax.client.renderer.Shader)1