Class ScreenEffects
java.lang.Object
net.ixdarklord.coolcatcanvas.api.client.effect.ScreenEffects
Full-screen post-processing effects: color grading, distortion, blur, and whatever else a fragment shader can do to
the finished frame, with uniforms that can change every frame. Every effect is a
ScreenEffect: it fades in
and out, can be pulsed, driven by a condition or by the server, and stacks with any number of others.
A tint, with no assets
The one effect CoolCatLib ships. Calltint(Identifier, int) right where it's needed:
ScreenEffects.tint(MyMod.id("hurt"), 0x59FF0000).enableFor(5); // a red flash
ScreenEffects.tint(MyMod.id("frost"), 0x593366FF).enable(); // stays until disable()
A vanilla effect
Vanilla's post effects register by their id. They ignore the effect's strength, soautoBlend fades them:
ScreenEffect invert = ScreenEffects.register(MyMod.id("invert"), Identifier.withDefaultNamespace("invert")).autoBlend(true);
invert.enableFor(40);
Your own shader
A mod brings its ownpost_effect JSON and fragment shader (see ScreenEffectDefinition). Register it
once, from client code (a ClientModConstructor is a good place), then turn it on and off as the game goes,
or let it run itself:
// assets/mymod/post_effect/desaturate.json, drawing assets/mymod/shaders/post/desaturate.fsh
ScreenEffect insanity = ScreenEffects.register(MyMod.id("insanity"), MyMod.id("desaturate"))
.fade(40)
.activeWhen(context -> context.inWorld() && Sanity.of(context.player()) > 0.4F)
.strength(context -> Mth.inverseLerp(Sanity.of(context.player()), 0.4F, 0.8F))
.setUniform("Contrast", 1.4F);
Effects start disabled, and draw over the world unless moved to ScreenEffectScope.SCREEN. The server can
drive a player's effects too, tints included, through ScreenEffectControl.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final net.minecraft.resources.IdentifierThe built-in bloom definition: bright parts of the frame glow into what is around them.static final StringHow strong the glow is (0.9 by default).static final StringHow far the glow spreads, in pixels a blur step (2 by default).static final StringHow bright a pixel must be to glow, 0 to 1 (0.72 by default): lower lights up more of the frame.static final net.minecraft.resources.IdentifierThe built-in tint definition: washes the frame in itsColoruniform, a vec4 whose alpha is how far the frame is mixed towards the color (scaled by the effect's strength).static final StringTheTINTdefinition's color uniform. -
Method Summary
Modifier and TypeMethodDescriptionstatic Collection<ScreenEffect> all()static ScreenEffectbloom(net.minecraft.resources.Identifier id, float intensity) Bloom over the world, with nothing to set up: the first call for an id makes it, later ones set its strength and hand back the same effect.static net.minecraft.client.gui.screens.ScreencreateScreen(@Nullable net.minecraft.client.gui.screens.Screen parent) The effects screen: every selectable effect with a switch, the active ones as reorderable layers with a strength slider each, previewed live over the game.static voidHides every effect at once, e.g.static Optional<ScreenEffect> get(net.minecraft.resources.Identifier id) static ScreenEffectLayerslayers()The order effects are drawn in.static voidOpenscreateScreen(Screen)over the current screen.static ScreenEffectregister(net.minecraft.resources.Identifier id, ScreenEffectDefinition definition) Registers an effect from a definition built in code.static ScreenEffectregister(net.minecraft.resources.Identifier id, net.minecraft.resources.Identifier definition) Registers an effect loaded fromassets/<namespace>/post_effect/<path>.json, a vanilla one included.static ScreenEffecttint(net.minecraft.resources.Identifier id, int argb) A tint over the screen, with nothing to set up: the first call for an id makes the tint, later ones recolor it and hand back the same effect, so this can be called right where the tint is needed.static booleanunregister(net.minecraft.resources.Identifier id) Removes an effect and frees its GPU resources.
-
Field Details
-
TINT
public static final net.minecraft.resources.Identifier TINTThe built-in tint definition: washes the frame in itsColoruniform, a vec4 whose alpha is how far the frame is mixed towards the color (scaled by the effect's strength). Seetint(Identifier, int). -
TINT_COLOR
-
BLOOM
public static final net.minecraft.resources.Identifier BLOOMThe built-in bloom definition: bright parts of the frame glow into what is around them. Seebloom(Identifier, float). -
BLOOM_THRESHOLD
How bright a pixel must be to glow, 0 to 1 (0.72 by default): lower lights up more of the frame.- See Also:
-
BLOOM_INTENSITY
-
BLOOM_RADIUS
How far the glow spreads, in pixels a blur step (2 by default).- See Also:
-
-
Method Details
-
bloom
Bloom over the world, with nothing to set up: the first call for an id makes it, later ones set its strength and hand back the same effect. World effects, fire, lava, the sun and anything else bright glow softly.
It is aScreenEffects.bloom(MyMod.id("glow"), 0.9F).enable(); // on until disable() ScreenEffects.bloom(MyMod.id("blast"), 2.5F).fade(10).enableFor(4); // a surge of light that dies away ScreenEffects.bloom(MyMod.id("glow"), 1.2F).setUniform(ScreenEffects.BLOOM_THRESHOLD, 0.55F);ScreenEffectlike any other. Bloom costs six full-screen passes while it is visible, so leave it off when nothing needs it.- Parameters:
intensity- how strong the glow is; around 1 is gentle, 2 and up is a haze- Throws:
IllegalArgumentException- if the id belongs to an effect that isn't a bloom
-
tint
A tint over the screen, with nothing to set up: the first call for an id makes the tint, later ones recolor it and hand back the same effect, so this can be called right where the tint is needed.
Each id is its own effect, with its own color and state. It's aScreenEffects.tint(MyMod.id("hurt"), 0x59FF0000).enableFor(5); // a red flash ScreenEffects.tint(MyMod.id("frost"), 0x593366FF).enable(); // stays until disable() // Over the HUD and menus too, with a slow fade. ScreenEffects.tint(MyMod.id("blackout"), 0xE6000000).scope(ScreenEffectScope.SCREEN).fade(40).enable(); // Set up once, then it runs by itself: redder the lower the player's health. ScreenEffects.tint(MyMod.id("low_health"), 0x66FF0000) .activeWhen(context -> context.inWorld() && context.player().getHealth() < 8.0F) .strength(context -> 1.0F - context.player().getHealth() / 8.0F);ScreenEffectlike any other (fades, strength, conditions), drawn over the world unless moved toScreenEffectScope.SCREEN. Unlike registered effects it starts out of the effects screen;selectable(true)lists it. To change the color smoothly instead of at once, animate itsTINT_COLORuniform.- Parameters:
argb- the color; its alpha is how strong the tint is at full strength- Throws:
IllegalArgumentException- if the id belongs to an effect that isn't a tint
-
register
public static ScreenEffect register(net.minecraft.resources.Identifier id, net.minecraft.resources.Identifier definition) Registers an effect loaded fromassets/<namespace>/post_effect/<path>.json, a vanilla one included. It's loaded with the game's resources, and reloaded with them.- Throws:
IllegalArgumentException- if the id is taken
-
register
public static ScreenEffect register(net.minecraft.resources.Identifier id, ScreenEffectDefinition definition) Registers an effect from a definition built in code. Its shaders still come from resources.- Throws:
IllegalArgumentException- if the id is taken
-
get
-
all
-
unregister
public static boolean unregister(net.minecraft.resources.Identifier id) Removes an effect and frees its GPU resources. -
disableAllInstantly
public static void disableAllInstantly()Hides every effect at once, e.g. for a cutscene or a clean screenshot. -
layers
The order effects are drawn in. -
createScreen
public static net.minecraft.client.gui.screens.Screen createScreen(@Nullable net.minecraft.client.gui.screens.Screen parent) The effects screen: every selectable effect with a switch, the active ones as reorderable layers with a strength slider each, previewed live over the game. Players' choices there are remembered across sessions. Also bound to a key (unset by default), and in a development environment/coolcatcanvas_client effects. -
openScreen
public static void openScreen()OpenscreateScreen(Screen)over the current screen.
-