summaryrefslogtreecommitdiff
path: root/assets/minecraft/shaders/include
diff options
context:
space:
mode:
Diffstat (limited to 'assets/minecraft/shaders/include')
-rwxr-xr-xassets/minecraft/shaders/include/emissive_utils.glsl102
-rwxr-xr-xassets/minecraft/shaders/include/player.glsl49
2 files changed, 151 insertions, 0 deletions
diff --git a/assets/minecraft/shaders/include/emissive_utils.glsl b/assets/minecraft/shaders/include/emissive_utils.glsl
new file mode 100755
index 00000000..d0c999cb
--- /dev/null
+++ b/assets/minecraft/shaders/include/emissive_utils.glsl
@@ -0,0 +1,102 @@
1#version 150
2
3// Checking for the exact alpha value breaks things, so I use this function to cut down on space while also making it work better.
4
5bool check_alpha(float textureAlpha, float targetAlpha) {
6
7 float targetLess = targetAlpha - 0.01;
8 float targetMore = targetAlpha + 0.01;
9 return (textureAlpha > targetLess && textureAlpha < targetMore);
10
11}
12
13
14// For cases in which you want something to have a lower light level, but still be bright when in light.
15
16vec4 apply_partial_emissivity(vec4 inputColor, vec4 originalLightColor, vec3 minimumLightColor) {
17
18 vec4 newLightColor = originalLightColor;
19 newLightColor.r = max(originalLightColor.r, minimumLightColor.r);
20 newLightColor.g = max(originalLightColor.g, minimumLightColor.g);
21 newLightColor.b = max(originalLightColor.b, minimumLightColor.b);
22 return inputColor * newLightColor;
23
24}
25
26
27// The meat and bones of the pack, does all the work for making things emissive.
28
29vec4 make_emissive(vec4 inputColor, vec4 lightColor, vec4 maxLightColor, float vertexDistance, float inputAlpha) {
30
31 if (vertexDistance > 800) return inputColor; // Vertex Distance > 800 generally means an object is in the UI, which we don't want to affect.
32
33 if (check_alpha(inputAlpha, 252.0)) return inputColor; // Checks for alpha 252 and just returns the input color if it is. Used in the example pack for redstone ore and the zombie's eyes.
34 else if (check_alpha(inputAlpha, 251.0)) return apply_partial_emissivity(inputColor, lightColor, vec3(0.411, 0.345, 0.388)); // Used in the example pack for ice.
35 else if (check_alpha(inputAlpha, 250.0)) return inputColor; // You can copy & this line and change the function to add a new emissive type. Used in the example pack for lime concrete.
36
37 else return inputColor * lightColor; // If none of the pixels are supposed to be emissive, then it adds the light.
38
39}
40
41
42// Gets the dimension that an object is in, -1 for The Nether, 0 for The Overworld, 1 for The End.
43
44float get_dimension(vec4 minLightColor) {
45
46 if (minLightColor.r == minLightColor.g && minLightColor.g == minLightColor.b) return 0.0; // Shadows are grayscale in The Overworld
47 else if (minLightColor.r > minLightColor.g) return -1.0; // Shadows are more red in The Nether
48 else return 1.0; // Shadows are slightly green in The End
49
50}
51
52
53// Gets the face lighting of a block. Credits to Venaxsys for the original function.
54
55vec4 get_face_lighting(vec3 normal, float dimension) {
56
57 vec4 faceLighting = vec4(1.0, 1.0, 1.0, 1.0);
58 vec3 absNormal = abs(normal);
59 float top = 229.0 / 255.0;
60 float bottom = 127.0 / 255.0;
61 float east = 153.0 / 255.0;
62 float north = 204.0 / 255.0;
63
64 // Top (only required in the Nether)
65 if (normal.y > normal.z && normal.y > normal.x && check_alpha(dimension, -1.0)) faceLighting = vec4(top, top, top, 1.0); // It's not really checking the alpha but I'm too stubborn to change the function name
66
67 // Bottom
68 if (normal.y < normal.z && normal.y < normal.x && !check_alpha(dimension, -1.0)) faceLighting = vec4(bottom, bottom, bottom, 1.0);
69 else if (normal.y < normal.z && normal.y < normal.x && check_alpha(dimension, -1.0)) faceLighting = vec4(top, top, top, 1.0);
70
71 // East-West
72 if (absNormal.x > absNormal.z && absNormal.x > absNormal.y) faceLighting = vec4(east, east, east, 1.0);
73
74 // North-South
75 if (absNormal.z > absNormal.x && absNormal.z > absNormal.y) faceLighting = vec4(north, north, north, 1.0);
76
77 return faceLighting;
78}
79
80
81// Checks the alpha and removes face lighting if required.
82
83vec4 face_lighting_check(vec3 normal, float inputAlpha, float dimension) {
84
85 if (check_alpha(inputAlpha, 250.0)) return get_face_lighting(normal, dimension); // Checks for alpha 250, and runs it through the remove_face_lighting() function if it is. Used in the example pack for lime concrete.
86 else return vec4(1.0, 1.0, 1.0, 1.0); // If the block doesn't need to have its face lighting removed, returns 1.0 so nothing gets divided.
87
88}
89
90
91// Makes sure transparent things don't become solid and vice versa.
92
93float remap_alpha(float inputAlpha) {
94
95 if (check_alpha(inputAlpha, 252.0)) return 255.0; // Checks for alpha 252 and converts all pixels of that to alpha 255. Used in the example pack for redstone ore and the zombie's eyes.
96 else if (check_alpha(inputAlpha, 251.0)) return 190.0; // You can copy & paste this line and change the values to make any transparent block work with this pack. Used in the example pack for ice.
97 else if (check_alpha(inputAlpha, 250.0)) return 255.0; // Used in the example pack for lime concrete.
98
99 else return inputAlpha; // If a pixel doesn't need to have its alpha changed then it simply does not change.
100
101}
102
diff --git a/assets/minecraft/shaders/include/player.glsl b/assets/minecraft/shaders/include/player.glsl
new file mode 100755
index 00000000..a421a1ff
--- /dev/null
+++ b/assets/minecraft/shaders/include/player.glsl
@@ -0,0 +1,49 @@
1if (player == 2 && color.rgb == vec3(0.0)) {
2 color.a = 0.0;
3}
4
5float emissive = 0.0;
6float damage = 0.25;
7
8for (int i = 0; i < 4; i++) {
9 for (int j = 0; j < 4; j++) {
10 vec4 control = texelFetch(Sampler0, ivec2(36 + i, 16 + j), 0);
11 if (control.rgb == color.rgb) {
12 emissive = 1.0;
13 }
14 }
15}
16
17if (settings2.r > 0.99) {
18 damage = 0.0;
19}
20
21if (overlayColor.a < 0.99) {
22 if (texelFetch(Sampler0, ivec2(2, 16), 0).r > 0.99) {
23 for (int i = 0; i < 4; i++) {
24 for (int j = 0; j < 4; j++) {
25 vec4 control = texelFetch(Sampler0, ivec2(12 + i, 16 + j), 0);
26 if (control.rgb == color.rgb) {
27 damage = 0.25;
28 }
29 }
30 }
31 for (int i = 0; i < 4; i++) {
32 for (int j = 0; j < 4; j++) {
33 vec4 control = texelFetch(Sampler0, ivec2(16 + i, 16 + j), 0);
34 if (control.rgb == color.rgb) {
35 damage = 1.0;
36 }
37 }
38 }
39 }
40 color.rgb = mix(color.rgb, overlayColor.rgb, damage);
41}
42
43color *= ColorModulator;
44
45if (settings.g != 1.0 || emissive != 1.0) {
46 color *= lightMapColor * vertexColor;
47}
48
49fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor);