Introduced light and added normal in the template for future shading improvement
This commit is contained in:
@@ -263,11 +263,12 @@ public class LodBuilder
|
||||
continue;
|
||||
}
|
||||
|
||||
yAbs = height;
|
||||
blockPos.set(xAbs, yAbs, zAbs);
|
||||
yAbs = height - 1;
|
||||
// We search light on above air block
|
||||
blockPos.set(xAbs, yAbs + 1, zAbs);
|
||||
|
||||
color = generateLodColor(chunk, config, xRel, height, zRel);
|
||||
light = getLightBlockValue(chunk, blockPos, xRel, yAbs, zRel);
|
||||
color = generateLodColor(chunk, config, xRel, yAbs, zRel);
|
||||
light = getLightBlockValue(chunk, blockPos);
|
||||
depth = determineBottomPoint(chunk, config, xRel, zRel);
|
||||
|
||||
dataToMerge[index] = DataPointUtil.createDataPoint(height, depth, color, light, generation);
|
||||
@@ -331,7 +332,7 @@ public class LodBuilder
|
||||
{
|
||||
if (isLayerValidLodPoint(chunkSections, sectionIndex, yRel, xRel, zRel))
|
||||
{
|
||||
height = (short) (sectionIndex * CHUNK_DATA_WIDTH + yRel);
|
||||
height = (short) (sectionIndex * CHUNK_DATA_WIDTH + yRel + 1);
|
||||
voidData = false;
|
||||
break;
|
||||
}
|
||||
@@ -376,14 +377,15 @@ public class LodBuilder
|
||||
return colorInt;
|
||||
}
|
||||
|
||||
private byte getLightBlockValue(IChunk chunk, BlockPos.Mutable blockPos, int xRel, int yAbs, int zRel)
|
||||
private int getLightBlockValue(IChunk chunk, BlockPos.Mutable blockPos)
|
||||
{
|
||||
byte lightBlock;
|
||||
BlockState blockState = chunk.getSections()[Math.floorDiv(yAbs, CHUNK_SECTION_HEIGHT)].getBlockState(xRel, Math.floorMod(yAbs, CHUNK_SECTION_HEIGHT), zRel);
|
||||
int lightBlock;
|
||||
|
||||
//lightBlock = MinecraftWrapper.INSTANCE.getPlayer().level.getLightEngine().getLayerListener(LightType.BLOCK).getLightValue(blockPos);
|
||||
//lightBlock = MinecraftWrapper.INSTANCE.getPlayer().level.getLightEngine().blockEngine.getLightValue(blockPos);
|
||||
lightBlock = (byte) blockState.getLightBlock(chunk, blockPos);
|
||||
//lightBlock = (byte) MinecraftWrapper.INSTANCE.getPlayer().level.getLightEngine().blockEngine.getLightValue(blockPos);
|
||||
lightBlock = (byte) MinecraftWrapper.INSTANCE.getPlayer().level.getBrightness(LightType.BLOCK, blockPos);
|
||||
//BlockState blockState = chunk.getBlockState(blockPos);
|
||||
//lightBlock = (byte) blockState.getLightBlock(chunk, blockPos);
|
||||
return lightBlock;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,9 @@ package com.seibel.lod.builders.lodTemplates;
|
||||
|
||||
import com.seibel.lod.enums.DebugMode;
|
||||
|
||||
import com.seibel.lod.enums.DistanceGenerationMode;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
@@ -31,9 +33,17 @@ import net.minecraft.util.math.BlockPos;
|
||||
*/
|
||||
public abstract class AbstractLodTemplate
|
||||
{
|
||||
|
||||
private Direction direction;
|
||||
|
||||
public abstract void addLodToBuffer(BufferBuilder buffer, BlockPos bufferCenterBlockPos, long data, long[] adjData,
|
||||
byte detailLevel, int posX, int posZ, Box box, DebugMode debugging);
|
||||
|
||||
|
||||
protected void setDirection(Direction direction){
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* add the given position and color to the buffer
|
||||
*/
|
||||
@@ -41,7 +51,8 @@ public abstract class AbstractLodTemplate
|
||||
double x, double y, double z,
|
||||
int red, int green, int blue, int alpha)
|
||||
{
|
||||
buffer.vertex(x, y, z).color(red, green, blue, alpha).endVertex();
|
||||
|
||||
buffer.vertex(x, y, z).color(red, green, blue, alpha).normal(direction.getNormal().getX(), direction.getNormal().getY(), direction.getNormal().getZ()).endVertex();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,14 +61,15 @@ public class CubicLodTemplate extends AbstractLodTemplate
|
||||
0,
|
||||
posZ * width,
|
||||
bufferCenterBlockPos);
|
||||
int color;/*
|
||||
if(MinecraftWrapper.INSTANCE.getPlayer().level.isDay())
|
||||
int color;
|
||||
int time = (int) (MinecraftWrapper.INSTANCE.getPlayer().level.getDayTime() - 13000);
|
||||
if(time < 0)
|
||||
{
|
||||
color = DataPointUtil.getColor(data);
|
||||
}else{
|
||||
/*TODO implement a smoother transition for light from day to night */
|
||||
color = DataPointUtil.getLightColor(data);
|
||||
}*/
|
||||
color = DataPointUtil.getLightColor(data);
|
||||
}
|
||||
|
||||
if (debugging != DebugMode.OFF)
|
||||
{
|
||||
@@ -171,6 +172,7 @@ public class CubicLodTemplate extends AbstractLodTemplate
|
||||
maxY = box.getMaxY();
|
||||
minZ = box.getMinZ();
|
||||
maxZ = box.getMaxZ();
|
||||
setDirection(Direction.UP);
|
||||
addPosAndColor(buffer, minX, maxY, minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, minX, maxY, maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, maxX, maxY, maxZ, red, green, blue, alpha);
|
||||
@@ -189,6 +191,7 @@ public class CubicLodTemplate extends AbstractLodTemplate
|
||||
maxY = box.getMaxY();
|
||||
minZ = box.getMinZ();
|
||||
maxZ = box.getMaxZ();
|
||||
setDirection(Direction.DOWN);
|
||||
addPosAndColor(buffer, maxX, minY, minZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, maxX, minY, maxZ, red, green, blue, alpha);
|
||||
addPosAndColor(buffer, minX, minY, maxZ, red, green, blue, alpha);
|
||||
@@ -210,6 +213,7 @@ public class CubicLodTemplate extends AbstractLodTemplate
|
||||
maxY = box.getMaxY();
|
||||
minZ = box.getMinZ();
|
||||
maxZ = box.getMaxZ();
|
||||
setDirection(Direction.WEST);
|
||||
if (data == 0)
|
||||
{
|
||||
addPosAndColor(buffer, minX, minY, minZ, red, green, blue, alpha);
|
||||
@@ -255,6 +259,7 @@ public class CubicLodTemplate extends AbstractLodTemplate
|
||||
maxY = box.getMaxY();
|
||||
minZ = box.getMinZ();
|
||||
maxZ = box.getMaxZ();
|
||||
setDirection(Direction.EAST);
|
||||
if (data == 0)
|
||||
{
|
||||
addPosAndColor(buffer, maxX, maxY, minZ, red, green, blue, alpha);
|
||||
@@ -301,6 +306,7 @@ public class CubicLodTemplate extends AbstractLodTemplate
|
||||
minZ = box.getMinZ();
|
||||
maxZ = box.getMaxZ();
|
||||
// north (facing +Z)
|
||||
setDirection(Direction.NORTH);
|
||||
if (data == 0)
|
||||
{
|
||||
addPosAndColor(buffer, maxX, minY, maxZ, red, green, blue, alpha);
|
||||
@@ -347,6 +353,7 @@ public class CubicLodTemplate extends AbstractLodTemplate
|
||||
minZ = box.getMinZ();
|
||||
maxZ = box.getMaxZ();
|
||||
// south (facing -Z)
|
||||
setDirection(Direction.SOUTH);
|
||||
if (data == 0)
|
||||
{
|
||||
addPosAndColor(buffer, minX, minY, minZ, red, green, blue, alpha);
|
||||
|
||||
@@ -125,11 +125,13 @@ public class DataPointUtil
|
||||
{
|
||||
return (int) ((dataPoint >>> COLOR_SHIFT) & COLOR_MASK);
|
||||
}
|
||||
|
||||
public static int getLightColor(long dataPoint)
|
||||
{
|
||||
int red = Math.min(getRed(dataPoint) + getLightValue(dataPoint)*8, 255);
|
||||
int green = Math.min(getGreen(dataPoint) + getLightValue(dataPoint)*8, 255);
|
||||
int blue = Math.min(getBlue(dataPoint) + getLightValue(dataPoint)*4, 255);
|
||||
int lightBlock = getLightValue(dataPoint);
|
||||
int red = Math.min(getRed(dataPoint) + lightBlock*8, 255);
|
||||
int green = Math.min(getGreen(dataPoint) + lightBlock*8, 255);
|
||||
int blue = Math.min(getBlue(dataPoint) + lightBlock*4, 255);
|
||||
return ColorUtil.rgbToInt(red,green,blue);
|
||||
}
|
||||
|
||||
@@ -176,6 +178,7 @@ public class DataPointUtil
|
||||
tempBlue += DataPointUtil.getBlue(data);
|
||||
tempHeight += DataPointUtil.getHeight(data);
|
||||
tempDepth += DataPointUtil.getDepth(data);
|
||||
tempLight += DataPointUtil.getLightValue(data);
|
||||
} else
|
||||
{
|
||||
// void children have the default height (most likely -1)
|
||||
|
||||
Reference in New Issue
Block a user