Skip to content

Commit

Permalink
Added the ability to remove face lighting from any block
Browse files Browse the repository at this point in the history
  • Loading branch information
ShockMicro committed Dec 31, 2021
1 parent f8663fa commit 626198c
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Translucent textures require a bit more work. Check the example for ice to get a

### Functions
`return inputColor;` means you're returning the color of the texture without any lighting applied. This is used for making something fully emissive.
`return apply_partial_emissivity();` means the blocks with that alpha are only partially emissive, tinting it with a specific color of light. You can find a handy link to a table of light colors [here](https://minecraft.fandom.com/wiki/Light?file=1.9_lighting_curves_%2528gamma%253D0%2529.png). Remember, colors in OpenGL are formatted as RGB values from 0 to 1!
`return apply_partial_emissivity();` means the blocks with that alpha are only partially emissive, tinting it with a specific color of light. You can find a handy link to a table of light colors here: https://minecraft.fandom.com/wiki/Light?file=1.9_lighting_curves_%2528gamma%253D0%2529.png. Remember, colors in OpenGL are formatted as RGB values from 0 to 1!
`return inputColor * lightColor;` means you're simply returning the texture with its proper lighting. This is the default case.
You can do `return inputColor * maxLightColor;` if you change the lightmap in any way in order to make emissives emit the max light color instead of just not having lighting.

### NOTICE
This pack probably won't work with Optifine! If it does, good for you! This pack is supposed to be installed in the __resource packs__ folder, using vanilla Minecraft on 1.18.1, because it is a __resource pack__. If there's still a bug after doing everything correctly, report it in the [issues tab](https://github.com/ShockMicro/VanillaDynamicEmissives/issues).
This pack probably won't work with Optifine! If it does, good for you! This pack is supposed to be installed in the RESOURCE PACKS folder, using vanilla Minecraft on 1.18.1, because it is a RESOURCE PACK. If there's still a bug after doing everything correctly, report it in the issues tab at https://github.com/ShockMicro/VanillaDynamicEmissives/issues.
4 changes: 3 additions & 1 deletion assets/minecraft/shaders/core/rendertype_cutout.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ uniform float FogEnd;
uniform vec4 FogColor;

in float vertexDistance;
in float dimension;
in vec4 vertexColor;
in vec4 lightColor;
in vec4 maxLightColor;
in vec2 texCoord0;
in vec3 faceLightingNormal;
in vec4 normal;

out vec4 fragColor;

void main() {
vec4 color = texture(Sampler0, texCoord0) * vertexColor * ColorModulator;
float alpha = textureLod(Sampler0, texCoord0, 0.0).a * 255.0;
color = make_emissive(color, lightColor, maxLightColor, vertexDistance, alpha);
color = make_emissive(color, lightColor, maxLightColor, vertexDistance, alpha) / face_lighting_check(faceLightingNormal, alpha, dimension);
color.a = remap_alpha(alpha) / 255.0;
if (color.a < 0.1) {
discard;
Expand Down
5 changes: 5 additions & 0 deletions assets/minecraft/shaders/core/rendertype_cutout.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#moj_import <light.glsl>
#moj_import <fog.glsl>
#moj_import <emissive_utils.glsl>

in vec3 Position;
in vec4 Color;
Expand All @@ -16,20 +17,24 @@ uniform mat4 ProjMat;
uniform vec3 ChunkOffset;

out float vertexDistance;
out float dimension;
out vec4 vertexColor;
out vec4 lightColor;
out vec4 maxLightColor;
out vec2 texCoord0;
out vec3 faceLightingNormal;
out vec4 normal;

void main() {
vec3 pos = Position + ChunkOffset;
gl_Position = ProjMat * ModelViewMat * vec4(pos, 1.0);

vertexDistance = cylindrical_distance(ModelViewMat, pos);
dimension = get_dimension(minecraft_sample_lightmap(Sampler2, ivec2(0.0, 0.0)));
vertexColor = Color;
lightColor = minecraft_sample_lightmap(Sampler2, UV2);
maxLightColor = minecraft_sample_lightmap(Sampler2, ivec2(240.0, 240.0));
texCoord0 = UV0;
faceLightingNormal = Normal;
normal = ProjMat * ModelViewMat * vec4(Normal, 0.0);
}
4 changes: 3 additions & 1 deletion assets/minecraft/shaders/core/rendertype_cutout_mipped.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ uniform float FogEnd;
uniform vec4 FogColor;

in float vertexDistance;
in float dimension;
in vec4 vertexColor;
in vec4 lightColor;
in vec4 maxLightColor;
in vec2 texCoord0;
in vec3 faceLightingNormal;
in vec4 normal;

out vec4 fragColor;

void main() {
vec4 color = texture(Sampler0, texCoord0) * vertexColor * ColorModulator;
float alpha = textureLod(Sampler0, texCoord0, 0.0).a * 255.0;
color = make_emissive(color, lightColor, maxLightColor, vertexDistance, alpha);
color = make_emissive(color, lightColor, maxLightColor, vertexDistance, alpha) / face_lighting_check(faceLightingNormal, alpha, dimension);
color.a = remap_alpha(alpha) / 255.0;
if (color.a < 0.5) {
discard;
Expand Down
5 changes: 5 additions & 0 deletions assets/minecraft/shaders/core/rendertype_cutout_mipped.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#moj_import <light.glsl>
#moj_import <fog.glsl>
#moj_import <emissive_utils.glsl>

in vec3 Position;
in vec4 Color;
Expand All @@ -16,20 +17,24 @@ uniform mat4 ProjMat;
uniform vec3 ChunkOffset;

out float vertexDistance;
out float dimension;
out vec4 vertexColor;
out vec4 lightColor;
out vec4 maxLightColor;
out vec2 texCoord0;
out vec3 faceLightingNormal;
out vec4 normal;

void main() {
vec3 pos = Position + ChunkOffset;
gl_Position = ProjMat * ModelViewMat * vec4(pos, 1.0);

vertexDistance = cylindrical_distance(ModelViewMat, pos);
dimension = get_dimension(minecraft_sample_lightmap(Sampler2, ivec2(0.0, 0.0)));
vertexColor = Color;
lightColor = minecraft_sample_lightmap(Sampler2, UV2);
maxLightColor = minecraft_sample_lightmap(Sampler2, ivec2(240.0, 240.0));
texCoord0 = UV0;
faceLightingNormal = Normal;
normal = ProjMat * ModelViewMat * vec4(Normal, 0.0);
}
4 changes: 3 additions & 1 deletion assets/minecraft/shaders/core/rendertype_solid.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ uniform float FogEnd;
uniform vec4 FogColor;

in float vertexDistance;
in float dimension;
in vec4 vertexColor;
in vec4 lightColor;
in vec4 maxLightColor;
in vec2 texCoord0;
in vec3 faceLightingNormal;
in vec4 normal;

out vec4 fragColor;

void main() {
vec4 color = texture(Sampler0, texCoord0) * vertexColor * ColorModulator;
float alpha = textureLod(Sampler0, texCoord0, 0.0).a * 255.0;
color = make_emissive(color, lightColor, maxLightColor, vertexDistance, alpha);
color = make_emissive(color, lightColor, maxLightColor, vertexDistance, alpha) / face_lighting_check(faceLightingNormal, alpha, dimension);
color.a = remap_alpha(alpha) / 255.0;
fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor);
}
5 changes: 5 additions & 0 deletions assets/minecraft/shaders/core/rendertype_solid.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#moj_import <light.glsl>
#moj_import <fog.glsl>
#moj_import <emissive_utils.glsl>

in vec3 Position;
in vec4 Color;
Expand All @@ -16,20 +17,24 @@ uniform mat4 ProjMat;
uniform vec3 ChunkOffset;

out float vertexDistance;
out float dimension;
out vec4 vertexColor;
out vec4 lightColor;
out vec4 maxLightColor;
out vec2 texCoord0;
out vec3 faceLightingNormal;
out vec4 normal;

void main() {
vec3 pos = Position + ChunkOffset;
gl_Position = ProjMat * ModelViewMat * vec4(pos, 1.0);

vertexDistance = cylindrical_distance(ModelViewMat, pos);
dimension = get_dimension(minecraft_sample_lightmap(Sampler2, ivec2(0.0, 0.0)));
vertexColor = Color;
lightColor = minecraft_sample_lightmap(Sampler2, UV2);
maxLightColor = minecraft_sample_lightmap(Sampler2, ivec2(240.0, 240.0));
texCoord0 = UV0;
faceLightingNormal = Normal;
normal = ProjMat * ModelViewMat * vec4(Normal, 0.0);
}
4 changes: 3 additions & 1 deletion assets/minecraft/shaders/core/rendertype_translucent.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ uniform float FogEnd;
uniform vec4 FogColor;

in float vertexDistance;
in float dimension;
in vec4 vertexColor;
in vec4 lightColor;
in vec4 maxLightColor;
in vec2 texCoord0;
in vec3 faceLightingNormal;
in vec4 normal;

out vec4 fragColor;

void main() {
vec4 color = texture(Sampler0, texCoord0) * vertexColor * ColorModulator;
float alpha = textureLod(Sampler0, texCoord0, 0.0).a * 255.0;
color = make_emissive(color, lightColor, maxLightColor, vertexDistance, alpha);
color = make_emissive(color, lightColor, maxLightColor, vertexDistance, alpha) / face_lighting_check(faceLightingNormal, alpha, dimension);
color.a = remap_alpha(alpha) / 255.0;
fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor);
}
5 changes: 5 additions & 0 deletions assets/minecraft/shaders/core/rendertype_translucent.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#moj_import <light.glsl>
#moj_import <fog.glsl>
#moj_import <emissive_utils.glsl>

in vec3 Position;
in vec4 Color;
Expand All @@ -16,20 +17,24 @@ uniform mat4 ProjMat;
uniform vec3 ChunkOffset;

out float vertexDistance;
out float dimension;
out vec4 vertexColor;
out vec4 lightColor;
out vec4 maxLightColor;
out vec2 texCoord0;
out vec3 faceLightingNormal;
out vec4 normal;

void main() {
vec3 pos = Position + ChunkOffset;
gl_Position = ProjMat * ModelViewMat * vec4(pos, 1.0);

vertexDistance = cylindrical_distance(ModelViewMat, pos);
dimension = get_dimension(minecraft_sample_lightmap(Sampler2, ivec2(0.0, 0.0)));
vertexColor = Color;
lightColor = minecraft_sample_lightmap(Sampler2, UV2);
maxLightColor = minecraft_sample_lightmap(Sampler2, ivec2(240.0, 240.0));
texCoord0 = UV0;
faceLightingNormal = Normal;
normal = ProjMat * ModelViewMat * vec4(Normal, 0.0);
}
53 changes: 52 additions & 1 deletion assets/minecraft/shaders/include/emissive_utils.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,70 @@ vec4 make_emissive(vec4 inputColor, vec4 lightColor, vec4 maxLightColor, float v
if (vertexDistance > 800) return inputColor; // Vertex Distance > 800 generally means an object is in the UI, which we don't want to affect.

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.
else if (check_alpha(inputAlpha, 251.0)) return apply_partial_emissivity(inputColor, lightColor, vec3(0.411, 0.345, 0.388)); // You can copy & paste this line and change the function to add your own functionality. Used in the example pack for ice.
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.
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.

else return inputColor * lightColor; // If none of the pixels are supposed to be emissive, then it adds the light.

}


// Gets the dimension that an object is in, -1 for The Nether, 0 for The Overworld, 1 for The End.

float get_dimension(vec4 minLightColor) {

if (minLightColor.r == minLightColor.g && minLightColor.g == minLightColor.b) return 0.0; // Shadows are grayscale in The Overworld
else if (minLightColor.r > minLightColor.g) return -1.0; // Shadows are more red in The Nether
else return 1.0; // Shadows are slightly green in The End

}


// Gets the face lighting of a block. Credits to Venaxsys for the original function.

vec4 get_face_lighting(vec3 normal, float dimension) {

vec4 faceLighting = vec4(1.0, 1.0, 1.0, 1.0);
vec3 absNormal = abs(normal);
float top = 229.0 / 255.0;
float bottom = 127.0 / 255.0;
float east = 153.0 / 255.0;
float north = 204.0 / 255.0;

// Top (only required in the Nether)
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

// Bottom
if (normal.y < normal.z && normal.y < normal.x && !check_alpha(dimension, -1.0)) faceLighting = vec4(bottom, bottom, bottom, 1.0);
else if (normal.y < normal.z && normal.y < normal.x && check_alpha(dimension, -1.0)) faceLighting = vec4(top, top, top, 1.0);

// East-West
if (absNormal.x > absNormal.z && absNormal.x > absNormal.y) faceLighting = vec4(east, east, east, 1.0);

// North-South
if (absNormal.z > absNormal.x && absNormal.z > absNormal.y) faceLighting = vec4(north, north, north, 1.0);

return faceLighting;
}


// Checks the alpha and removes face lighting if required.

vec4 face_lighting_check(vec3 normal, float inputAlpha, float dimension) {

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.
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.

}


// Makes sure transparent things don't become solid and vice versa.

float remap_alpha(float inputAlpha) {

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.
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.
else if (check_alpha(inputAlpha, 250.0)) return 255.0; // Used in the example pack for lime concrete.

else return inputAlpha; // If a pixel doesn't need to have its alpha changed then it simply does not change.

Expand Down
Binary file added assets/minecraft/textures/block/lime_concrete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 626198c

Please sign in to comment.