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 com.mojang.blaze3d.platform.NativeImage;
|
||||||
import net.fabricmc.fabric.impl.client.texture.FabricSprite;
|
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.TextureAtlas;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
@ -18,71 +19,79 @@ import java.io.IOException;
|
||||||
|
|
||||||
@Mixin(TextureAtlas.class)
|
@Mixin(TextureAtlas.class)
|
||||||
public class TextureAtlasMixin {
|
public class TextureAtlasMixin {
|
||||||
|
private static final int EMISSIVE_ALPHA = 253 << 24;
|
||||||
private boolean bclib_modifyAtlas;
|
private boolean bclib_modifyAtlas;
|
||||||
|
|
||||||
@Inject(method = "<init>*", at = @At("TAIL"))
|
@Inject(method = "<init>*", at = @At("TAIL"))
|
||||||
private void bclib_onAtlasInit(ResourceLocation resourceLocation, CallbackInfo info) {
|
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)
|
@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) {
|
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();
|
ResourceLocation location = spriteInfo.name();
|
||||||
if (bclib_modifyAtlas && location.getPath().startsWith("block")) {
|
if (!location.getPath().startsWith("block")) {
|
||||||
ResourceLocation emissiveLocation = new ResourceLocation(
|
return;
|
||||||
location.getNamespace(),
|
}
|
||||||
"textures/" + location.getPath() + "_e.png"
|
|
||||||
);
|
ResourceLocation emissiveLocation = new ResourceLocation(
|
||||||
if (resourceManager.hasResource(emissiveLocation)) {
|
location.getNamespace(),
|
||||||
NativeImage sprite = null;
|
"textures/" + location.getPath() + "_e.png"
|
||||||
NativeImage emission = null;
|
);
|
||||||
try {
|
if (resourceManager.hasResource(emissiveLocation)) {
|
||||||
ResourceLocation spriteLocation = new ResourceLocation(
|
NativeImage sprite = null;
|
||||||
location.getNamespace(),
|
NativeImage emission = null;
|
||||||
"textures/" + location.getPath() + ".png"
|
try {
|
||||||
);
|
ResourceLocation spriteLocation = new ResourceLocation(
|
||||||
Resource resource = resourceManager.getResource(spriteLocation);
|
location.getNamespace(),
|
||||||
sprite = NativeImage.read(resource.getInputStream());
|
"textures/" + location.getPath() + ".png"
|
||||||
resource.close();
|
);
|
||||||
|
Resource resource = resourceManager.getResource(spriteLocation);
|
||||||
resource = resourceManager.getResource(emissiveLocation);
|
sprite = NativeImage.read(resource.getInputStream());
|
||||||
emission = NativeImage.read(resource.getInputStream());
|
resource.close();
|
||||||
resource.close();
|
|
||||||
}
|
resource = resourceManager.getResource(emissiveLocation);
|
||||||
catch (IOException e) {
|
emission = NativeImage.read(resource.getInputStream());
|
||||||
BCLib.LOGGER.warning(e.getMessage());
|
resource.close();
|
||||||
}
|
}
|
||||||
if (sprite != null && emission != null) {
|
catch (IOException e) {
|
||||||
int width = Math.min(sprite.getWidth(), emission.getWidth());
|
BCLib.LOGGER.warning(e.getMessage());
|
||||||
int height = Math.min(sprite.getHeight(), emission.getHeight());
|
}
|
||||||
for (int x = 0; x < width; x++) {
|
if (sprite != null && emission != null) {
|
||||||
for (int y = 0; y < height; y++) {
|
int width = Math.min(sprite.getWidth(), emission.getWidth());
|
||||||
int argb = emission.getPixelRGBA(x, y);
|
int height = Math.min(sprite.getHeight(), emission.getHeight());
|
||||||
int alpha = (argb >> 24) & 255;
|
for (int x = 0; x < width; x++) {
|
||||||
if (alpha > 127) {
|
for (int y = 0; y < height; y++) {
|
||||||
int r = (argb >> 16) & 255;
|
int argb = emission.getPixelRGBA(x, y);
|
||||||
int g = (argb >> 8) & 255;
|
int alpha = (argb >> 24) & 255;
|
||||||
int b = argb & 255;
|
if (alpha > 127) {
|
||||||
if (r > 0 || g > 0 || b > 0) {
|
int r = (argb >> 16) & 255;
|
||||||
argb = (argb & 0x00FFFFFF) | (250 << 24);
|
int g = (argb >> 8) & 255;
|
||||||
sprite.setPixelRGBA(x, y, argb);
|
int b = argb & 255;
|
||||||
}
|
if (r > 0 || g > 0 || b > 0) {
|
||||||
|
argb = (argb & 0x00FFFFFF) | EMISSIVE_ALPHA;
|
||||||
|
sprite.setPixelRGBA(x, y, argb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TextureAtlas self = (TextureAtlas) (Object) this;
|
|
||||||
FabricSprite result = new FabricSprite(
|
|
||||||
self,
|
|
||||||
spriteInfo,
|
|
||||||
maxLevel,
|
|
||||||
atlasWidth,
|
|
||||||
atlasHeight,
|
|
||||||
posX,
|
|
||||||
posY,
|
|
||||||
sprite
|
|
||||||
);
|
|
||||||
info.setReturnValue(result);
|
|
||||||
}
|
}
|
||||||
|
TextureAtlas self = (TextureAtlas) (Object) this;
|
||||||
|
FabricSprite result = new FabricSprite(
|
||||||
|
self,
|
||||||
|
spriteInfo,
|
||||||
|
maxLevel,
|
||||||
|
atlasWidth,
|
||||||
|
atlasHeight,
|
||||||
|
posX,
|
||||||
|
posY,
|
||||||
|
sprite
|
||||||
|
);
|
||||||
|
info.setReturnValue(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,19 +24,24 @@ vec3 rgbToHSV(vec3 color) {
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 hsvToRGB(vec3 color) {
|
vec3 hsvToRGB(vec3 color) {
|
||||||
vec4 k = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
vec4 k = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||||
vec3 p = abs(fract(color.xxx + k.xyz) * 6.0 - k.www);
|
vec3 p = abs(fract(color.xxx + k.xyz) * 6.0 - k.www);
|
||||||
return color.z * mix(k.xxx, clamp(p - k.xxx, 0.0, 1.0), color.y);
|
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() {
|
void main() {
|
||||||
vec4 tex = texture(Sampler0, texCoord0);
|
vec4 tex = texture(Sampler0, texCoord0);
|
||||||
if (tex.a < 0.1) {
|
if (tex.a < 0.1) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
vec4 color = tex * ColorModulator;
|
vec4 color = tex * ColorModulator;
|
||||||
vec4 vertex = vertexColor;
|
vec4 vertex = vertexColor;
|
||||||
if (tex.a < 0.99) {
|
if (isEmissive(tex.a)) {
|
||||||
vec3 hsv = rgbToHSV(vertex.rgb);
|
vec3 hsv = rgbToHSV(vertex.rgb);
|
||||||
hsv.z = 1.0;
|
hsv.z = 1.0;
|
||||||
vertex.rgb = hsvToRGB(hsv);
|
vertex.rgb = hsvToRGB(hsv);
|
||||||
|
|
|
@ -26,20 +26,25 @@ vec3 rgbToHSV(vec3 color) {
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 hsvToRGB(vec3 color) {
|
vec3 hsvToRGB(vec3 color) {
|
||||||
vec4 k = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
vec4 k = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||||
vec3 p = abs(fract(color.xxx + k.xyz) * 6.0 - k.www);
|
vec3 p = abs(fract(color.xxx + k.xyz) * 6.0 - k.www);
|
||||||
return color.z * mix(k.xxx, clamp(p - k.xxx, 0.0, 1.0), color.y);
|
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() {
|
void main() {
|
||||||
vec4 tex = texture(Sampler0, texCoord0);
|
vec4 tex = texture(Sampler0, texCoord0);
|
||||||
if (tex.a < 0.1) {
|
if (tex.a < 0.1) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
vec4 color = tex * ColorModulator;
|
vec4 color = tex * ColorModulator;
|
||||||
color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a);
|
color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a);
|
||||||
vec4 vertex = vertexColor * lightMapColor;
|
vec4 vertex = vertexColor * lightMapColor;
|
||||||
if (tex.a < 0.99) {
|
if (isEmissive(tex.a)) {
|
||||||
vec3 hsv = rgbToHSV(vertex.rgb);
|
vec3 hsv = rgbToHSV(vertex.rgb);
|
||||||
hsv.z = 1.0;
|
hsv.z = 1.0;
|
||||||
vertex.rgb = hsvToRGB(hsv);
|
vertex.rgb = hsvToRGB(hsv);
|
||||||
|
|
|
@ -25,20 +25,25 @@ vec3 rgbToHSV(vec3 color) {
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 hsvToRGB(vec3 color) {
|
vec3 hsvToRGB(vec3 color) {
|
||||||
vec4 k = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
vec4 k = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||||
vec3 p = abs(fract(color.xxx + k.xyz) * 6.0 - k.www);
|
vec3 p = abs(fract(color.xxx + k.xyz) * 6.0 - k.www);
|
||||||
return color.z * mix(k.xxx, clamp(p - k.xxx, 0.0, 1.0), color.y);
|
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() {
|
void main() {
|
||||||
vec4 tex = texture(Sampler0, texCoord0);
|
vec4 tex = texture(Sampler0, texCoord0);
|
||||||
if (tex.a < 0.1) {
|
if (tex.a < 0.1) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
vec4 color = tex * ColorModulator;
|
vec4 color = tex * ColorModulator;
|
||||||
color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a);
|
color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a);
|
||||||
vec4 vertex = vertexColor;
|
vec4 vertex = vertexColor;
|
||||||
if (tex.a < 0.99) {
|
if (isEmissive(tex.a)) {
|
||||||
vec3 hsv = rgbToHSV(vertex.rgb);
|
vec3 hsv = rgbToHSV(vertex.rgb);
|
||||||
hsv.z = 1.0;
|
hsv.z = 1.0;
|
||||||
vertex.rgb = hsvToRGB(hsv);
|
vertex.rgb = hsvToRGB(hsv);
|
||||||
|
|
|
@ -24,16 +24,21 @@ vec3 rgbToHSV(vec3 color) {
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 hsvToRGB(vec3 color) {
|
vec3 hsvToRGB(vec3 color) {
|
||||||
vec4 k = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
vec4 k = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||||
vec3 p = abs(fract(color.xxx + k.xyz) * 6.0 - k.www);
|
vec3 p = abs(fract(color.xxx + k.xyz) * 6.0 - k.www);
|
||||||
return color.z * mix(k.xxx, clamp(p - k.xxx, 0.0, 1.0), color.y);
|
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() {
|
void main() {
|
||||||
vec4 tex = texture(Sampler0, texCoord0);
|
vec4 tex = texture(Sampler0, texCoord0);
|
||||||
vec4 color = tex * ColorModulator;
|
vec4 color = tex * ColorModulator;
|
||||||
vec4 vertex = vertexColor;
|
vec4 vertex = vertexColor;
|
||||||
if (tex.a < 0.99) {
|
if (isEmissive(tex.a)) {
|
||||||
vec3 hsv = rgbToHSV(vertex.rgb);
|
vec3 hsv = rgbToHSV(vertex.rgb);
|
||||||
hsv.z = 1.0;
|
hsv.z = 1.0;
|
||||||
vertex.rgb = hsvToRGB(hsv);
|
vertex.rgb = hsvToRGB(hsv);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue