-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
I'm going to assume you know what a resource pack is and that you have at least a little bit of experience programming. I'll explain some terms, especially those related to shader programming, but it's recommended that you know some stuff. If you know what you're doing, or just want to see the final result, click here.
As you now know, it's possible to create these shaders completely vanilla, by using a resource pack.
Once you've got your resource pack, you'll need to create a folder called shaders
in the minecraft
directory.
After this, you're free to create directories as you wish, but Minecraft has a core
folder so I'll be using one too.
Minecraft comes with three files used for basic text, you can view these in your .jar file.
As you can see, there are a lot of different shaders that you can experiment with. The ones we'll use today are the rendertype_text
ones. These are responsible for what all of the text in Minecraft looks like, except nametags. They're used in titles, the inventory, but most importantly - in chat!
Those files should be copied from the vanilla jar into your resource pack.
Alternatively, you can create these files in your resource pack.
#version 150
#moj_import <fog.glsl>
in vec3 Position;
in vec4 Color;
in vec2 UV0;
in ivec2 UV2;
uniform sampler2D Sampler2;
uniform mat4 ModelViewMat;
uniform mat4 ProjMat;
uniform mat3 IViewRotMat;
uniform int FogShape;
out float vertexDistance;
out vec4 vertexColor;
out vec2 texCoord0;
void main() {
gl_Position = ProjMat * ModelViewMat * vec4(Position, 1.0);
vertexDistance = fog_distance(ModelViewMat, IViewRotMat * Position, FogShape);
vertexColor = Color * texelFetch(Sampler2, UV2 / 16, 0);
texCoord0 = UV0;
}
This is a vertex shader, these typically define how the vertices act.
{
"blend": {
"func": "add",
"srcrgb": "srcalpha",
"dstrgb": "1-srcalpha"
},
"vertex": "rendertype_text",
"fragment": "rendertype_text",
"attributes": [
"Position",
"Color",
"UV0",
"UV2"
],
"samplers": [
{ "name": "Sampler0" },
{ "name": "Sampler2" }
],
"uniforms": [
{ "name": "ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "IViewRotMat", "type": "matrix3x3", "count": 9, "values": [ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ] },
{ "name": "ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] },
{ "name": "FogStart", "type": "float", "count": 1, "values": [ 0.0 ] },
{ "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] },
{ "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] },
{ "name": "FogShape", "type": "int", "count": 1, "values": [ 0 ] }
]
}
We won't be touching this file much, but if you wanted to rename your other files, you should update the vertex
and fragment
parts of this file.
The attributes
are useful as they can be used as inputs for the shader files.
#version 150
#moj_import <fog.glsl>
uniform sampler2D Sampler0;
uniform vec4 ColorModulator;
uniform float FogStart;
uniform float FogEnd;
uniform vec4 FogColor;
in float vertexDistance;
in vec4 vertexColor;
in vec2 texCoord0;
out vec4 fragColor;
void main() {
vec4 color = texture(Sampler0, texCoord0) * vertexColor * ColorModulator;
if (color.a < 0.1) {
discard;
}
fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor);
}
This little guy is a fragment shader, typically used to define how the pixels look.
We won't be using this as we can define how the pixels look in the vertex shader, too.