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.
A tint, with no assets
The one effect CoolCatLib ships. Calltint(net.minecraft.resources.ResourceLocation, 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()
Your own shader
A mod brings its own post effect JSON and shaders (or uses vanilla's, likeminecraft:invert). Register
effects once, from client code (a ClientModConstructor is a good place), then turn them on and off as the
game goes:
// 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.ResourceLocationThe 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 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.ResourceLocation id) static ScreenEffectLayerslayers()The order effects are drawn in.static voidOpenscreateScreen(net.minecraft.client.gui.screens.Screen)over the current screen.static ScreenEffectregister(net.minecraft.resources.ResourceLocation id, ScreenEffectDefinition definition) Registers an effect from a definition built in code.static ScreenEffectregister(net.minecraft.resources.ResourceLocation id, net.minecraft.resources.ResourceLocation definition) Registers an effect loaded fromassets/<namespace>/post_effect/<path>.json, or else from a vanilla post chain atassets/<namespace>/shaders/post/<path>.json(vanilla's own included).static ScreenEffecttint(net.minecraft.resources.ResourceLocation 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.ResourceLocation id) Removes an effect and frees its GPU resources.
-
Field Details
-
TINT
public static final net.minecraft.resources.ResourceLocation 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(net.minecraft.resources.ResourceLocation, int). -
TINT_COLOR
TheTINTdefinition's color uniform.- See Also:
-
-
Method Details
-
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.ResourceLocation id, net.minecraft.resources.ResourceLocation definition) Registers an effect loaded fromassets/<namespace>/post_effect/<path>.json, or else from a vanilla post chain atassets/<namespace>/shaders/post/<path>.json(vanilla's own 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.ResourceLocation 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.ResourceLocation 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 @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(net.minecraft.client.gui.screens.Screen)over the current screen.
-