diff --git a/README.md b/README.md index be26e2e..ee7cf3b 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,14 @@ Allows for dynamic emissive textures in vanilla Minecraft. ### How to Use -If you want to make a solid texture emissive, just set the alpha value to 252 in your favorite image editor. You can see an example of this in the redstone ore texture. +If you want to make a solid texture emissive, just set the alpha value to 252 in your favorite image editor. You can see an example of this with redstone ore. +Translucent textures require a bit more work. Check the example for ice to get a general idea of how this works. -Translucent textures are a bit more tricky, but it's still fairly simple. Go to the `light.glsl` file and open it up. There are two functions you want -to look at there, the ones that tell you to copy/paste. If it's inside a `check_alpha()` function, that's the alpha value you're checking for. If it's right -after `return`, that's the one that it will actually be ingame. See the ice, it checks for 251 and makes it look like 190. +### 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 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, 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](https://github.com/ShockMicro/VanillaDynamicEmissives/issues). \ No newline at end of file diff --git a/assets/minecraft/shaders/include/emissive_utils.glsl b/assets/minecraft/shaders/include/emissive_utils.glsl index 5a37c76..2db5953 100644 --- a/assets/minecraft/shaders/include/emissive_utils.glsl +++ b/assets/minecraft/shaders/include/emissive_utils.glsl @@ -1,21 +1,51 @@ #version 150 -float check_alpha(float textureAlpha, float targetAlpha) { +// Checking for the exact alpha value breaks things, so I use this function to cut down on space while also making it work better. + +bool check_alpha(float textureAlpha, float targetAlpha) { + float targetLess = targetAlpha - 0.01; float targetMore = targetAlpha + 0.01; - if (textureAlpha > targetLess && textureAlpha < targetMore) return 1.0; - else return 0.0; + return (textureAlpha > targetLess && textureAlpha < targetMore); + +} + + +// For cases in which you want something to have a lower light level, but still be bright when in light. + +vec4 apply_partial_emissivity(vec4 inputColor, vec4 originalLightColor, vec3 minimumLightColor) { + + vec4 newLightColor = originalLightColor; + newLightColor.r = max(originalLightColor.r, minimumLightColor.r); + newLightColor.g = max(originalLightColor.g, minimumLightColor.g); + newLightColor.b = max(originalLightColor.b, minimumLightColor.b); + return inputColor * newLightColor; + } + +// The meat and bones of the pack, does all the work for making things emissive. + vec4 make_emissive(vec4 inputColor, vec4 lightColor, vec4 maxLightColor, float vertexDistance, float inputAlpha) { - if (vertexDistance > 800) return inputColor; - if (check_alpha(inputAlpha, 252.0) == 1.0) return inputColor; // Default case, checks for alpha 252 and just returns the input color if it is. - else if (check_alpha(inputAlpha, 251.0) == 1.0) return inputColor; // Copypaste this and change the number to add a custom alpha value. + + 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 return inputColor * lightColor; // If none of the pixels are supposed to be emissive, then it adds the light. + } + +// Makes sure transparent things don't become solid and vice versa. + float remap_alpha(float inputAlpha) { - if (check_alpha(inputAlpha, 252.0) == 1.0) return 255.0; // Default case, checks for alpha 252 and converts all pixels of that to alpha 255. - else if (check_alpha(inputAlpha, 251.0) == 1.0) return 190.0; // Copypaste this and change the numbers to add a custom alpha value. - else return inputAlpha; // If none of the pixels are meant to be mapped then it just doesn't map. -} \ No newline at end of file + + 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 return inputAlpha; // If a pixel doesn't need to have its alpha changed then it simply does not change. + +} +