Added fake lighting system. Improved some point

This commit is contained in:
Leonardo
2021-09-15 16:17:26 +02:00
parent cdeba2616c
commit 5ede5fa202
9 changed files with 125 additions and 80 deletions
@@ -142,19 +142,6 @@ public class LodBufferBuilder
BlockPos playerBlockPos, boolean fullRegen)
{
/*
for(int i = 0; i<16; i++)
{
for(int j = 0; j<16; j++)
{
int lightTint = LightTexture.pack(i,j);
//System.out.print(ColorUtil.getRed(lightTint) + " " + ColorUtil.getGreen(lightTint) + " " + ColorUtil.getBlue(lightTint) + " ");
System.out.print(Integer.toHexString(lightTint) + " ");
}
System.out.println();
}*/
// only allow one generation process to happen at a time
if (generatingBuffers)
return;
@@ -318,7 +305,7 @@ public class LodBufferBuilder
}
}
LodConfig.CLIENT.graphics.lodTemplate.get().template.addLodToBuffer(currentBuffer, playerBlockPosRounded, dataPoint, adjData,
detailLevel, posX, posZ, boxCache[xR][zR],renderer.previousDebugMode);
detailLevel, posX, posZ, boxCache[xR][zR],renderer.previousDebugMode, lodDim.dimension);
}
} else if (region.getLodQualityMode() == LodQualityMode.MULTI_LOD)
@@ -329,7 +316,7 @@ public class LodBufferBuilder
if (!DataPointUtil.isItVoid(dataPoint) && DataPointUtil.doesItExist(dataPoint))
{
LodConfig.CLIENT.graphics.lodTemplate.get().template.addLodToBuffer(currentBuffer, playerBlockPosRounded, dataPoint, adjData,
detailLevel, posX, posZ, boxCache[xR][zR], renderer.previousDebugMode);
detailLevel, posX, posZ, boxCache[xR][zR], renderer.previousDebugMode, lodDim.dimension);
}
}
}
@@ -194,7 +194,8 @@ public class LodBuilder
long[] data = null;
boolean isServer = config.distanceGenerationMode == DistanceGenerationMode.SERVER;
switch (lodQualityMode){
switch (lodQualityMode)
{
default:
case HEIGHTMAP:
long[] dataToMergeSingle;
@@ -223,7 +224,6 @@ public class LodBuilder
}
}
lodDim.updateData(LodUtil.CHUNK_DETAIL_LEVEL, chunk.getPos().x, chunk.getPos().z);
} catch (Exception e)
@@ -253,14 +253,15 @@ public class LodBuilder
BlockPos.Mutable blockPos = new BlockPos.Mutable(0, 0, 0);
int index = 0;
if(dataToMerge == null){
if (dataToMerge == null)
{
dataToMerge = new long[size * size][DataPointUtil.WORLD_HEIGHT];
}
//dataToMerge = new long[size * size][1024];
for (index = 0; index < size * size; index++)
{
for(int i = 0; i < dataToMerge[index].length; i++)
for (int i = 0; i < dataToMerge[index].length; i++)
{
dataToMerge[index][i] = 0;
}
@@ -546,6 +547,10 @@ public class LodBuilder
//*TODO choose the best one between those options*/
//lightBlock = MinecraftWrapper.INSTANCE.getPlayer().level.getLightEngine().getLayerListener(LightType.BLOCK).getLightValue(blockPos);
//lightBlock = (byte) MinecraftWrapper.INSTANCE.getPlayer().level.getLightEngine().blockEngine.getLightValue(blockPos);
if (MinecraftWrapper.INSTANCE.getPlayer() == null)
return 0;
if (MinecraftWrapper.INSTANCE.getPlayer().level == null)
return 0;
light = MinecraftWrapper.INSTANCE.getPlayer().level.getBrightness(LightType.BLOCK, blockPos);
light += MinecraftWrapper.INSTANCE.getPlayer().level.getBrightness(LightType.SKY, blockPos) << 4;
//BlockState blockState = chunk.getBlockState(blockPos);
@@ -581,6 +586,18 @@ public class LodBuilder
} else if (blockState == Blocks.CRIMSON_NYLIUM.defaultBlockState())
{
colorInt = LodUtil.CRIMSON_NYLIUM_COLOR_INT;
} else if (blockState == Blocks.WEEPING_VINES.defaultBlockState()
|| blockState == Blocks.WEEPING_VINES_PLANT.defaultBlockState()
|| blockState == Blocks.CRIMSON_FUNGUS.defaultBlockState()
|| blockState == Blocks.CRIMSON_ROOTS.defaultBlockState())
{
colorInt = Blocks.NETHER_WART_BLOCK.defaultMaterialColor().col;
} else if (blockState == Blocks.TWISTING_VINES.defaultBlockState()
|| blockState == Blocks.TWISTING_VINES_PLANT.defaultBlockState()
|| blockState == Blocks.CRIMSON_FUNGUS.defaultBlockState()
|| blockState == Blocks.CRIMSON_ROOTS.defaultBlockState())
{
colorInt = Blocks.WARPED_WART_BLOCK.defaultMaterialColor().col;
} else if (blockState == Blocks.BEDROCK.defaultBlockState())
{
colorInt = getColorForBiome(x, z, biome);
@@ -703,6 +720,8 @@ public class LodBuilder
BlockState blockState = chunk.getBlockState(blockPos);
if (blockState != null)
{
//blockState.isCollisionShapeFullBlock(chunk, blockPos);
/*if (!blockState.getFluidState().isEmpty())
{
return true;
@@ -22,6 +22,7 @@ import com.seibel.lod.enums.DebugMode;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.DimensionType;
/**
* This is the abstract class used to create different
@@ -35,7 +36,7 @@ public abstract class AbstractLodTemplate
public abstract void addLodToBuffer(BufferBuilder buffer, BlockPos bufferCenterBlockPos, long data, long[] adjData,
byte detailLevel, int posX, int posZ, Box box, DebugMode debugging);
byte detailLevel, int posX, int posZ, Box box, DebugMode debugging, DimensionType dimensionType);
/**
* add the given position and color to the buffer
@@ -20,6 +20,7 @@ package com.seibel.lod.builders.lodTemplates;
import com.seibel.lod.config.LodConfig;
import com.seibel.lod.enums.DebugMode;
import com.seibel.lod.enums.ShadingMode;
import com.seibel.lod.objects.LodDimension;
import com.seibel.lod.util.DataPointUtil;
import com.seibel.lod.util.ColorUtil;
import com.seibel.lod.util.LodUtil;
@@ -27,8 +28,10 @@ import com.seibel.lod.util.LodUtil;
import com.seibel.lod.wrappers.MinecraftWrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.DimensionType;
/**
* Builds LODs as rectangular prisms.
@@ -47,7 +50,7 @@ public class CubicLodTemplate extends AbstractLodTemplate
@Override
public void addLodToBuffer(BufferBuilder buffer, BlockPos bufferCenterBlockPos, long data, long[] adjData,
byte detailLevel, int posX, int posZ, Box box, DebugMode debugging)
byte detailLevel, int posX, int posZ, Box box, DebugMode debugging, DimensionType dimensionType)
{
int width = 1 << detailLevel;
@@ -61,14 +64,15 @@ public class CubicLodTemplate extends AbstractLodTemplate
0,
posZ * width,
bufferCenterBlockPos);
int color;/*
boolean hasSkyLight = MinecraftWrapper.INSTANCE.getPlayer().level.dimensionType().hasSkyLight();
boolean hasRoof = MinecraftWrapper.INSTANCE.getPlayer().level.dimensionType().hasSkyLight();
int time = (int) (MinecraftWrapper.INSTANCE.getPlayer().level.getDayTime() - 13000);
boolean isDay = time < 0;*/
//USE THIS IN THE boolean hasCeiling = MinecraftWrapper.INSTANCE.getPlayer().level.dimensionType().hasCeiling();
//color = DataPointUtil.getLightColor(data, (hasRoof & hasSkyLight), isDay);
color = DataPointUtil.getColor(data);
int color;
boolean hasSkyLight = dimensionType.hasSkyLight();
boolean hasRoof = dimensionType.hasCeiling();
boolean isDay = MinecraftWrapper.INSTANCE.getPlayer().level.isDay();
color = DataPointUtil.getLightColor(data, (hasRoof || hasSkyLight), isDay);
//color = DataPointUtil.getColor(data);
if (debugging != DebugMode.OFF)
@@ -21,6 +21,7 @@ import com.seibel.lod.enums.DebugMode;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.DimensionType;
/**
* TODO DynamicLodTemplate
@@ -35,7 +36,7 @@ public class DynamicLodTemplate extends AbstractLodTemplate
{
@Override
public void addLodToBuffer(BufferBuilder buffer, BlockPos bufferCenterBlockPos, long data, long[] adjData,
byte detailLevel, int posX, int posZ, Box box, DebugMode debugging)
byte detailLevel, int posX, int posZ, Box box, DebugMode debugging, DimensionType dimensionType)
{
System.err.println("DynamicLodTemplate not implemented!");
}
@@ -21,6 +21,7 @@ import com.seibel.lod.enums.DebugMode;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.DimensionType;
/**
* TODO #21 TriangularLodTemplate
@@ -33,7 +34,7 @@ public class TriangularLodTemplate extends AbstractLodTemplate
{
@Override
public void addLodToBuffer(BufferBuilder buffer, BlockPos bufferCenterBlockPos, long data, long[] adjData,
byte detailLevel, int posX, int posZ, Box box, DebugMode debugging)
byte detailLevel, int posX, int posZ, Box box, DebugMode debugging, DimensionType dimensionType)
{
System.err.println("DynamicLodTemplate not implemented!");
}
@@ -100,53 +100,57 @@ public class ClientProxy
*/
public void renderLods(float partialTicks)
{
// only run the first time setup once
if (!firstTimeSetupComplete)
try
{
firstFrameSetup();
// only run the first time setup once
if (!firstTimeSetupComplete)
{
firstFrameSetup();
}
DetailDistanceUtil.updateSettings();
if (mc == null || mc.getPlayer() == null || !lodWorld.getIsWorldLoaded())
return;
viewDistanceChangedEvent();
LodDimension lodDim = lodWorld.getLodDimension(mc.getCurrentDimension());
if (lodDim == null)
return;
playerMoveEvent(lodDim);
lodDim.treeCutter((int) mc.getPlayer().getX(), (int) mc.getPlayer().getZ());
lodDim.treeGenerator((int) mc.getPlayer().getX(), (int) mc.getPlayer().getZ());
// comment out when creating a release
applyConfigOverrides();
// Note to self:
// if "unspecified" shows up in the pie chart, it is
// possibly because the amount of time between sections
// is too small for the profiler to measure
IProfiler profiler = mc.getProfiler();
profiler.pop(); // get out of "terrain"
profiler.push("LOD");
renderer.drawLODs(lodDim, partialTicks, mc.getProfiler());
profiler.pop(); // end LOD
profiler.push("terrain"); // go back into "terrain"
// 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
previousChunkRenderDistance = mc.getRenderDistance();
previousLodRenderDistance = LodConfig.CLIENT.graphics.lodChunkRenderDistance.get();
}catch (Exception e){
}
DetailDistanceUtil.updateSettings();
if (mc == null || mc.getPlayer() == null || !lodWorld.getIsWorldLoaded())
return;
viewDistanceChangedEvent();
LodDimension lodDim = lodWorld.getLodDimension(mc.getCurrentDimension());
if (lodDim == null)
return;
playerMoveEvent(lodDim);
lodDim.treeCutter((int) mc.getPlayer().getX(), (int) mc.getPlayer().getZ());
lodDim.treeGenerator((int) mc.getPlayer().getX(), (int) mc.getPlayer().getZ());
// comment out when creating a release
applyConfigOverrides();
// Note to self:
// if "unspecified" shows up in the pie chart, it is
// possibly because the amount of time between sections
// is too small for the profiler to measure
IProfiler profiler = mc.getProfiler();
profiler.pop(); // get out of "terrain"
profiler.push("LOD");
renderer.drawLODs(lodDim, partialTicks, mc.getProfiler());
profiler.pop(); // end LOD
profiler.push("terrain"); // go back into "terrain"
// 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
previousChunkRenderDistance = mc.getRenderDistance();
previousLodRenderDistance = LodConfig.CLIENT.graphics.lodChunkRenderDistance.get();
}
@@ -67,4 +67,16 @@ public class ColorUtil
LodUtil.clamp(0.0f, hsv[1] * saturationMultiplier, 1.0f),
LodUtil.clamp(0.0f, hsv[2] * brightnessMultiplier, 1.0f)).getRGB();
}
/**
* Edit the given color as a HSV (Hue Saturation Value) color.
*/
public static int changeBrightness(int color, float brightness)
{
float[] hsv = Color.RGBtoHSB(getRed(color), getGreen(color), getBlue(color), null);
return Color.getHSBColor(
hsv[0], // hue
hsv[1],
brightness).getRGB();
}
}
@@ -175,11 +175,27 @@ public class DataPointUtil
{
int lightBlock = getLightBlock(dataPoint);
int lightSky = getLightSky(dataPoint);
int lightTint = LightTexture.pack(lightSky,lightBlock);
int lightTint = 0;
int red = (ColorUtil.getRed(lightTint) + getRed(dataPoint))/2;
int green = (ColorUtil.getGreen(lightTint) + getGreen(dataPoint))/2;
int blue = (ColorUtil.getBlue(lightTint) + getBlue(dataPoint))/2;
int red;
int green;
int blue;
if(roof)
{
red = LodUtil.clamp(0, getRed(dataPoint) + -30 + lightBlock*4,255);
green = LodUtil.clamp(0, getGreen(dataPoint) + -30 + lightBlock*4,255);
blue = LodUtil.clamp(0, getBlue(dataPoint) + -30 + lightBlock*2,255);
}else{
if(day){
red = LodUtil.clamp(0, getRed(dataPoint) + -30 + LodUtil.clamp(0, lightBlock + lightSky,15)*4,255);
green = LodUtil.clamp(0, getGreen(dataPoint) + -30 + LodUtil.clamp(0, lightBlock + lightSky,15)*4,255);
blue = LodUtil.clamp(0, getBlue(dataPoint) + -30 + LodUtil.clamp(0, lightBlock/2 + lightSky,15)*4,255);
}else{
red = LodUtil.clamp(0, getRed(dataPoint) + -60 + lightBlock*6,255);
green = LodUtil.clamp(0, getGreen(dataPoint) + -60 + lightBlock*6,255);
blue = LodUtil.clamp(0, getBlue(dataPoint) + -30 + lightBlock*2,255);
}
}
/*
red = LodUtil.clamp(0, getRed(dataPoint) + red, 255);
green = LodUtil.clamp(0, getGreen(dataPoint) + green, 255);