hell yeah, glsl shaders. Credit to focalsalt for being a massive help.
This commit is contained in:
parent
8bb384d0d7
commit
a49a1c238b
6 changed files with 326 additions and 0 deletions
84
assets/minecraft/shaders/core/position_color.fsh
Normal file
84
assets/minecraft/shaders/core/position_color.fsh
Normal file
|
@ -0,0 +1,84 @@
|
|||
#version 150
|
||||
|
||||
in vec4 vertexColor;
|
||||
|
||||
flat in vec2 flatCorner;
|
||||
in vec2 Pos1;
|
||||
in vec2 Pos2;
|
||||
in vec4 Coords;
|
||||
in vec2 position;
|
||||
|
||||
uniform vec4 ColorModulator;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
vec4 colors[4] = vec4[](
|
||||
vec4(0),
|
||||
vec4(20, 17, 25, 255) / 255,
|
||||
vec4(73, 40, 121, 255) / 255,
|
||||
vec4(42, 31, 61, 255) / 255
|
||||
);
|
||||
|
||||
int bitmap[64] = int[](
|
||||
0, 0, 1, 1, 1, 1, 1, 1,
|
||||
0, 1, 3, 3, 3, 3, 3, 3,
|
||||
1, 3, 3, 2, 2, 2, 2, 2,
|
||||
1, 3, 2, 2, 3, 3, 3, 3,
|
||||
1, 3, 2, 3, 3, 3, 3, 3,
|
||||
1, 3, 2, 3, 3, 3, 3, 3,
|
||||
1, 3, 2, 3, 3, 3, 3, 3,
|
||||
1, 3, 2, 3, 3, 3, 3, 3
|
||||
);
|
||||
|
||||
|
||||
|
||||
void main() {
|
||||
vec4 color = vertexColor;
|
||||
if (color.a == 0.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
fragColor = color * ColorModulator;
|
||||
|
||||
if (flatCorner != vec2(-1))
|
||||
{
|
||||
//Actual Pos
|
||||
vec2 APos1 = Pos1;
|
||||
vec2 APos2 = Pos2;
|
||||
APos1 = round(APos1 / (flatCorner.x == 0 ? 1 - Coords.z : 1 - Coords.w)); //Right-up corner
|
||||
APos2 = round(APos2 / (flatCorner.x == 0 ? Coords.w : Coords.z)); //Left-down corner
|
||||
|
||||
ivec2 res = ivec2(abs(APos1 - APos2)) - 1; //Resolution of frame
|
||||
ivec2 stp = ivec2(min(APos1, APos2)); //Left-Up corner
|
||||
ivec2 pos = ivec2(floor(position)) - stp; //Position in frame
|
||||
|
||||
vec4 col = vec4(42, 31, 61, 255) / 255.0;
|
||||
col.rgb -= max(1 - length((pos - res / 2.0) / res) * 2, 0) / 10;
|
||||
|
||||
ivec2 corner = min(pos, res - pos);
|
||||
|
||||
if (corner.x < 8 && corner.y < 8)
|
||||
{
|
||||
int bit = bitmap[corner.y * 8 + corner.x];
|
||||
if (bit == 0)
|
||||
discard;
|
||||
if (bit != 4)
|
||||
col = colors[bit];
|
||||
}
|
||||
else if (corner.x == 0) // left and right side: Outer
|
||||
col = colors[1];
|
||||
else if (corner.x == 2) // left and right side: Middle
|
||||
col = colors[3];
|
||||
else if (corner.x == 3) // left and right side: Inner ish
|
||||
col = colors[2];
|
||||
else if (corner.y == 0) // top and bottom side: Outer
|
||||
col = colors[1];
|
||||
else if (corner.y == 2) // top and bottom side: Middle
|
||||
col = colors[3];
|
||||
else if (corner.y == 3) // top and bottom side: Inner ish
|
||||
col = colors[2];
|
||||
|
||||
fragColor = col;
|
||||
|
||||
}
|
||||
}
|
19
assets/minecraft/shaders/core/position_color.json
Normal file
19
assets/minecraft/shaders/core/position_color.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"blend": {
|
||||
"func": "add",
|
||||
"srcrgb": "srcalpha",
|
||||
"dstrgb": "1-srcalpha"
|
||||
},
|
||||
"vertex": "position_color",
|
||||
"fragment": "position_color",
|
||||
"attributes": [
|
||||
"Color"
|
||||
],
|
||||
"samplers": [
|
||||
],
|
||||
"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": "ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] }
|
||||
]
|
||||
}
|
61
assets/minecraft/shaders/core/position_color.vsh
Normal file
61
assets/minecraft/shaders/core/position_color.vsh
Normal file
|
@ -0,0 +1,61 @@
|
|||
#version 150
|
||||
|
||||
in vec3 Position;
|
||||
in vec4 Color;
|
||||
|
||||
uniform mat4 ModelViewMat;
|
||||
uniform mat4 ProjMat;
|
||||
|
||||
uniform vec2 ScreenSize;
|
||||
|
||||
out vec4 vertexColor;
|
||||
out vec4 Coords;
|
||||
out vec2 position;
|
||||
|
||||
flat out vec2 flatCorner;
|
||||
out vec2 Pos1;
|
||||
out vec2 Pos2;
|
||||
|
||||
bool isTooltip(mat4 ProjMat,vec3 Position) {
|
||||
return ProjMat[2][3] == 0 && Position.z > 300 && Position.z < 500;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vertexColor = Color;
|
||||
|
||||
gl_Position = ProjMat * ModelViewMat * vec4(Position, 1.0);
|
||||
|
||||
Coords = vec4(-1);
|
||||
position = vec2(-1);
|
||||
Pos1 = vec2(-1);
|
||||
Pos2 = vec2(-1);
|
||||
flatCorner = vec2(-1);
|
||||
|
||||
//Tooltip frame
|
||||
if (Color.r != 0 && Color.g == 0 && Color.b != 0 && ProjMat[3][0] == -1)
|
||||
{
|
||||
int id = gl_VertexID / 4;
|
||||
|
||||
int vertID = (gl_VertexID) % 4;
|
||||
const vec2[4] corners = vec2[4](vec2(0, 0), vec2(0, 1), vec2(1, 1), vec2(1, 0));
|
||||
vec2 ScrSize = 2 / vec2(ProjMat[0][0], -ProjMat[1][1]);
|
||||
vec3 Pos = Position - vec3(corners[((gl_VertexID) ) % 4] * -10 - (-10 / 2.0), 0);
|
||||
|
||||
Pos1 = Pos2 = vec2(0);
|
||||
if (vertID == 0) Pos1 = Pos.xy;
|
||||
if (vertID == 2) Pos2 = Pos.xy;
|
||||
|
||||
Coords.xy = ScrSize;
|
||||
Coords.zw = flatCorner = corners[vertID];
|
||||
position = Pos.xy;
|
||||
|
||||
if (id != 2)
|
||||
Pos.xy = vec2(0);
|
||||
|
||||
gl_Position = ProjMat * ModelViewMat * vec4(Pos, 1);
|
||||
}
|
||||
|
||||
if (isTooltip(ProjMat, Position) && (gl_Position.x > 1 || gl_Position.x < -0.99)) {
|
||||
vertexColor = vec4(0);
|
||||
}
|
||||
}
|
82
assets/minecraft/shaders/core/rendertype_gui.fsh
Normal file
82
assets/minecraft/shaders/core/rendertype_gui.fsh
Normal file
|
@ -0,0 +1,82 @@
|
|||
#version 150
|
||||
|
||||
in vec4 vertexColor;
|
||||
|
||||
flat in vec2 flatCorner;
|
||||
in vec2 Pos1;
|
||||
in vec2 Pos2;
|
||||
in vec4 Coords;
|
||||
in vec2 position;
|
||||
|
||||
uniform vec4 ColorModulator;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
vec4 colors[4] = vec4[](
|
||||
vec4(0),
|
||||
vec4(20, 17, 25, 255) / 255,
|
||||
vec4(73, 40, 121, 255) / 255,
|
||||
vec4(42, 31, 61, 255) / 255
|
||||
);
|
||||
|
||||
int bitmap[64] = int[](
|
||||
0, 0, 1, 1, 1, 1, 1, 1,
|
||||
0, 1, 3, 3, 3, 3, 3, 3,
|
||||
1, 3, 3, 2, 2, 2, 2, 2,
|
||||
1, 3, 2, 2, 3, 3, 3, 3,
|
||||
1, 3, 2, 3, 3, 3, 3, 3,
|
||||
1, 3, 2, 3, 3, 3, 3, 3,
|
||||
1, 3, 2, 3, 3, 3, 3, 3,
|
||||
1, 3, 2, 3, 3, 3, 3, 3
|
||||
);
|
||||
|
||||
|
||||
|
||||
void main() {
|
||||
vec4 color = vertexColor;
|
||||
if (color.a == 0.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
fragColor = color * ColorModulator;
|
||||
|
||||
if (flatCorner != vec2(-1))
|
||||
{
|
||||
//Actual Pos
|
||||
vec2 APos1 = Pos1;
|
||||
vec2 APos2 = Pos2;
|
||||
APos1 = round(APos1 / (flatCorner.x == 0 ? 1 - Coords.z : 1 - Coords.w)); //Right-up corner
|
||||
APos2 = round(APos2 / (flatCorner.x == 0 ? Coords.w : Coords.z)); //Left-down corner
|
||||
|
||||
ivec2 res = ivec2(abs(APos1 - APos2)) - 1; //Resolution of frame
|
||||
ivec2 stp = ivec2(min(APos1, APos2)); //Left-Up corner
|
||||
ivec2 pos = ivec2(floor(position)) - stp; //Position in frame
|
||||
|
||||
vec4 col = vec4(42, 31, 61, 255) / 255.0;
|
||||
ivec2 corner = min(pos, res - pos);
|
||||
|
||||
if (corner.x < 8 && corner.y < 8)
|
||||
{
|
||||
int bit = bitmap[corner.y * 8 + corner.x];
|
||||
if (bit == 0)
|
||||
discard;
|
||||
if (bit != 4)
|
||||
col = colors[bit];
|
||||
}
|
||||
else if (corner.x == 0) // left and right side: Outer
|
||||
col = colors[1];
|
||||
else if (corner.x == 1) // left and right side: Middle
|
||||
col = colors[3];
|
||||
else if (corner.x == 2) // left and right side: Inner ish
|
||||
col = colors[2];
|
||||
else if (corner.y == 0) // top and bottom side: Outer
|
||||
col = colors[1];
|
||||
else if (corner.y == 1) // top and bottom side: Middle
|
||||
col = colors[3];
|
||||
else if (corner.y == 2) // top and bottom side: Inner ish
|
||||
col = colors[2];
|
||||
|
||||
fragColor = col;
|
||||
|
||||
}
|
||||
}
|
19
assets/minecraft/shaders/core/rendertype_gui.json
Normal file
19
assets/minecraft/shaders/core/rendertype_gui.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"blend": {
|
||||
"func": "add",
|
||||
"srcrgb": "srcalpha",
|
||||
"dstrgb": "1-srcalpha"
|
||||
},
|
||||
"vertex": "rendertype_gui",
|
||||
"fragment": "rendertype_gui",
|
||||
"attributes": [
|
||||
"Color"
|
||||
],
|
||||
"samplers": [
|
||||
],
|
||||
"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": "ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] }
|
||||
]
|
||||
}
|
61
assets/minecraft/shaders/core/rendertype_gui.vsh
Normal file
61
assets/minecraft/shaders/core/rendertype_gui.vsh
Normal file
|
@ -0,0 +1,61 @@
|
|||
#version 150
|
||||
|
||||
in vec3 Position;
|
||||
in vec4 Color;
|
||||
|
||||
uniform mat4 ModelViewMat;
|
||||
uniform mat4 ProjMat;
|
||||
|
||||
uniform vec2 ScreenSize;
|
||||
|
||||
out vec4 vertexColor;
|
||||
out vec4 Coords;
|
||||
out vec2 position;
|
||||
|
||||
flat out vec2 flatCorner;
|
||||
out vec2 Pos1;
|
||||
out vec2 Pos2;
|
||||
|
||||
bool isTooltip(mat4 ProjMat,vec3 Position) {
|
||||
return ProjMat[2][3] == 0 && Position.z > 300 && Position.z < 500;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vertexColor = Color;
|
||||
|
||||
gl_Position = ProjMat * ModelViewMat * vec4(Position, 1.0);
|
||||
|
||||
Coords = vec4(-1);
|
||||
position = vec2(-1);
|
||||
Pos1 = vec2(-1);
|
||||
Pos2 = vec2(-1);
|
||||
flatCorner = vec2(-1);
|
||||
|
||||
//Tooltip frame
|
||||
if (Color.r != 0 && Color.g == 0 && Color.b != 0 && ProjMat[3][0] == -1)
|
||||
{
|
||||
int id = gl_VertexID / 4;
|
||||
|
||||
int vertID = (gl_VertexID) % 4;
|
||||
const vec2[4] corners = vec2[4](vec2(0, 0), vec2(0, 1), vec2(1, 1), vec2(1, 0));
|
||||
vec2 ScrSize = 2 / vec2(ProjMat[0][0], -ProjMat[1][1]);
|
||||
vec3 Pos = Position - vec3(corners[((gl_VertexID) ) % 4] * 10 - (10 / 2.0), 0);
|
||||
|
||||
Pos1 = Pos2 = vec2(0);
|
||||
if (vertID == 0) Pos1 = Pos.xy;
|
||||
if (vertID == 2) Pos2 = Pos.xy;
|
||||
|
||||
Coords.xy = ScrSize;
|
||||
Coords.zw = flatCorner = corners[vertID];
|
||||
position = Pos.xy;
|
||||
|
||||
if (id != 2)
|
||||
Pos.xy = vec2(0);
|
||||
|
||||
gl_Position = ProjMat * ModelViewMat * vec4(Pos, 1);
|
||||
}
|
||||
|
||||
if (isTooltip(ProjMat, Position) && (gl_Position.x > 1 || gl_Position.x < -0.99)) {
|
||||
vertexColor = vec4(0);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue