Overlay effects in vanilla Minecraft using shaders
This article describes how you can make your own simple overlay effects in vanilla minecraft using core shaders and fonts. This method is compatible with mods like Sodium or Iris. It's limited to overlays since you can access the current render state from the shader
1. Filling the screen
First off, we want a single character to fill the whole screen when its rendered. For this we will use a vertex shader, to align the vertices of the letter plane with the corners of the game window.
rendertype_text.vsh
/* GLSL code block placeholder */
You will also need the json for the shader:
/* JSON code block placeholder */
Nice, we now have a shader that produces very large characters.
2. Custom font
Since we don't want out shader to maximise all characters, we will make a custom font with a character that has a special texture which we will use to identify the character in the shader.
First off create the texture; a 5x5 texture with the first pixel's alpha value being 254 and an RGB value of #010101 (or any other alpha/color combination you want to use)
Then the font:
/* JSON code block placeholder */
You can test your character using
/tellraw {"text": "A", "font": "thing:me"}
3. Fragment shader
Now, just 1 solid color is not much of an effect and the character will stay visible as long as its still in the chat log of the client.
In order to show/hide the character whenever we want, we use the title command.
The fade-in and fade-out duration as well as the duration the title stays in the screen for can
be configured on a per-player basis using the title command.
This is not only useful for a very basic fading effect to fade to black and back, but it also
gives us a time variable - we can use the transparency
of the title in the shader for that!