Add generic object materials

This commit is contained in:
James Seibel
2024-07-11 18:12:58 -05:00
parent 17aa85ad24
commit e9d254f8c4
7 changed files with 70 additions and 17 deletions
@@ -1,11 +1,25 @@
package com.seibel.distanthorizons.api.enums.rendering;
/**
* contains the indices used by Iris to determine how different block types should be rendered
* contains the indices used by shaders to determine
* how different block types should be rendered. <br><br>
*
* USE_OPTIFINE_FOG_SETTING, <br>
* FOG_ENABLED, <br>
* FOG_DISABLED <br>
* UNKOWN, <br>
* LEAVES, <br>
* STONE, <br>
* WOOD, <br>
* METAL, <br>
* DIRT, <br>
* LAVA, <br>
* DEEPSLATE, <br>
* SNOW, <br>
* SAND, <br>
* TERRACOTTA, <br>
* NETHER_STONE, <br>
* WATER, <br>
* GRASS, <br>
* AIR, <br>
* ILLUMINATED, <br>
*
* @author James Seibel
* @since API 3.0.0
@@ -1,6 +1,7 @@
package com.seibel.distanthorizons.api.objects.render;
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
@@ -22,6 +23,7 @@ public class DhApiRenderableBox
public DhApiVec3d maxPos;
public Color color;
public byte material;
@@ -29,20 +31,21 @@ public class DhApiRenderableBox
// constructors //
//==============//
public DhApiRenderableBox(DhApiVec3d minPos, float width, Color color)
public DhApiRenderableBox(DhApiVec3d minPos, float width, Color color, EDhApiBlockMaterial material)
{
this(minPos, new DhApiVec3d(
minPos.x + width,
minPos.y + width,
minPos.z + width
), color);
), color, material);
}
public DhApiRenderableBox(DhApiVec3d minPos, DhApiVec3d maxPos, Color color)
public DhApiRenderableBox(DhApiVec3d minPos, DhApiVec3d maxPos, Color color, EDhApiBlockMaterial material)
{
this.minPos = minPos;
this.maxPos = maxPos;
this.color = color;
this.material = material.index;
}
}
@@ -19,6 +19,7 @@
package com.seibel.distanthorizons.core.render.renderer.generic;
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
@@ -186,7 +187,8 @@ public class BeaconRenderHandler
DhApiRenderableBox beaconBox = new DhApiRenderableBox(
new DhApiVec3d(beacon.pos.x, beacon.pos.y+1, beacon.pos.z),
new DhApiVec3d(beacon.pos.x+1, BEAM_TOP_Y, beacon.pos.z+1),
beacon.color
beacon.color,
EDhApiBlockMaterial.ILLUMINATED
);
this.beaconBoxGroup.add(beaconBox);
@@ -19,6 +19,7 @@
package com.seibel.distanthorizons.core.render.renderer.generic;
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
import com.seibel.distanthorizons.api.objects.math.DhApiVec3d;
import com.seibel.distanthorizons.api.objects.math.DhApiVec3f;
@@ -208,7 +209,8 @@ public class CloudRenderHandler
DhApiRenderableBox box = new DhApiRenderableBox(
new DhApiVec3d(minXBlockPos, 0, minZBlockPos),
new DhApiVec3d(maxXBlockPos, CLOUD_BOX_THICKNESS, maxZBlockPos),
color
color,
EDhApiBlockMaterial.UNKOWN
);
boxList.add(box);
}
@@ -21,6 +21,7 @@ package com.seibel.distanthorizons.core.render.renderer.generic;
import com.seibel.distanthorizons.api.enums.config.EDhApiGpuUploadMethod;
import com.seibel.distanthorizons.api.enums.config.EDhApiLoggerMode;
import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial;
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiGenericObjectShaderProgram;
import com.seibel.distanthorizons.api.interfaces.render.IDhApiRenderableBoxGroup;
import com.seibel.distanthorizons.api.interfaces.render.IDhApiCustomRenderRegister;
@@ -221,7 +222,8 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister
ModInfo.NAME + ":CyanChunkBox",
new DhApiRenderableBox(
new DhApiVec3d(0,0,0), new DhApiVec3d(16,190,16),
new Color(Color.CYAN.getRed(), Color.CYAN.getGreen(), Color.CYAN.getBlue(), 125))
new Color(Color.CYAN.getRed(), Color.CYAN.getGreen(), Color.CYAN.getBlue(), 125),
EDhApiBlockMaterial.WATER)
);
singleGiantBoxGroup.setSkyLight(LodUtil.MAX_MC_LIGHT);
singleGiantBoxGroup.setBlockLight(LodUtil.MAX_MC_LIGHT);
@@ -233,7 +235,8 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister
ModInfo.NAME + ":GreenBeacon",
new DhApiRenderableBox(
new DhApiVec3d(16,0,31), new DhApiVec3d(17,2000,32),
new Color(Color.GREEN.getRed(), Color.GREEN.getGreen(), Color.GREEN.getBlue(), 125))
new Color(Color.GREEN.getRed(), Color.GREEN.getGreen(), Color.GREEN.getBlue(), 125),
EDhApiBlockMaterial.ILLUMINATED)
);
singleTallBoxGroup.setSkyLight(LodUtil.MAX_MC_LIGHT);
singleTallBoxGroup.setBlockLight(LodUtil.MAX_MC_LIGHT);
@@ -246,7 +249,10 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister
{
absBoxList.add(new DhApiRenderableBox(
new DhApiVec3d(i,150+i,24), new DhApiVec3d(1+i,151+i,25),
new Color(Color.ORANGE.getRed(), Color.ORANGE.getGreen(), Color.ORANGE.getBlue())));
new Color(Color.ORANGE.getRed(), Color.ORANGE.getGreen(), Color.ORANGE.getBlue()),
EDhApiBlockMaterial.LAVA
)
);
}
IDhApiRenderableBoxGroup absolutePosBoxGroup = factory.createAbsolutePositionedGroup(ModInfo.NAME + ":OrangeStairs", absBoxList);
this.add(absolutePosBoxGroup);
@@ -258,7 +264,10 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister
{
relBoxList.add(new DhApiRenderableBox(
new DhApiVec3d(0,i,0), new DhApiVec3d(1,1+i,1),
new Color(Color.MAGENTA.getRed(), Color.MAGENTA.getGreen(), Color.MAGENTA.getBlue())));
new Color(Color.MAGENTA.getRed(), Color.MAGENTA.getGreen(), Color.MAGENTA.getBlue()),
EDhApiBlockMaterial.METAL
)
);
}
IDhApiRenderableBoxGroup relativePosBoxGroup = factory.createRelativePositionedGroup(
ModInfo.NAME + ":MovingMagentaGroup",
@@ -282,7 +291,10 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister
{
massRelBoxList.add(new DhApiRenderableBox(
new DhApiVec3d(-x, 0, -z), new DhApiVec3d(1-x, 1, 1-z),
new Color(Color.RED.getRed(), Color.RED.getGreen(), Color.RED.getBlue())));
new Color(Color.RED.getRed(), Color.RED.getGreen(), Color.RED.getBlue()),
EDhApiBlockMaterial.TERRACOTTA
)
);
}
}
IDhApiRenderableBoxGroup massRelativePosBoxGroup = factory.createRelativePositionedGroup(
@@ -474,6 +486,11 @@ public class GenericObjectRenderer implements IDhApiCustomRenderRegister
this.vertexAttribDivisor(4, 1);
GL32.glVertexAttribPointer(4, 3, GL32.GL_FLOAT, false, 3 * Float.BYTES, 0);
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, boxGroup.instanceMaterialVbo);
GL32.glEnableVertexAttribArray(5);
this.vertexAttribDivisor(5, 1);
GL32.glVertexAttribIPointer(5, 1, GL32.GL_BYTE, Byte.BYTES, 0);
// Draw instanced
if (boxGroup.uploadedBoxCount > 0)
@@ -55,6 +55,7 @@ public class RenderableBoxGroup
// instance data
public int instanceColorVbo = 0;
public int instanceMaterialVbo = 0;
public int instanceScaleVbo = 0;
public int instanceChunkPosVbo = 0;
public int instanceSubChunkPosVbo = 0;
@@ -236,14 +237,15 @@ public class RenderableBoxGroup
this.instanceSubChunkPosVbo = GL32.glGenBuffers();
this.instanceScaleVbo = GL32.glGenBuffers();
this.instanceColorVbo = GL32.glGenBuffers();
this.instanceMaterialVbo = GL32.glGenBuffers();
}
int boxCount = this.size();
this.uploadedBoxCount = boxCount;
// transformation / scaling //
// transformation / scaling //
int[] chunkPosData = new int[boxCount * 3];
float[] subChunkPosData = new float[boxCount * 3];
float[] scalingData = new float[boxCount * 3];
@@ -268,9 +270,9 @@ public class RenderableBoxGroup
}
// colors //
// colors/materials //
float[] colorData = new float[boxCount * 4];
byte[] materialData = new byte[boxCount];
for (int i = 0; i < boxCount; i++)
{
DhApiRenderableBox box = this.get(i);
@@ -280,6 +282,8 @@ public class RenderableBoxGroup
colorData[colorIndex + 1] = color.getGreen() / 255.0f;
colorData[colorIndex + 2] = color.getBlue() / 255.0f;
colorData[colorIndex + 3] = color.getAlpha() / 255.0f;
materialData[i] = box.material;
}
@@ -294,6 +298,10 @@ public class RenderableBoxGroup
// Upload colors
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, this.instanceColorVbo);
GL32.glBufferData(GL32.GL_ARRAY_BUFFER, colorData, GL32.GL_DYNAMIC_DRAW);
// Upload materials
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, this.instanceMaterialVbo);
GL32.glBufferData(GL32.GL_ARRAY_BUFFER, colorData, GL32.GL_DYNAMIC_DRAW);
}
@@ -333,6 +341,12 @@ public class RenderableBoxGroup
GL32.glDeleteBuffers(this.instanceColorVbo);
this.instanceColorVbo = 0;
}
if (this.instanceMaterialVbo != 0)
{
GL32.glDeleteBuffers(this.instanceMaterialVbo);
this.instanceMaterialVbo = 0;
}
});
}
@@ -4,6 +4,7 @@ layout (location = 1) in vec4 aColor;
layout (location = 2) in vec3 aScale;
layout (location = 3) in ivec3 aTranslateChunk;
layout (location = 4) in vec3 aTranslateSubChunk;
layout (location = 5) in int aMaterial;
uniform ivec3 uOffsetChunk;
uniform vec3 uOffsetSubChunk;