Add multiple color modes and set up for geometry quality

This commit is contained in:
James Seibel
2021-05-08 16:41:55 -05:00
parent ae9144a6c4
commit 815b00c3ca
7 changed files with 149 additions and 99 deletions
@@ -199,7 +199,7 @@ public class LodBufferBuilder
// get the desired LodTemplate and
// add this LOD to the buffer
LodConfig.CLIENT.lodTemplateMode.get().template.
LodConfig.CLIENT.lodTemplate.get().template.
addLodToBuffer(currentBuffer, lodDim, lod,
xOffset, yOffset, zOffset, renderer.debugging);
}
@@ -6,6 +6,7 @@ import com.backsun.lod.enums.ColorDirection;
import com.backsun.lod.enums.LodCorner;
import com.backsun.lod.objects.LodChunk;
import com.backsun.lod.objects.LodDimension;
import com.backsun.lod.util.LodConfig;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.util.math.AxisAlignedBB;
@@ -31,108 +32,99 @@ public class CubicLodTemplate extends AbstractLodTemplate
double xOffset, double yOffset, double zOffset,
boolean debugging)
{
// add the new box to the array
int topPoint = getValidHeightPoint(lod.top);
int bottomPoint = getValidHeightPoint(lod.bottom);
// don't draw an LOD if it is empty
// don't add an LOD if it is empty
if (topPoint == -1 && bottomPoint == -1)
return;
Color c = null;
if (!debugging)
if (bottomPoint == topPoint)
{
// add the color to the array
c = lod.colors[ColorDirection.TOP.value];
// if the top and bottom points are at the same height
// render this LOD as 1 block thick
topPoint++;
}
else
Color[] c = new Color[ColorDirection.values().length];
// generate the color for this LOD
if (debugging)
{
// if debugging draw the squares as a black and white checker board
if ((lod.x + lod.z) % 2 == 0)
c = debugWhite;
for(ColorDirection dir : ColorDirection.values())
// have each direction be the same
// color if debugging
c[dir.value] = debugWhite;
else
c = debugBlack;
}
AxisAlignedBB bb = new AxisAlignedBB(0, bottomPoint, 0, LodChunk.WIDTH, topPoint, LodChunk.WIDTH).offset(xOffset, yOffset, zOffset);
if (bb.minY != bb.maxY)
{
// top (facing up)
addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
// bottom (facing down)
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
// south (facing -Z)
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
// north (facing +Z)
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
// west (facing -X)
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
// east (facing +X)
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
for(ColorDirection dir : ColorDirection.values())
c[dir.value] = debugBlack;
}
else
{
// render this LOD as one block thick
// top (facing up)
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
// bottom (facing down)
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
// south (facing -Z)
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
// north (facing +Z)
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
// west (facing -X)
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY+1, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
// east (facing +X)
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY+1, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
switch (LodConfig.CLIENT.lodColorStyle.get())
{
case TOP:
// only add the top's color to the array
for(ColorDirection dir : ColorDirection.values())
c[dir.value] = lod.colors[ColorDirection.TOP.value];
break;
case INDIVIDUAL_SIDES:
// add each direction's color to the array
for(ColorDirection dir : ColorDirection.values())
c[dir.value] = lod.colors[dir.value];
break;
}
}
// TODO add different geometry quality levels
AxisAlignedBB bb = new AxisAlignedBB(0, bottomPoint, 0, LodChunk.WIDTH, topPoint, LodChunk.WIDTH).offset(xOffset, yOffset, zOffset);
// top (facing up)
addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, c[ColorDirection.TOP.value].getRed(), c[ColorDirection.TOP.value].getGreen(), c[ColorDirection.TOP.value].getBlue(), c[ColorDirection.TOP.value].getAlpha());
addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, c[ColorDirection.TOP.value].getRed(), c[ColorDirection.TOP.value].getGreen(), c[ColorDirection.TOP.value].getBlue(), c[ColorDirection.TOP.value].getAlpha());
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, c[ColorDirection.TOP.value].getRed(), c[ColorDirection.TOP.value].getGreen(), c[ColorDirection.TOP.value].getBlue(), c[ColorDirection.TOP.value].getAlpha());
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, c[ColorDirection.TOP.value].getRed(), c[ColorDirection.TOP.value].getGreen(), c[ColorDirection.TOP.value].getBlue(), c[ColorDirection.TOP.value].getAlpha());
// bottom (facing down)
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, c[ColorDirection.BOTTOM.value].getRed(), c[ColorDirection.BOTTOM.value].getGreen(), c[ColorDirection.BOTTOM.value].getBlue(), c[ColorDirection.BOTTOM.value].getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, c[ColorDirection.BOTTOM.value].getRed(), c[ColorDirection.BOTTOM.value].getGreen(), c[ColorDirection.BOTTOM.value].getBlue(), c[ColorDirection.BOTTOM.value].getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, c[ColorDirection.BOTTOM.value].getRed(), c[ColorDirection.BOTTOM.value].getGreen(), c[ColorDirection.BOTTOM.value].getBlue(), c[ColorDirection.BOTTOM.value].getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, c[ColorDirection.BOTTOM.value].getRed(), c[ColorDirection.BOTTOM.value].getGreen(), c[ColorDirection.BOTTOM.value].getBlue(), c[ColorDirection.BOTTOM.value].getAlpha());
// south (facing -Z)
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, c[ColorDirection.S.value].getRed(), c[ColorDirection.S.value].getGreen(), c[ColorDirection.S.value].getBlue(), c[ColorDirection.S.value].getAlpha());
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, c[ColorDirection.S.value].getRed(), c[ColorDirection.S.value].getGreen(), c[ColorDirection.S.value].getBlue(), c[ColorDirection.S.value].getAlpha());
addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, c[ColorDirection.S.value].getRed(), c[ColorDirection.S.value].getGreen(), c[ColorDirection.S.value].getBlue(), c[ColorDirection.S.value].getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, c[ColorDirection.S.value].getRed(), c[ColorDirection.S.value].getGreen(), c[ColorDirection.S.value].getBlue(), c[ColorDirection.S.value].getAlpha());
// north (facing +Z)
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, c[ColorDirection.N.value].getRed(), c[ColorDirection.N.value].getGreen(), c[ColorDirection.N.value].getBlue(), c[ColorDirection.N.value].getAlpha());
addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, c[ColorDirection.N.value].getRed(), c[ColorDirection.N.value].getGreen(), c[ColorDirection.N.value].getBlue(), c[ColorDirection.N.value].getAlpha());
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, c[ColorDirection.N.value].getRed(), c[ColorDirection.N.value].getGreen(), c[ColorDirection.N.value].getBlue(), c[ColorDirection.N.value].getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, c[ColorDirection.N.value].getRed(), c[ColorDirection.N.value].getGreen(), c[ColorDirection.N.value].getBlue(), c[ColorDirection.N.value].getAlpha());
// west (facing -X)
addPosAndColor(buffer, bb.minX, bb.minY, bb.minZ, c[ColorDirection.W.value].getRed(), c[ColorDirection.W.value].getGreen(), c[ColorDirection.W.value].getBlue(), c[ColorDirection.W.value].getAlpha());
addPosAndColor(buffer, bb.minX, bb.minY, bb.maxZ, c[ColorDirection.W.value].getRed(), c[ColorDirection.W.value].getGreen(), c[ColorDirection.W.value].getBlue(), c[ColorDirection.W.value].getAlpha());
addPosAndColor(buffer, bb.minX, bb.maxY, bb.maxZ, c[ColorDirection.W.value].getRed(), c[ColorDirection.W.value].getGreen(), c[ColorDirection.W.value].getBlue(), c[ColorDirection.W.value].getAlpha());
addPosAndColor(buffer, bb.minX, bb.maxY, bb.minZ, c[ColorDirection.W.value].getRed(), c[ColorDirection.W.value].getGreen(), c[ColorDirection.W.value].getBlue(), c[ColorDirection.W.value].getAlpha());
// east (facing +X)
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.minZ, c[ColorDirection.E.value].getRed(), c[ColorDirection.E.value].getGreen(), c[ColorDirection.E.value].getBlue(), c[ColorDirection.E.value].getAlpha());
addPosAndColor(buffer, bb.maxX, bb.maxY, bb.maxZ, c[ColorDirection.E.value].getRed(), c[ColorDirection.E.value].getGreen(), c[ColorDirection.E.value].getBlue(), c[ColorDirection.E.value].getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY, bb.maxZ, c[ColorDirection.E.value].getRed(), c[ColorDirection.E.value].getGreen(), c[ColorDirection.E.value].getBlue(), c[ColorDirection.E.value].getAlpha());
addPosAndColor(buffer, bb.maxX, bb.minY, bb.minZ, c[ColorDirection.E.value].getRed(), c[ColorDirection.E.value].getGreen(), c[ColorDirection.E.value].getBlue(), c[ColorDirection.E.value].getAlpha());
}
/**
* @Returns -1 if there are no valid points
*/
@@ -0,0 +1,18 @@
package com.backsun.lod.enums;
/**
* top, individual_sides
*
* @author James Seibel
* @version 05-08-2021
*/
public enum LodColorStyle
{
/** Use the color from the top of the LOD chunk
* for all sides */
TOP,
/** For each side of the LOD use the color corresponding
* to that side */
INDIVIDUAL_SIDES;
}
@@ -0,0 +1,19 @@
package com.backsun.lod.enums;
/**
* low, medium, high
*
* @author James Seibel
* @version 05-08-2021
*/
public enum LodGeometryQuality
{
/** render 1 LOD for each chunk */
SINGLE,
/** render 4 LODs for each near chunk and 1 LOD for each far chunk */
SINGLE_CLOSE_QUAD_FAR,
/** render 4 LODs for each chunk */
QUAD;
}
@@ -11,7 +11,7 @@ import com.backsun.lod.builders.lodTemplates.TriangularLodTemplate;
* @author James Seibel
* @version 05-07-2021
*/
public enum LodTemplateMode
public enum LodTemplate
{
// used for position
@@ -31,7 +31,7 @@ public enum LodTemplateMode
public final AbstractLodTemplate template;
private LodTemplateMode(AbstractLodTemplate newTemplate)
private LodTemplate(AbstractLodTemplate newTemplate)
{
template = newTemplate;
}
@@ -160,15 +160,16 @@ public class LodRenderer
// the dimension is the same
}
if (LodConfig.CLIENT.drawCheckerBoard.get())
// TODO simplify this logic?
if (LodConfig.CLIENT.debugMode.get())
{
if (debugging != LodConfig.CLIENT.drawCheckerBoard.get())
if (debugging != LodConfig.CLIENT.debugMode.get())
regen = true;
debugging = true;
}
else
{
if (debugging != LodConfig.CLIENT.drawCheckerBoard.get())
if (debugging != LodConfig.CLIENT.debugMode.get())
regen = true;
debugging = false;
}
@@ -8,7 +8,9 @@ import org.apache.logging.log4j.LogManager;
import com.backsun.lod.ModInfo;
import com.backsun.lod.enums.FogDistance;
import com.backsun.lod.enums.LodTemplateMode;
import com.backsun.lod.enums.LodColorStyle;
import com.backsun.lod.enums.LodGeometryQuality;
import com.backsun.lod.enums.LodTemplate;
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.electronwill.nightconfig.core.io.WritingMode;
@@ -31,10 +33,13 @@ public class LodConfig
public ForgeConfigSpec.EnumValue<FogDistance> fogDistance;
public ForgeConfigSpec.BooleanValue drawCheckerBoard;
public ForgeConfigSpec.BooleanValue debugMode;
public ForgeConfigSpec.EnumValue<LodTemplateMode> lodTemplateMode;
public ForgeConfigSpec.EnumValue<LodTemplate> lodTemplate;
public ForgeConfigSpec.EnumValue<LodGeometryQuality> lodGeometryQuality;
public ForgeConfigSpec.EnumValue<LodColorStyle> lodColorStyle;
Client(ForgeConfigSpec.Builder builder)
{
@@ -49,11 +54,11 @@ public class LodConfig
fogDistance = builder
.comment("\n"
+ " At what distance should Fog be drawn on the LODs? \n"
+ " If fog cuts off ubruptly or you are using Optifine's \"fast\" \n"
+ " If the fog cuts off ubruptly or you are using Optifine's \"fast\" \n"
+ " fog option set this to " + FogDistance.NEAR.toString() + " or " + FogDistance.FAR.toString() + ".")
.defineEnum("fogDistance", FogDistance.NEAR_AND_FAR);
drawCheckerBoard = builder
debugMode = builder
.comment("\n"
+ " If false the LODs will draw with their normal world colors. \n"
+ " If true they will draw as a black and white checkerboard. \n"
@@ -61,13 +66,28 @@ public class LodConfig
+ " giant game of chess ;)")
.define("drawCheckerBoard", false);
lodTemplateMode = builder
lodTemplate = builder
.comment("\n"
+ " How should the LODs be drawn? \n"
+ " " + LodTemplateMode.CUBIC.toString() + ": LOD Chunks are drawn as rectangular prisms (boxes). \n"
+ " " + LodTemplateMode.TRIANGULAR.toString() + ": LOD Chunks smoothly transition between other. \n"
+ " " + LodTemplateMode.DYNAMIC.toString() + ": LOD Chunks smoothly transition between other, unless a neighboring chunk is at a significantly different height. ")
.defineEnum("lodDrawMode", LodTemplateMode.CUBIC);
+ " " + LodTemplate.CUBIC.toString() + ": LOD Chunks are drawn as rectangular prisms (boxes). \n"
+ " " + LodTemplate.TRIANGULAR.toString() + ": LOD Chunks smoothly transition between other. \n"
+ " " + LodTemplate.DYNAMIC.toString() + ": LOD Chunks smoothly transition between other, unless a neighboring chunk is at a significantly different height. ")
.defineEnum("lodTemplate", LodTemplate.CUBIC);
lodGeometryQuality = builder
.comment("\n"
+ " How detailed should the LODs be? \n"
+ " " + LodGeometryQuality.SINGLE.toString() + ": render 1 LOD for each Chunk. \n"
+ " " + LodGeometryQuality.SINGLE_CLOSE_QUAD_FAR.toString() + ": render 4 LODs for each near chunk and 1 LOD for each far chunk. \n"
+ " " + LodGeometryQuality.QUAD.toString() + ": render 4 LODs for each Chunk. ")
.defineEnum("lodGeometryQuality", LodGeometryQuality.SINGLE);
lodColorStyle = builder
.comment("\n"
+ " How should the LODs be colored? \n"
+ " " + LodColorStyle.TOP.toString() + ": Use the color from the top of the LOD chunk for all sides. \n"
+ " " + LodColorStyle.INDIVIDUAL_SIDES.toString() + ": For each side of the LOD use the color correspondingto that side. ")
.defineEnum("lodColorStyle", LodColorStyle.TOP);
builder.pop();
}