Skip to content

Commit

Permalink
Many changes (read desc)
Browse files Browse the repository at this point in the history
- Commit changes from v2.1 to Github
- Do a little bit of changing to make things cleaner and (hopefully) more understandable
- Make check_alpha() be a boolean because I was dumb
  • Loading branch information
ShockMicro committed Dec 30, 2021
1 parent a118caf commit f8663fa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
50 changes: 40 additions & 10 deletions assets/minecraft/shaders/include/emissive_utils.glsl
Original file line number Diff line number Diff line change
@@ -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.
}

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.

}

0 comments on commit f8663fa

Please sign in to comment.