Skip to content

Commit

Permalink
Brightness option
Browse files Browse the repository at this point in the history
  • Loading branch information
paulevsGitch committed Sep 15, 2022
1 parent ddecd6a commit 079940e
Show file tree
Hide file tree
Showing 14 changed files with 328 additions and 194 deletions.
354 changes: 184 additions & 170 deletions src/main/java/ru/paulevs/bismuthlib/BismuthLibClient.java

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/main/java/ru/paulevs/bismuthlib/LightPropagator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/ru/paulevs/bismuthlib/data/AdvancedBlockStorage.java
Original file line number Diff line number Diff line change
@@ -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<BlockPos, LightTransformer> transformers = new HashMap<>();
private Map<BlockPos, LightInfo> 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);
}
}
18 changes: 7 additions & 11 deletions src/main/java/ru/paulevs/bismuthlib/data/LevelShaderData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
38 changes: 37 additions & 1 deletion src/main/java/ru/paulevs/bismuthlib/gui/CFOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<Integer> MAP_RADIUS_XZ = new OptionInstance<>(
"bismuthlib.options.mapRadiusXZ",
Expand Down Expand Up @@ -70,6 +74,19 @@ public class CFOptions {
mapRadiusY = val;
}
);
public static final OptionInstance<Integer> 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<Boolean> FAST_LIGHT = new OptionInstance<>(
"bismuthlib.options.lightType",
OptionInstance.noTooltip(),
Expand Down Expand Up @@ -103,9 +120,20 @@ public class CFOptions {
modifyColor = val;
}
);
private static final OptionInstance<Boolean> 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() {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/assets/bismuthlib/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 079940e

Please sign in to comment.