Skip to content

Screen effects ​

FxApi runs your full-screen shaders after the world is drawn, and it handles shake, flash and other screen effects. It is client only.

Set up a stage ​

Make one stage for your mod in your client init. Its shaders warm up with Rimulib's loading screen.

java
public static final FxApi.Stage STAGE = FxApi.stage("mymod");

Add a layer ​

A layer runs every frame. Add passes to draw shaders, and remove the layer when the effect ends.

java
FxApi.Layer pulse = frame -> {
    frame.pass("my_pulse", u -> {
        u.f1("Strength", 0.8F);
        u.v3("Target", target.subtract(cameraPos));
    });
    frame.screen().shake = 0.3F;
};

STAGE.add(pulse);
// Later
STAGE.remove(pulse);

Nothing is drawn while no layer adds a pass or a screen effect.

Write a shader ​

Put fragment shaders in assets/mymod/shaders/fx/. The name passed to pass is the file name without .fsh.

Rimulib adds its common.glsl to the top of every shader, so leave out #version and the shared declarations. It gives you texCoord, fragColor, DiffuseSampler, DepthSampler, Time, GTime, OutSize and helpers such as scenePosAt.

glsl
uniform float Strength;

void main() {
    vec3 scene = texture(DiffuseSampler, texCoord).rgb;
    fragColor = vec4(scene * (1.0 + Strength * sin(GTime * 4.0)), 1.0);
}

Use #include "file.glsl" to pull in your own files from the same folder, or Rimulib's if you have none by that name.

Uniforms ​

MethodSets
f1, f2, f3, f4A float or vector
v3A vector from a Vec3
vec4sAn array of vec4
texture(sampler, spec)An image, loaded in the background

Uniforms a shader does not use are ignored.

Screen effects ​

Set these fields on frame.screen(). They reset every frame.

shake, aberration, desaturate, zoomBlur, flash, flashR, flashG, flashB, vignette, vignetteR, vignetteG, vignetteB, bloom.