diff --git a/src/main/java/ru/paulevs/bismuthlib/BismuthLibClient.java b/src/main/java/ru/paulevs/bismuthlib/BismuthLibClient.java index d90f2ed..d15c581 100644 --- a/src/main/java/ru/paulevs/bismuthlib/BismuthLibClient.java +++ b/src/main/java/ru/paulevs/bismuthlib/BismuthLibClient.java @@ -48,6 +48,7 @@ import ru.paulevs.bismuthlib.gui.CFOptions; import ru.paulevs.bismuthlib.mixin.TextureAtlasSpriteAccessor; +import java.awt.Color; import java.io.BufferedReader; import java.io.IOException; import java.util.Arrays; @@ -66,8 +67,11 @@ public class BismuthLibClient implements ClientModInitializer { private static final ResourceLocation LIGHTMAP_ID = new ResourceLocation(MOD_ID, "colored_light"); private static LevelShaderData data; + private static final Gson GSON = new GsonBuilder().create(); + private static ResourceManager managerCache; private static boolean fastLight = false; private static boolean modifyLight = false; + private static boolean brightSources = false; @Override public void onInitializeClient() { @@ -98,7 +102,6 @@ public void onInitializeClient() { PrintCommand.register(dispatcher); }); - final Gson gson = new GsonBuilder().create(); final ResourceLocation location = new ResourceLocation(MOD_ID, "resource_reloader"); ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() { @Override @@ -108,190 +111,192 @@ public ResourceLocation getFabricId() { @Override public void onResourceManagerReload(ResourceManager resourceManager) { - /*LightInfo[] white = new LightInfo[15]; - for (byte i = 0; i < 15; i++) { - int c = (i + 1) << 4; - white[i] = new LightInfo(c << 16 | c << 8 | c, i + 1); - } - - Registry.BLOCK.forEach(block -> { - block.getStateDefinition().getPossibleStates().stream().filter(state -> state.getLightEmission() > 0).forEach(state -> { - BlockLights.addLight(state, white[state.getLightEmission() - 1]); - }); - });*/ - - Set exclude = new HashSet<>(); - - Map list = resourceManager.listResources("lights", resourceLocation -> - resourceLocation.getPath().endsWith(".json") && resourceLocation.getNamespace().equals(MOD_ID) - ); - - BlockLights.clear(); - Map colorMap = new HashMap<>(); - Map radiusMap = new HashMap<>(); - list.forEach((id, resource) -> { - JsonObject obj = new JsonObject(); + managerCache = resourceManager; + loadBlocks(resourceManager); + } + }); + } + + private static void loadBlocks(ResourceManager resourceManager) { + Set exclude = new HashSet<>(); + + Map list = resourceManager.listResources("lights", resourceLocation -> + resourceLocation.getPath().endsWith(".json") && resourceLocation.getNamespace().equals(MOD_ID) + ); + + BlockLights.clear(); + Map colorMap = new HashMap<>(); + Map radiusMap = new HashMap<>(); + list.forEach((id, resource) -> { + JsonObject obj = new JsonObject(); + + try { + BufferedReader reader = resource.openAsReader(); + obj = GSON.fromJson(reader, JsonObject.class); + reader.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + + final JsonObject storage = obj; + storage.keySet().forEach(key -> { + ResourceLocation blockID = new ResourceLocation(key); + Optional optional = Registry.BLOCK.getOptional(blockID); + if (optional.isPresent()) { + Block block = optional.get(); + ImmutableList blockStates = block.getStateDefinition().getPossibleStates(); + exclude.add(block); - try { - BufferedReader reader = resource.openAsReader(); - obj = gson.fromJson(reader, JsonObject.class); - reader.close(); + JsonObject data = storage.getAsJsonObject(key); + if (data.keySet().isEmpty()) { + BlockLights.addLight(block, null); } - catch (IOException e) { - e.printStackTrace(); - } - - final JsonObject storage = obj; - storage.keySet().forEach(key -> { - ResourceLocation blockID = new ResourceLocation(key); - Optional optional = Registry.BLOCK.getOptional(blockID); - if (optional.isPresent()) { - Block block = optional.get(); - ImmutableList blockStates = block.getStateDefinition().getPossibleStates(); - exclude.add(block); - - JsonObject data = storage.getAsJsonObject(key); - if (data.keySet().isEmpty()) { - BlockLights.addLight(block, null); + else { + radiusMap.clear(); + colorMap.clear(); + BlockColor provider = null; + int providerIndex = 0; + + JsonElement element = data.get("color"); + if (element == null) throw new RuntimeException("Block " + blockID + " in " + id + " missing color element!"); + if (element.isJsonPrimitive()) { + String preValue = element.getAsString(); + if (preValue.startsWith("provider")) { + provider = ColorProviderRegistry.BLOCK.get(block); + providerIndex = Integer.parseInt(preValue.substring(preValue.indexOf('=') + 1)); } else { - radiusMap.clear(); - colorMap.clear(); - BlockColor provider = null; - int providerIndex = 0; - - JsonElement element = data.get("color"); - if (element == null) throw new RuntimeException("Block " + blockID + " in " + id + " missing color element!"); - if (element.isJsonPrimitive()) { - String preValue = element.getAsString(); - if (preValue.startsWith("provider")) { - provider = ColorProviderRegistry.BLOCK.get(block); - providerIndex = Integer.parseInt(preValue.substring(preValue.indexOf('=') + 1)); - } - else { - int value = Integer.parseInt(preValue, 16); - blockStates.forEach(state -> colorMap.put(state, value)); - } - } - else { - getValues(block, element.getAsJsonObject()).forEach((state, primitive) -> { - int value = Integer.parseInt(primitive.getAsString(), 16); - colorMap.put(state, value); - }); - } - - element = data.get("radius"); - if (element == null) throw new RuntimeException("Block " + blockID + " in " + id + " missing radius element!"); - if (element.isJsonPrimitive()) { - int value = element.getAsInt(); - blockStates.forEach(state -> radiusMap.put(state, value)); + int value = Integer.parseInt(preValue, 16); + blockStates.forEach(state -> colorMap.put(state, value)); + } + } + else { + getValues(block, element.getAsJsonObject()).forEach((state, primitive) -> { + int value = Integer.parseInt(primitive.getAsString(), 16); + colorMap.put(state, value); + }); + } + + element = data.get("radius"); + if (element == null) throw new RuntimeException("Block " + blockID + " in " + id + " missing radius element!"); + if (element.isJsonPrimitive()) { + int value = element.getAsInt(); + blockStates.forEach(state -> radiusMap.put(state, value)); + } + else { + Map values = getValues(block, element.getAsJsonObject()); + values.forEach((state, primitive) -> radiusMap.put(state, primitive.getAsInt())); + } + + final int indexCopy = providerIndex; + final BlockColor colorCopy = provider; + blockStates.forEach(state -> { + if (radiusMap.containsKey(state)) { + int radius = radiusMap.get(state); + if (colorCopy != null) { + BlockLights.addLight(state, new ProviderLight(state, colorCopy, indexCopy, radius)); } - else { - Map values = getValues(block, element.getAsJsonObject()); - values.forEach((state, primitive) -> radiusMap.put(state, primitive.getAsInt())); + else if (colorMap.containsKey(state)) { + int color = colorMap.get(state); + BlockLights.addLight(state, new SimpleLight(color, radius)); } - - final int indexCopy = providerIndex; - final BlockColor colorCopy = provider; - blockStates.forEach(state -> { - if (radiusMap.containsKey(state)) { - int radius = radiusMap.get(state); - if (colorCopy != null) { - BlockLights.addLight(state, new ProviderLight(state, colorCopy, indexCopy, radius)); - } - else if (colorMap.containsKey(state)) { - int color = colorMap.get(state); - BlockLights.addLight(state, new SimpleLight(color, radius)); - } - } - }); } - } - }); - }); - - Registry.BLOCK.stream().filter(block -> !exclude.contains(block)).forEach(block -> { - block.getStateDefinition().getPossibleStates().stream().filter(state -> state.getLightEmission() > 0).forEach(state -> { - int color = getBlockColor(state); - int radius = state.getLightEmission(); - BlockLights.addLight(state, new SimpleLight(color, radius)); - }); - }); - - list = resourceManager.listResources("transformers", resourceLocation -> - resourceLocation.getPath().endsWith(".json") && resourceLocation.getNamespace().equals(MOD_ID) - ); - - list.forEach((id, resource) -> { - JsonObject obj = new JsonObject(); - - try { - BufferedReader reader = resource.openAsReader(); - obj = gson.fromJson(reader, JsonObject.class); - reader.close(); - } - catch (IOException e) { - e.printStackTrace(); + }); } + } + }); + }); + + Registry.BLOCK.stream().filter(block -> !exclude.contains(block)).forEach(block -> { + block.getStateDefinition().getPossibleStates().stream().filter(state -> state.getLightEmission() > 0).forEach(state -> { + int color = getBlockColor(state); + int radius = state.getLightEmission(); + BlockLights.addLight(state, new SimpleLight(color, radius)); + }); + }); + + list = resourceManager.listResources("transformers", resourceLocation -> + resourceLocation.getPath().endsWith(".json") && resourceLocation.getNamespace().equals(MOD_ID) + ); + + float[] hsv = new float[3]; + list.forEach((id, resource) -> { + JsonObject obj = new JsonObject(); + + try { + BufferedReader reader = resource.openAsReader(); + obj = GSON.fromJson(reader, JsonObject.class); + reader.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + + final JsonObject storage = obj; + storage.keySet().forEach(key -> { + ResourceLocation blockID = new ResourceLocation(key); + Optional optional = Registry.BLOCK.getOptional(blockID); + if (optional.isPresent()) { + Block block = optional.get(); + ImmutableList blockStates = block.getStateDefinition().getPossibleStates(); + exclude.add(block); - final JsonObject storage = obj; - storage.keySet().forEach(key -> { - ResourceLocation blockID = new ResourceLocation(key); - Optional optional = Registry.BLOCK.getOptional(blockID); - if (optional.isPresent()) { - Block block = optional.get(); - ImmutableList blockStates = block.getStateDefinition().getPossibleStates(); - exclude.add(block); - - JsonObject data = storage.getAsJsonObject(key); - if (data.keySet().isEmpty()) { - BlockLights.addLight(block, null); + JsonObject data = storage.getAsJsonObject(key); + if (data.keySet().isEmpty()) { + BlockLights.addLight(block, null); + } + else { + colorMap.clear(); + BlockColor provider = null; + int providerIndex = 0; + + JsonElement element = data.get("color"); + if (element == null) throw new RuntimeException("Block " + blockID + " in " + id + " missing color element!"); + if (element.isJsonPrimitive()) { + String preValue = element.getAsString(); + if (preValue.startsWith("provider")) { + provider = ColorProviderRegistry.BLOCK.get(block); + providerIndex = Integer.parseInt(preValue.substring(preValue.indexOf('=') + 1)); } else { - colorMap.clear(); - BlockColor provider = null; - int providerIndex = 0; - - JsonElement element = data.get("color"); - if (element == null) throw new RuntimeException("Block " + blockID + " in " + id + " missing color element!"); - if (element.isJsonPrimitive()) { - String preValue = element.getAsString(); - if (preValue.startsWith("provider")) { - provider = ColorProviderRegistry.BLOCK.get(block); - providerIndex = Integer.parseInt(preValue.substring(preValue.indexOf('=') + 1)); - } - else { - int value = Integer.parseInt(preValue, 16); - blockStates.forEach(state -> colorMap.put(state, value)); - } + int value = Integer.parseInt(preValue, 16); + if (CFOptions.isBrightSources()) { + int r = (value >> 16) & 255; + int g = (value >> 8) & 255; + int b = value & 255; + Color.RGBtoHSB(r, g, b, hsv); + hsv[2] = 1.0F; + value = Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]); } - else { - getValues(block, element.getAsJsonObject()).forEach((state, primitive) -> { - int value = Integer.parseInt(primitive.getAsString(), 16); - colorMap.put(state, value); - }); - } - - final int indexCopy = providerIndex; - final BlockColor colorCopy = provider; - blockStates.forEach(state -> { - if (colorCopy != null) { - BlockLights.addTransformer(state, new ProviderLightTransformer(state, colorCopy, indexCopy)); - } - else if (colorMap.containsKey(state)) { - BlockLights.addTransformer(state, new SimpleLightTransformer(colorMap.get(state))); - } - }); + final int valueCopy = value; + blockStates.forEach(state -> colorMap.put(state, valueCopy)); } } - }); - }); - - } + else { + getValues(block, element.getAsJsonObject()).forEach((state, primitive) -> { + int value = Integer.parseInt(primitive.getAsString(), 16); + colorMap.put(state, value); + }); + } + + final int indexCopy = providerIndex; + final BlockColor colorCopy = provider; + blockStates.forEach(state -> { + if (colorCopy != null) { + BlockLights.addTransformer(state, new ProviderLightTransformer(state, colorCopy, indexCopy)); + } + else if (colorMap.containsKey(state)) { + BlockLights.addTransformer(state, new SimpleLightTransformer(colorMap.get(state))); + } + }); + } + } + }); }); } - private Map getValues(Block block, final JsonObject values) { + private static Map getValues(Block block, final JsonObject values) { ImmutableList states = block.getStateDefinition().getPossibleStates(); Map result = new HashMap<>(); values.keySet().forEach(stateString -> { @@ -316,7 +321,7 @@ private Map getValues(Block block, final JsonObject v return result; } - private boolean hasPropertyWithValue(BlockState state, String propertyName, String propertyValue) { + private static boolean hasPropertyWithValue(BlockState state, String propertyName, String propertyValue) { Collection> properties = state.getProperties(); Iterator> iterator = properties.iterator(); boolean result = false; @@ -347,7 +352,11 @@ else if (data.getDataWidth() != w || data.getDataHeight() != h || count != data. boolean fast = CFOptions.isFastLight(); boolean modify = CFOptions.modifyColor(); - if (fast != fastLight || modify != modifyLight) { + boolean bright = CFOptions.isBrightSources(); + if (fast != fastLight || modify != modifyLight || bright != brightSources) { + if (managerCache != null && bright != brightSources) { + loadBlocks(managerCache); + } fastLight = fast; modifyLight = modify; data.resetAll(); @@ -394,6 +403,11 @@ public static void bindWithUniforms() { uniform.set(level.getTimeOfDay(0)); } } + + uniform = shader.getUniform("lightsBrightness"); + if (uniform != null) { + uniform.set(CFOptions.getBrightness()); + } } private static int getBlockColor(BlockState state) { diff --git a/src/main/java/ru/paulevs/bismuthlib/LightPropagator.java b/src/main/java/ru/paulevs/bismuthlib/LightPropagator.java index a64fcab..63df659 100644 --- a/src/main/java/ru/paulevs/bismuthlib/LightPropagator.java +++ b/src/main/java/ru/paulevs/bismuthlib/LightPropagator.java @@ -188,6 +188,7 @@ private void fillLight(Level level, int[] data, BlockPos pos, LightInfo info, Bl int maskIndex = getMaskIndex(maskX, maskY, maskZ); if (mask[maskIndex]) continue; + mask[maskIndex] = true; BlockPos p = positions[maskIndex].set(start).move(offset); BlockState state = storage.getBlockState(p); @@ -196,18 +197,15 @@ private void fillLight(Level level, int[] data, BlockPos pos, LightInfo info, Bl if (modify && transformer != null) { int mixedColor = ColorMath.mulBlend(color, transformer.getColor(level, p)); transformers.add(new TransformerInfo(new SimpleLight(mixedColor, radius - i, false), p.immutable())); - mask[maskIndex] = true; continue; } else if (BlockLights.getLight(state) != null) { - mask[maskIndex] = true; continue; } else if (blockFace(state, storage, p, offset) && blockLight(state, storage, p)) { continue; } - mask[maskIndex] = true; setLight(data, p, color, secMin, secMax, true); ends.add(p); } diff --git a/src/main/java/ru/paulevs/bismuthlib/data/AdvancedBlockStorage.java b/src/main/java/ru/paulevs/bismuthlib/data/AdvancedBlockStorage.java new file mode 100644 index 0000000..560ce2e --- /dev/null +++ b/src/main/java/ru/paulevs/bismuthlib/data/AdvancedBlockStorage.java @@ -0,0 +1,78 @@ +package ru.paulevs.bismuthlib.data; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.BlockPos.MutableBlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import ru.paulevs.bismuthlib.data.info.LightInfo; +import ru.paulevs.bismuthlib.data.transformer.LightTransformer; +import ru.paulevs.bismuthlib.gui.CFOptions; + +import java.util.HashMap; +import java.util.Map; + +public class AdvancedBlockStorage { + private static final Direction[] DIRECTIONS = new Direction[] { Direction.UP, Direction.NORTH, Direction.EAST }; + private static final byte[] FLAGS = new byte[] { 0b001, 0b010, 0b100 }; + private static final byte[] FLAGS_INV = new byte[] { 0b110, 0b101, 0b011 }; + private static final byte MAX = 0b111; + + private Map transformers = new HashMap<>(); + private Map lights = new HashMap<>(); + private MutableBlockPos pos = new MutableBlockPos(); + private byte[] storage = new byte[110592]; + private int storedIndex; + + public void fill(Level level, int x1, int y1, int z1) { + storedIndex = 0; + for (byte dx = 0; dx < 48; dx++) { + pos.setX(x1 + dx); + for (byte dy = 0; dy < 48; dy++) { + pos.setY(y1 + dy); + for (byte dz = 0; dz < 48; dz++) { + pos.setZ(z1 + dz); + storage[storedIndex] = MAX; + BlockState state = level.getBlockState(pos); + + LightInfo light = BlockLights.getLight(state); + if (light != null) { + lights.put(pos.immutable(), light); + storage[storedIndex++] = 0; + continue; + } + + if (CFOptions.modifyColor()) { + LightTransformer transformer = BlockLights.getTransformer(state); + if (transformer != null) { + transformers.put(pos.immutable(), transformer); + storage[storedIndex++] = 0; + continue; + } + } + + if (blockLight(state, level, pos)) { + storage[storedIndex] = 0; + } + else { + for (Direction dir: DIRECTIONS) { + if (blockFace(state, level, pos, dir)) { + storage[storedIndex] &= FLAGS_INV[dir.getAxis().ordinal()]; + } + } + } + storedIndex++; + } + } + } + pos.set(x1, y1, z1); + } + + private boolean blockFace(BlockState state, Level level, BlockPos pos, Direction dir) { + return state.isFaceSturdy(level, pos, dir) || state.isFaceSturdy(level, pos, dir.getOpposite()); + } + + private boolean blockLight(BlockState state, Level level, BlockPos pos) { + return state.getMaterial().isSolidBlocking() || !state.propagatesSkylightDown(level, pos); + } +} diff --git a/src/main/java/ru/paulevs/bismuthlib/data/LevelShaderData.java b/src/main/java/ru/paulevs/bismuthlib/data/LevelShaderData.java index 8401f71..f452eeb 100644 --- a/src/main/java/ru/paulevs/bismuthlib/data/LevelShaderData.java +++ b/src/main/java/ru/paulevs/bismuthlib/data/LevelShaderData.java @@ -190,6 +190,13 @@ public void update(Level level, int cx, int cy, int cz) { } if (updateTicks++ > 16) { + if (upload) { + synchronized (texture) { + upload = false; + texture.upload(); + } + } + updateTicks = 0; updateSections.forEach(pos -> { int index = getMultiIndex(pos); @@ -204,17 +211,6 @@ public void update(Level level, int cx, int cy, int cz) { updateSections.addAll(delayedSections); delayedSections.clear(); } - - if (mapUpdate++ > 4) { - mapUpdate = 0; - if (upload) { - synchronized (texture) { - upload = false; - texture.upload(); - } - } - ; - } } private int getMultiIndex(BlockPos pos) { diff --git a/src/main/java/ru/paulevs/bismuthlib/gui/CFOptions.java b/src/main/java/ru/paulevs/bismuthlib/gui/CFOptions.java index 247e2e9..ceff745 100644 --- a/src/main/java/ru/paulevs/bismuthlib/gui/CFOptions.java +++ b/src/main/java/ru/paulevs/bismuthlib/gui/CFOptions.java @@ -13,6 +13,7 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.util.Locale; public class CFOptions { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); @@ -41,6 +42,9 @@ public class CFOptions { private static boolean fastLight = getBool("fastLight", false); private static int threads = getInt("threads", 4); private static boolean modifyColor = getBool("modifyColor", false); + private static int brightness = getInt("brightness", 64); + private static float floatBrightness = brightness / 64F; + private static boolean brightSources = getBool("brightSources", false); public static final OptionInstance MAP_RADIUS_XZ = new OptionInstance<>( "bismuthlib.options.mapRadiusXZ", @@ -70,6 +74,19 @@ public class CFOptions { mapRadiusY = val; } ); + public static final OptionInstance BRIGHTNESS = new OptionInstance<>( + "bismuthlib.options.brightness", + OptionInstance.noTooltip(), + (component, i) -> Options.genericValueLabel(component, Component.translatable(String.format(Locale.ROOT, "%.2f", i / 64F))), //Options.genericValueLabel(component, i), + new OptionInstance.IntRange(0, 128), + brightness, + val -> { + setInt("brightness", val); + brightness = val; + floatBrightness = val / 64F; + } + ); + private static final OptionInstance FAST_LIGHT = new OptionInstance<>( "bismuthlib.options.lightType", OptionInstance.noTooltip(), @@ -103,9 +120,20 @@ public class CFOptions { modifyColor = val; } ); + private static final OptionInstance BRIGHT_SOURCES = new OptionInstance<>( + "bismuthlib.options.brightSources", + OptionInstance.noTooltip(), + (component, bool) -> Component.translatable("bismuthlib.options.brightSources." + bool), + OptionInstance.BOOLEAN_VALUES, + brightSources, + val -> { + setBool("brightSources", val); + brightSources = val; + } + ); public static final OptionInstance[] OPTIONS = new OptionInstance[] { - FAST_LIGHT, THREADS, MODIFY_COLOR + FAST_LIGHT, THREADS, MODIFY_COLOR, BRIGHT_SOURCES }; public static int getMapRadiusXZ() { @@ -128,6 +156,14 @@ public static boolean modifyColor() { return modifyColor; } + public static float getBrightness() { + return floatBrightness; + } + + public static boolean isBrightSources() { + return brightSources; + } + private static int getInt(String name, int def) { return config.has(name) ? config.get(name).getAsInt() : def; } diff --git a/src/main/java/ru/paulevs/bismuthlib/gui/CFSettingsScreen.java b/src/main/java/ru/paulevs/bismuthlib/gui/CFSettingsScreen.java index 478a023..73ddcbc 100644 --- a/src/main/java/ru/paulevs/bismuthlib/gui/CFSettingsScreen.java +++ b/src/main/java/ru/paulevs/bismuthlib/gui/CFSettingsScreen.java @@ -25,6 +25,7 @@ protected void init() { this.list = new OptionsList(this.minecraft, this.width, this.height, 32, this.height - 32, 25); this.list.addBig(CFOptions.MAP_RADIUS_XZ); this.list.addBig(CFOptions.MAP_RADIUS_Y); + this.list.addBig(CFOptions.BRIGHTNESS); this.list.addSmall(CFOptions.OPTIONS); this.addWidget(this.list); diff --git a/src/main/resources/assets/bismuthlib/lang/en_us.json b/src/main/resources/assets/bismuthlib/lang/en_us.json index 3ea80eb..9e4721e 100644 --- a/src/main/resources/assets/bismuthlib/lang/en_us.json +++ b/src/main/resources/assets/bismuthlib/lang/en_us.json @@ -16,5 +16,9 @@ "bismuthlib.options.threads": "Threads", "bismuthlib.options.modifyColor": "Modify Light", "bismuthlib.options.modifyColor.true": "Enabled", - "bismuthlib.options.modifyColor.false": "Disabled" + "bismuthlib.options.modifyColor.false": "Disabled", + "bismuthlib.options.brightSources": "Bright Sources", + "bismuthlib.options.brightSources.true": "Enabled", + "bismuthlib.options.brightSources.false": "Disabled", + "bismuthlib.options.brightness": "Brightness" } diff --git a/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout.fsh b/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout.fsh index 3f1ff3c..f47c213 100644 --- a/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout.fsh +++ b/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout.fsh @@ -16,6 +16,7 @@ uniform ivec3 playerSectionPos; uniform ivec2 dataScale; uniform int dataSide; uniform int fastLight; +uniform float lightsBrightness; in vec4 defaultVertex; in vec3 colorMultiplier; @@ -36,7 +37,7 @@ void main() { } int textureSize = textureSize(Sampler7, 0).x; vec4 color = tex * ColorModulator; - color = addColoredLight(color, vertexColor, tex, Sampler7, blockPos, playerSectionPos, ChunkOffset, dataScale, dataSide, skylight, defaultVertex, fastLight, colorMultiplier, meshNormal); + color = addColoredLight(color, vertexColor, tex, Sampler7, blockPos, playerSectionPos, ChunkOffset, dataScale, dataSide, skylight, defaultVertex, fastLight, colorMultiplier, meshNormal, lightsBrightness); color = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor); fragColor = color; } diff --git a/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout.json b/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout.json index 457569d..e5740af 100644 --- a/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout.json +++ b/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout.json @@ -31,6 +31,7 @@ { "name": "dataScale", "type": "int", "count": 2, "values": [ 0, 0 ] }, { "name": "dataSide", "type": "int", "count": 1, "values": [ 0 ] }, { "name": "fastLight", "type": "int", "count": 1, "values": [ 0 ] }, - { "name": "timeOfDay", "type": "float", "count": 1, "values": [ 0.0 ] } + { "name": "timeOfDay", "type": "float", "count": 1, "values": [ 0.0 ] }, + { "name": "lightsBrightness", "type": "float", "count": 1, "values": [ 0.0 ] } ] } diff --git a/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout_mipped.fsh b/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout_mipped.fsh index 3bb8bf2..f47c213 100644 --- a/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout_mipped.fsh +++ b/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout_mipped.fsh @@ -16,12 +16,14 @@ uniform ivec3 playerSectionPos; uniform ivec2 dataScale; uniform int dataSide; uniform int fastLight; +uniform float lightsBrightness; in vec4 defaultVertex; in vec3 colorMultiplier; in vec3 blockPos; in float skylight; +in vec3 meshNormal; in float vertexDistance; in vec4 vertexColor; in vec2 texCoord0; @@ -35,7 +37,7 @@ void main() { } int textureSize = textureSize(Sampler7, 0).x; vec4 color = tex * ColorModulator; - color = addColoredLight(color, vertexColor, tex, Sampler7, blockPos, playerSectionPos, ChunkOffset, dataScale, dataSide, skylight, defaultVertex, fastLight, colorMultiplier); + color = addColoredLight(color, vertexColor, tex, Sampler7, blockPos, playerSectionPos, ChunkOffset, dataScale, dataSide, skylight, defaultVertex, fastLight, colorMultiplier, meshNormal, lightsBrightness); color = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor); fragColor = color; } diff --git a/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout_mipped.json b/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout_mipped.json index 457569d..e5740af 100644 --- a/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout_mipped.json +++ b/src/main/resources/assets/minecraft/shaders/core/rendertype_cutout_mipped.json @@ -31,6 +31,7 @@ { "name": "dataScale", "type": "int", "count": 2, "values": [ 0, 0 ] }, { "name": "dataSide", "type": "int", "count": 1, "values": [ 0 ] }, { "name": "fastLight", "type": "int", "count": 1, "values": [ 0 ] }, - { "name": "timeOfDay", "type": "float", "count": 1, "values": [ 0.0 ] } + { "name": "timeOfDay", "type": "float", "count": 1, "values": [ 0.0 ] }, + { "name": "lightsBrightness", "type": "float", "count": 1, "values": [ 0.0 ] } ] } diff --git a/src/main/resources/assets/minecraft/shaders/core/rendertype_solid.fsh b/src/main/resources/assets/minecraft/shaders/core/rendertype_solid.fsh index 869dbe0..5dce408 100644 --- a/src/main/resources/assets/minecraft/shaders/core/rendertype_solid.fsh +++ b/src/main/resources/assets/minecraft/shaders/core/rendertype_solid.fsh @@ -16,6 +16,7 @@ uniform ivec3 playerSectionPos; uniform ivec2 dataScale; uniform int dataSide; uniform int fastLight; +uniform float lightsBrightness; in vec4 defaultVertex; in vec3 colorMultiplier; @@ -33,7 +34,7 @@ void main() { int textureSize = textureSize(Sampler7, 0).x; vec4 tex = texture(Sampler0, texCoord0); vec4 color = tex * ColorModulator; - color = addColoredLight(color, vertexColor, tex, Sampler7, blockPos, playerSectionPos, ChunkOffset, dataScale, dataSide, skylight, defaultVertex, fastLight, colorMultiplier, meshNormal); + color = addColoredLight(color, vertexColor, tex, Sampler7, blockPos, playerSectionPos, ChunkOffset, dataScale, dataSide, skylight, defaultVertex, fastLight, colorMultiplier, meshNormal, lightsBrightness); color = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor); fragColor = color; } diff --git a/src/main/resources/assets/minecraft/shaders/core/rendertype_solid.json b/src/main/resources/assets/minecraft/shaders/core/rendertype_solid.json index 27b2d71..e38ff97 100644 --- a/src/main/resources/assets/minecraft/shaders/core/rendertype_solid.json +++ b/src/main/resources/assets/minecraft/shaders/core/rendertype_solid.json @@ -31,6 +31,7 @@ { "name": "dataScale", "type": "int", "count": 2, "values": [ 0, 0 ] }, { "name": "dataSide", "type": "int", "count": 1, "values": [ 0 ] }, { "name": "fastLight", "type": "int", "count": 1, "values": [ 0 ] }, - { "name": "timeOfDay", "type": "float", "count": 1, "values": [ 0.0 ] } + { "name": "timeOfDay", "type": "float", "count": 1, "values": [ 0.0 ] }, + { "name": "lightsBrightness", "type": "float", "count": 1, "values": [ 0.0 ] } ] } diff --git a/src/main/resources/assets/minecraft/shaders/include/colorful_fabric.glsl b/src/main/resources/assets/minecraft/shaders/include/colorful_fabric.glsl index 47512ac..a9d4d3f 100644 --- a/src/main/resources/assets/minecraft/shaders/include/colorful_fabric.glsl +++ b/src/main/resources/assets/minecraft/shaders/include/colorful_fabric.glsl @@ -144,13 +144,13 @@ float getDistanceMix(vec3 blockPos, vec3 chunkOffset, ivec2 dataScale) { return clamp(m, 0.0, 1.0); } -vec4 addColoredLight(vec4 color, vec4 vertex, vec4 tex, sampler2D sampler, vec3 blockPos, ivec3 playerSectionPos, vec3 chunkOffset, ivec2 dataScale, int dataSide, float skylight, vec4 defaultVertex, int fastLight, vec3 colorMultiplier, vec3 normal) { +vec4 addColoredLight(vec4 color, vec4 vertex, vec4 tex, sampler2D sampler, vec3 blockPos, ivec3 playerSectionPos, vec3 chunkOffset, ivec2 dataScale, int dataSide, float skylight, vec4 defaultVertex, int fastLight, vec3 colorMultiplier, vec3 normal, float brightness) { //return vec4(skylight, skylight, skylight, 1.0); vec4 def = tex * defaultVertex; vec3 light1 = getInterpolatedColor(sampler, blockPos, playerSectionPos, chunkOffset, dataScale, dataSide); vec3 light2 = getInterpolatedColor(sampler, blockPos + normal * 0.5, playerSectionPos, chunkOffset, dataScale, dataSide); - vec3 coloredLight = max(light1, light2) * (1.0 - skylight); + vec3 coloredLight = max(light1, light2) * (1.0 - skylight) * brightness; float m = getDistanceMix(blockPos, chunkOffset, dataScale); vec3 hsv = rgbToHSV(colorMultiplier.rgb);