added better shading + small changes

This commit is contained in:
Leonardo
2021-08-27 00:54:46 +02:00
parent 9786a12273
commit fc0aaac69f
6 changed files with 119 additions and 97 deletions
@@ -130,7 +130,7 @@ public class LodBuilder
*/
public void generateLodNodeFromChunk(LodDimension lodDim, IChunk chunk, LodDetail detailLevel) throws IllegalArgumentException
{
generateLodNodeFromChunk(lodDim, chunk, new LodBuilderConfig(),detailLevel);
generateLodNodeFromChunk(lodDim, chunk, new LodBuilderConfig(), detailLevel);
}
/**
@@ -154,7 +154,7 @@ public class LodBuilder
short[] color;
short height;
short depth;
LevelPos levelPos = new LevelPos((byte) 0,0,0);
LevelPos levelPos = new LevelPos((byte) 0, 0, 0);
short[] data;
try
{
@@ -190,9 +190,11 @@ public class LodBuilder
//levelPos.changeParameters(LodUtil.CHUNK_DETAIL_LEVEL, chunk.getPos().x, chunk.getPos().z);
lodDim.updateData(new LevelPos(LodUtil.CHUNK_DETAIL_LEVEL, chunk.getPos().x, chunk.getPos().z));
}catch (NullPointerException e){
} catch (NullPointerException e)
{
e.printStackTrace();
}catch (ArrayIndexOutOfBoundsException e){
} catch (ArrayIndexOutOfBoundsException e)
{
e.printStackTrace();
}
}
@@ -248,6 +250,7 @@ public class LodBuilder
return -1;
}
/**
* Find the lowest valid point from the bottom.
*/
@@ -270,6 +273,8 @@ public class LodBuilder
*/
private short determineHeightPointForArea(ChunkSection[] chunkSections, int startX, int startZ, int endX, int endZ)
{
//blockState.getBlock().isAir();
int numberOfBlocksRequired = ((endX - startX) * (endZ - startZ) / 2);
// search from the top down
for (int section = chunkSections.length - 1; section >= 0; section--)
@@ -304,6 +309,7 @@ public class LodBuilder
return -1;
}
/**
* Find the highest point from the Top
*/
@@ -342,7 +348,7 @@ public class LodBuilder
* material color
*/
private short[] generateLodColorForArea(IChunk chunk, LodBuilderConfig config, int startX, int startZ, int endX,
int endZ)
int endZ)
{
ChunkSection[] chunkSections = chunk.getSections();
@@ -424,51 +430,49 @@ public class LodBuilder
* Returns a color int for a given block.
*/
private int getColorForBlock(int x, int z, BlockState blockState, Biome biome)
{
int colorInt = 0;
// block special cases
if (blockState == Blocks.AIR.defaultBlockState() || blockState == Blocks.CAVE_AIR.defaultBlockState())
{
Color tmp = LodUtil.intToColor(biome.getGrassColor(x, z));
tmp = tmp.darker();
colorInt = LodUtil.colorToInt(tmp);
}
else if (blockState == Blocks.MYCELIUM.defaultBlockState())
{
colorInt = LodUtil.MYCELIUM_COLOR_INT;
}
// plant life
else if (blockState.getBlock() instanceof LeavesBlock || blockState.getBlock() == Blocks.VINE)
{
Color leafColor = LodUtil.intToColor(biome.getFoliageColor()).darker();
leafColor = leafColor.darker();
colorInt = LodUtil.colorToInt(leafColor);
}
else if ((blockState.getBlock() instanceof GrassBlock || blockState.getBlock() instanceof AbstractPlantBlock
|| blockState.getBlock() instanceof BushBlock || blockState.getBlock() instanceof IGrowable)
&& !(blockState.getBlock() == Blocks.BROWN_MUSHROOM || blockState.getBlock() == Blocks.RED_MUSHROOM))
{
Color plantColor = LodUtil.intToColor(biome.getGrassColor(x, z));
plantColor = plantColor.darker();
colorInt = LodUtil.colorToInt(plantColor);
}
// water
else if (blockState.getBlock() == Blocks.WATER)
{
colorInt = biome.getWaterColor();
}
// everything else
else
{
colorInt = blockState.materialColor.col;
}
return colorInt;
}
{
int colorInt = 0;
// block special cases
if (blockState == Blocks.AIR.defaultBlockState() || blockState == Blocks.CAVE_AIR.defaultBlockState())
{
Color tmp = LodUtil.intToColor(biome.getGrassColor(x, z));
tmp = tmp.darker();
colorInt = LodUtil.colorToInt(tmp);
} else if (blockState == Blocks.MYCELIUM.defaultBlockState())
{
colorInt = LodUtil.MYCELIUM_COLOR_INT;
}
// plant life
else if (blockState.getBlock() instanceof LeavesBlock || blockState.getBlock() == Blocks.VINE)
{
Color leafColor = LodUtil.intToColor(biome.getFoliageColor()).darker();
leafColor = leafColor.darker();
colorInt = LodUtil.colorToInt(leafColor);
} else if ((blockState.getBlock() instanceof GrassBlock || blockState.getBlock() instanceof AbstractPlantBlock
|| blockState.getBlock() instanceof BushBlock || blockState.getBlock() instanceof IGrowable)
&& !(blockState.getBlock() == Blocks.BROWN_MUSHROOM || blockState.getBlock() == Blocks.RED_MUSHROOM))
{
Color plantColor = LodUtil.intToColor(biome.getGrassColor(x, z));
plantColor = plantColor.darker();
colorInt = LodUtil.colorToInt(plantColor);
}
// water
else if (blockState.getBlock() == Blocks.WATER)
{
colorInt = biome.getWaterColor();
}
// everything else
else
{
colorInt = blockState.materialColor.col;
}
return colorInt;
}
/**
* Returns a color int for the given biome.
@@ -545,7 +549,7 @@ public class LodBuilder
} else
{
if (chunkSections[sectionIndex].getBlockState(x, y, z) != null
&& chunkSections[sectionIndex].getBlockState(x, y, z).getBlock() != Blocks.AIR
&& chunkSections[sectionIndex].getBlockState(x, y, z).getBlock() != Blocks.AIR
&& chunkSections[sectionIndex].getBlockState(x, y, z).getBlock() != Blocks.CAVE_AIR)
{
return true;
@@ -26,7 +26,9 @@ import com.seibel.lod.objects.LevelPos.LevelPos;
import com.seibel.lod.util.ColorUtil;
import com.seibel.lod.util.LodUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
@@ -109,9 +111,11 @@ public class CubicLodTemplate extends AbstractLodTemplate
private void addBoundingBoxToBuffer(BufferBuilder buffer, AxisAlignedBB bb, int c, BlockPos playerBlockPos, short[][][] adjData)
{
int topColor = c;
int northSouthColor = c;
int eastWestColor = c;
int bottomColor = c;
int northColor = c;
int southColor = c;
int westColor = c;
int eastColor = c;
// darken the bottom and side colors if requested
if (LodConfig.CLIENT.shadingMode.get() == ShadingMode.DARKEN_SIDES)
@@ -127,23 +131,32 @@ public class CubicLodTemplate extends AbstractLodTemplate
northSouthColor = ColorUtil.applyShade(c,northSouthDarkenAmount);
eastWestColor = ColorUtil.applyShade(c,eastWestDarkenAmount);
bottomColor = ColorUtil.applyShade(c,bottomDarkenAmount);*/
/*
float northSouthDarkenAmount = 0.80f;
float eastWestDarkenAmount = 0.60f;
float bottomDarkenAmount = 0.40f;
northSouthColor = ColorUtil.applyShade(c,northSouthDarkenAmount);
eastWestColor = ColorUtil.applyShade(c,eastWestDarkenAmount);
bottomColor = ColorUtil.applyShade(c,bottomDarkenAmount);
float bottomDarkenAmount = 0.40f;*/
/**TODO OPTIMIZE THIS STEP*
topColor = ColorUtil.applyShade(c, Minecraft.getInstance().level.getShade(Direction.UP,true));
bottomColor = ColorUtil.applyShade(c, Minecraft.getInstance().level.getShade(Direction.DOWN,true));
northColor = ColorUtil.applyShade(c, Minecraft.getInstance().level.getShade(Direction.NORTH,true));
southColor = ColorUtil.applyShade(c, Minecraft.getInstance().level.getShade(Direction.SOUTH,true));
westColor = ColorUtil.applyShade(c, Minecraft.getInstance().level.getShade(Direction.WEST,true));
eastColor = ColorUtil.applyShade(c, Minecraft.getInstance().level.getShade(Direction.EAST,true));
}
// apply the user specified saturation and brightness
float saturationMultiplier = LodConfig.CLIENT.saturationMultiplier.get().floatValue();
float brightnessMultiplier = LodConfig.CLIENT.brightnessMultiplier.get().floatValue();
topColor = ColorUtil.applySaturationAndBrightnessMultipliers(topColor, saturationMultiplier, brightnessMultiplier);
northSouthColor = ColorUtil.applySaturationAndBrightnessMultipliers(northSouthColor, saturationMultiplier, brightnessMultiplier);
bottomColor = ColorUtil.applySaturationAndBrightnessMultipliers(bottomColor, saturationMultiplier, brightnessMultiplier);
if(saturationMultiplier != 1 || brightnessMultiplier != 1)
{
topColor = ColorUtil.applySaturationAndBrightnessMultipliers(topColor, saturationMultiplier, brightnessMultiplier);
bottomColor = ColorUtil.applySaturationAndBrightnessMultipliers(bottomColor, saturationMultiplier, brightnessMultiplier);
northColor = ColorUtil.applySaturationAndBrightnessMultipliers(northColor, saturationMultiplier, brightnessMultiplier);
southColor = ColorUtil.applySaturationAndBrightnessMultipliers(southColor, saturationMultiplier, brightnessMultiplier);
westColor = ColorUtil.applySaturationAndBrightnessMultipliers(westColor, saturationMultiplier, brightnessMultiplier);
eastColor = ColorUtil.applySaturationAndBrightnessMultipliers(eastColor, saturationMultiplier, brightnessMultiplier);
}
int minY;
int maxY;
short[] data;
@@ -180,10 +193,10 @@ public class CubicLodTemplate extends AbstractLodTemplate
if (playerBlockPos.getZ() > bb.minZ - CULL_OFFSET)
{
red = ColorUtil.getRed(northSouthColor);
green = ColorUtil.getGreen(northSouthColor);
blue = ColorUtil.getBlue(northSouthColor);
alpha = ColorUtil.getAlpha(northSouthColor);
red = ColorUtil.getRed(northColor);
green = ColorUtil.getGreen(northColor);
blue = ColorUtil.getBlue(northColor);
alpha = ColorUtil.getAlpha(northColor);
// south (facing -Z)
data = adjData[1][1];
if (data == null)
@@ -217,10 +230,10 @@ public class CubicLodTemplate extends AbstractLodTemplate
if (playerBlockPos.getZ() < bb.maxZ + CULL_OFFSET)
{
red = ColorUtil.getRed(northSouthColor);
green = ColorUtil.getGreen(northSouthColor);
blue = ColorUtil.getBlue(northSouthColor);
alpha = ColorUtil.getAlpha(northSouthColor);
red = ColorUtil.getRed(southColor);
green = ColorUtil.getGreen(southColor);
blue = ColorUtil.getBlue(southColor);
alpha = ColorUtil.getAlpha(southColor);
data = adjData[1][0];
// north (facing +Z)
if (data == null)
@@ -254,10 +267,10 @@ public class CubicLodTemplate extends AbstractLodTemplate
if (playerBlockPos.getX() < bb.maxX + CULL_OFFSET)
{
red = ColorUtil.getRed(eastWestColor);
green = ColorUtil.getGreen(eastWestColor);
blue = ColorUtil.getBlue(eastWestColor);
alpha = ColorUtil.getAlpha(eastWestColor);
red = ColorUtil.getRed(westColor);
green = ColorUtil.getGreen(westColor);
blue = ColorUtil.getBlue(westColor);
alpha = ColorUtil.getAlpha(westColor);
// west (facing -X)
data = adjData[0][0];
if (data == null)
@@ -291,10 +304,10 @@ public class CubicLodTemplate extends AbstractLodTemplate
if (playerBlockPos.getX() > bb.minX - CULL_OFFSET)
{
red = ColorUtil.getRed(eastWestColor);
green = ColorUtil.getGreen(eastWestColor);
blue = ColorUtil.getBlue(eastWestColor);
alpha = ColorUtil.getAlpha(eastWestColor);
red = ColorUtil.getRed(eastColor);
green = ColorUtil.getGreen(eastColor);
blue = ColorUtil.getBlue(eastColor);
alpha = ColorUtil.getAlpha(eastColor);
// east (facing +X)
data = adjData[0][1];
if (data == null)
@@ -68,7 +68,6 @@ public class LodDimension
private LodDimensionFileHandler fileHandler;
/**
* Creates the dimension centered at (0,0)
*
@@ -378,20 +378,24 @@ public class LodRegion implements Serializable
byte detailLevel = levelPos.detailLevel;
int posX = levelPos.posX;
int posZ = levelPos.posZ;
for(byte bottom = (byte) (minDetailLevel + 1); bottom <= detailLevel ; bottom++){
for (byte bottom = (byte) (minDetailLevel + 1); bottom <= detailLevel; bottom++)
{
levelPos.convert(bottom);
startX = levelPos.posX;
startZ = levelPos.posZ;
width = 1 << (detailLevel - bottom);
for(int x = 0; x < width; x++){
for(int z = 0; z < width; z++) {
levelPos.changeParameters(bottom,startX+x,startZ+z);
for (int x = 0; x < width; x++)
{
for (int z = 0; z < width; z++)
{
levelPos.changeParameters(bottom, startX + x, startZ + z);
update(levelPos);
}
}
levelPos.changeParameters(detailLevel,posX,posZ);
levelPos.changeParameters(detailLevel, posX, posZ);
}
for (byte tempLod = (byte) (detailLevel + 1); tempLod <= LodUtil.REGION_DETAIL_LEVEL; tempLod++) {
for (byte tempLod = (byte) (detailLevel + 1); tempLod <= LodUtil.REGION_DETAIL_LEVEL; tempLod++)
{
levelPos.convert(tempLod);
update(levelPos);
}
@@ -539,7 +543,8 @@ public class LodRegion implements Serializable
try
{
return (generationType[levelPos.detailLevel][levelPos.posX][levelPos.posZ] != 0);
}catch(Exception e){
} catch (Exception e)
{
System.out.println(levelPos);
e.printStackTrace();
throw e;
@@ -17,6 +17,8 @@
*/
package com.seibel.lod.proxy;
import net.minecraft.util.Direction;
import net.minecraft.world.lighting.WorldLightManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -62,11 +64,12 @@ public class ClientProxy
private static LodBufferBuilder lodBufferBuilder = new LodBufferBuilder();
private static LodRenderer renderer = new LodRenderer(lodBufferBuilder);
private static LodWorldGenerator lodWorldGenerator = LodWorldGenerator.INSTANCE;
private boolean configOverrideReminderPrinted = false;
Minecraft mc = Minecraft.getInstance();
/** This is used to determine if the LODs should be regenerated */
public static int previousChunkRenderDistance = 0;
/** This is used to determine if the LODs should be regenerated */
@@ -125,8 +128,6 @@ public class ClientProxy
profiler.pop(); // end LOD
profiler.push("terrain"); // restart "terrain"
applyConfigOverrides();
// these can't be set until after the buffers are built (in renderer.drawLODs)
// otherwise the buffers may be set to the wrong size, or not changed at all
@@ -153,13 +154,13 @@ public class ClientProxy
LodConfig.CLIENT.fogDistance.set(FogDistance.FAR);
LodConfig.CLIENT.fogDrawOverride.set(FogDrawOverride.ALWAYS_DRAW_FOG_FANCY);
LodConfig.CLIENT.shadingMode.set(ShadingMode.DARKEN_SIDES);
LodConfig.CLIENT.brightnessMultiplier.set(1.2);
LodConfig.CLIENT.saturationMultiplier.set(1.1);
LodConfig.CLIENT.brightnessMultiplier.set(1.0);
LodConfig.CLIENT.saturationMultiplier.set(1.0);
LodConfig.CLIENT.distanceGenerationMode.set(DistanceGenerationMode.SURFACE);
LodConfig.CLIENT.lodChunkRenderDistance.set(128);
LodConfig.CLIENT.lodDistanceCalculatorType.set(DistanceCalculatorType.QUADRATIC);
LodConfig.CLIENT.lodQuality.set(1);
LodConfig.CLIENT.lodDistanceCalculatorType.set(DistanceCalculatorType.LINEAR);
LodConfig.CLIENT.lodQuality.set(2);
LodConfig.CLIENT.allowUnstableFeatureGeneration.set(false);
LodConfig.CLIENT.numberOfWorldGenerationThreads.set(Runtime.getRuntime().availableProcessors());
@@ -7,9 +7,9 @@ import net.minecraft.client.Minecraft;
public class DetailDistanceUtil
{
private static double genMultiplier = 2;
private static double treeGenMultiplier = 2;
private static double treeCutMultiplier = 1.5;
private static double genMultiplier = 1.25;
private static double treeGenMultiplier = 1.5;
private static double treeCutMultiplier = 1.25;
private static int minDetail = LodConfig.CLIENT.maxGenerationDetail.get().detailLevel;
private static int maxDetail = LodUtil.REGION_DETAIL_LEVEL + 1;
private static int minDistance = 0;