Shader enhancements, disable when Optifine is installed
This commit is contained in:
parent
e5e948ef4f
commit
cdc9d85b53
5 changed files with 103 additions and 74 deletions
|
@ -2,6 +2,7 @@ package ru.bclib.mixin.client;
|
|||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import net.fabricmc.fabric.impl.client.texture.FabricSprite;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -18,17 +19,26 @@ import java.io.IOException;
|
|||
|
||||
@Mixin(TextureAtlas.class)
|
||||
public class TextureAtlasMixin {
|
||||
private static final int EMISSIVE_ALPHA = 253 << 24;
|
||||
private boolean bclib_modifyAtlas;
|
||||
|
||||
@Inject(method = "<init>*", at = @At("TAIL"))
|
||||
private void bclib_onAtlasInit(ResourceLocation resourceLocation, CallbackInfo info) {
|
||||
bclib_modifyAtlas = resourceLocation.toString().equals("minecraft:textures/atlas/blocks.png");
|
||||
boolean hasOptifine = FabricLoader.getInstance().isModLoaded("optifabric");
|
||||
bclib_modifyAtlas = !hasOptifine && resourceLocation.toString().equals("minecraft:textures/atlas/blocks.png");
|
||||
}
|
||||
|
||||
@Inject(method = "load(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite$Info;IIIII)Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;", at = @At("HEAD"), cancellable = true)
|
||||
private void bclib_loadSprite(ResourceManager resourceManager, TextureAtlasSprite.Info spriteInfo, int atlasWidth, int atlasHeight, int maxLevel, int posX, int posY, CallbackInfoReturnable<TextureAtlasSprite> info) {
|
||||
if (!bclib_modifyAtlas) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResourceLocation location = spriteInfo.name();
|
||||
if (bclib_modifyAtlas && location.getPath().startsWith("block")) {
|
||||
if (!location.getPath().startsWith("block")) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResourceLocation emissiveLocation = new ResourceLocation(
|
||||
location.getNamespace(),
|
||||
"textures/" + location.getPath() + "_e.png"
|
||||
|
@ -64,7 +74,7 @@ public class TextureAtlasMixin {
|
|||
int g = (argb >> 8) & 255;
|
||||
int b = argb & 255;
|
||||
if (r > 0 || g > 0 || b > 0) {
|
||||
argb = (argb & 0x00FFFFFF) | (250 << 24);
|
||||
argb = (argb & 0x00FFFFFF) | EMISSIVE_ALPHA;
|
||||
sprite.setPixelRGBA(x, y, argb);
|
||||
}
|
||||
}
|
||||
|
@ -86,4 +96,3 @@ public class TextureAtlasMixin {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,11 @@ vec3 hsvToRGB(vec3 color) {
|
|||
return color.z * mix(k.xxx, clamp(p - k.xxx, 0.0, 1.0), color.y);
|
||||
}
|
||||
|
||||
// Value between 252 and 254
|
||||
bool isEmissive(float alpha) {
|
||||
return 0.9883 < alpha && alpha < 0.9961;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 tex = texture(Sampler0, texCoord0);
|
||||
if (tex.a < 0.1) {
|
||||
|
@ -36,7 +41,7 @@ void main() {
|
|||
}
|
||||
vec4 color = tex * ColorModulator;
|
||||
vec4 vertex = vertexColor;
|
||||
if (tex.a < 0.99) {
|
||||
if (isEmissive(tex.a)) {
|
||||
vec3 hsv = rgbToHSV(vertex.rgb);
|
||||
hsv.z = 1.0;
|
||||
vertex.rgb = hsvToRGB(hsv);
|
||||
|
|
|
@ -31,6 +31,11 @@ vec3 hsvToRGB(vec3 color) {
|
|||
return color.z * mix(k.xxx, clamp(p - k.xxx, 0.0, 1.0), color.y);
|
||||
}
|
||||
|
||||
// Value between 252 and 254
|
||||
bool isEmissive(float alpha) {
|
||||
return 0.9883 < alpha && alpha < 0.9961;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 tex = texture(Sampler0, texCoord0);
|
||||
if (tex.a < 0.1) {
|
||||
|
@ -39,7 +44,7 @@ void main() {
|
|||
vec4 color = tex * ColorModulator;
|
||||
color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a);
|
||||
vec4 vertex = vertexColor * lightMapColor;
|
||||
if (tex.a < 0.99) {
|
||||
if (isEmissive(tex.a)) {
|
||||
vec3 hsv = rgbToHSV(vertex.rgb);
|
||||
hsv.z = 1.0;
|
||||
vertex.rgb = hsvToRGB(hsv);
|
||||
|
|
|
@ -30,6 +30,11 @@ vec3 hsvToRGB(vec3 color) {
|
|||
return color.z * mix(k.xxx, clamp(p - k.xxx, 0.0, 1.0), color.y);
|
||||
}
|
||||
|
||||
// Value between 252 and 254
|
||||
bool isEmissive(float alpha) {
|
||||
return 0.9883 < alpha && alpha < 0.9961;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 tex = texture(Sampler0, texCoord0);
|
||||
if (tex.a < 0.1) {
|
||||
|
@ -38,7 +43,7 @@ void main() {
|
|||
vec4 color = tex * ColorModulator;
|
||||
color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a);
|
||||
vec4 vertex = vertexColor;
|
||||
if (tex.a < 0.99) {
|
||||
if (isEmissive(tex.a)) {
|
||||
vec3 hsv = rgbToHSV(vertex.rgb);
|
||||
hsv.z = 1.0;
|
||||
vertex.rgb = hsvToRGB(hsv);
|
||||
|
|
|
@ -29,11 +29,16 @@ vec3 hsvToRGB(vec3 color) {
|
|||
return color.z * mix(k.xxx, clamp(p - k.xxx, 0.0, 1.0), color.y);
|
||||
}
|
||||
|
||||
// Value between 252 and 254
|
||||
bool isEmissive(float alpha) {
|
||||
return 0.9883 < alpha && alpha < 0.9961;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 tex = texture(Sampler0, texCoord0);
|
||||
vec4 color = tex * ColorModulator;
|
||||
vec4 vertex = vertexColor;
|
||||
if (tex.a < 0.99) {
|
||||
if (isEmissive(tex.a)) {
|
||||
vec3 hsv = rgbToHSV(vertex.rgb);
|
||||
hsv.z = 1.0;
|
||||
vertex.rgb = hsvToRGB(hsv);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue