aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/render
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/util/render')
-rw-r--r--src/main/kotlin/util/render/CustomRenderLayers.kt1
-rw-r--r--src/main/kotlin/util/render/RenderInWorldContext.kt115
2 files changed, 81 insertions, 35 deletions
diff --git a/src/main/kotlin/util/render/CustomRenderLayers.kt b/src/main/kotlin/util/render/CustomRenderLayers.kt
index f713a81..2da1de7 100644
--- a/src/main/kotlin/util/render/CustomRenderLayers.kt
+++ b/src/main/kotlin/util/render/CustomRenderLayers.kt
@@ -88,6 +88,7 @@ object CustomRenderLayers {
val COLORED_QUADS = RenderLayer.of(
"firmament_quads",
RenderLayer.DEFAULT_BUFFER_SIZE,
+ false, true,
CustomRenderPipelines.COLORED_OMNIPRESENT_QUADS,
RenderLayer.MultiPhaseParameters.builder()
.lightmap(RenderPhase.DISABLE_LIGHTMAP)
diff --git a/src/main/kotlin/util/render/RenderInWorldContext.kt b/src/main/kotlin/util/render/RenderInWorldContext.kt
index 4963920..c30ee19 100644
--- a/src/main/kotlin/util/render/RenderInWorldContext.kt
+++ b/src/main/kotlin/util/render/RenderInWorldContext.kt
@@ -11,7 +11,6 @@ import net.minecraft.client.render.RenderLayer
import net.minecraft.client.render.RenderTickCounter
import net.minecraft.client.render.VertexConsumer
import net.minecraft.client.render.VertexConsumerProvider
-import net.minecraft.client.render.VertexFormats
import net.minecraft.client.texture.Sprite
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.text.Text
@@ -20,7 +19,6 @@ import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Vec3d
import moe.nea.firmament.events.WorldRenderLastEvent
import moe.nea.firmament.util.FirmFormatters
-import moe.nea.firmament.util.IntUtil.toRGBA
import moe.nea.firmament.util.MC
@RenderContextDSL
@@ -49,6 +47,38 @@ class RenderInWorldContext private constructor(
matrixStack.pop()
}
+ fun sharedVoxelSurface(blocks: Set<BlockPos>, color: Int) {
+ val m = BlockPos.Mutable()
+ val l = vertexConsumers.getBuffer(CustomRenderLayers.COLORED_QUADS)
+ blocks.forEach {
+ matrixStack.push()
+ matrixStack.translate(it.x.toFloat(), it.y.toFloat(), it.z.toFloat())
+ val p = matrixStack.peek().positionMatrix
+ m.set(it)
+ if (m.setX(it.x + 1) !in blocks) {
+ buildFaceXP(p, l, color)
+ }
+ if (m.setX(it.x - 1) !in blocks) {
+ buildFaceXN(p, l, color)
+ }
+ m.set(it)
+ if (m.setY(it.y + 1) !in blocks) {
+ buildFaceYP(p, l, color)
+ }
+ if (m.setY(it.y - 1) !in blocks) {
+ buildFaceYN(p, l, color)
+ }
+ m.set(it)
+ if (m.setZ(it.z + 1) !in blocks) {
+ buildFaceZP(p, l, color)
+ }
+ if (m.setZ(it.z - 1) !in blocks) {
+ buildFaceZN(p, l, color)
+ }
+ matrixStack.pop()
+ }
+ }
+
enum class VerticalAlign {
TOP, BOTTOM, CENTER;
@@ -205,41 +235,56 @@ class RenderInWorldContext private constructor(
}
}
- private fun buildCube(matrix: Matrix4f, buf: VertexConsumer, colorInt: Int) {
- val (r, g, b, a) = colorInt.toRGBA()
-
- // Y-
- buf.vertex(matrix, 0F, 0F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 0F, 0F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 0F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 0F, 0F).color(r, g, b, a)
- // Y+
- buf.vertex(matrix, 0F, 1F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 1F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 1F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 0F, 1F, 1F).color(r, g, b, a)
- // X-
- buf.vertex(matrix, 0F, 0F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 0F, 0F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 0F, 1F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 0F, 1F, 0F).color(r, g, b, a)
- // X+
- buf.vertex(matrix, 1F, 0F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 1F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 1F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 0F, 1F).color(r, g, b, a)
- // Z-
- buf.vertex(matrix, 0F, 0F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 0F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 1F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 0F, 1F, 0F).color(r, g, b, a)
- // Z+
- buf.vertex(matrix, 0F, 0F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 0F, 1F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 1F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 0F, 1F).color(r, g, b, a)
+ private fun buildFaceZP(matrix: Matrix4f, buf: VertexConsumer, rgba: Int) {
+ buf.vertex(matrix, 0F, 0F, 1F).color(rgba)
+ buf.vertex(matrix, 0F, 1F, 1F).color(rgba)
+ buf.vertex(matrix, 1F, 1F, 1F).color(rgba)
+ buf.vertex(matrix, 1F, 0F, 1F).color(rgba)
+ }
+
+ private fun buildFaceZN(matrix: Matrix4f, buf: VertexConsumer, rgba: Int) {
+ buf.vertex(matrix, 0F, 0F, 0F).color(rgba)
+ buf.vertex(matrix, 1F, 0F, 0F).color(rgba)
+ buf.vertex(matrix, 1F, 1F, 0F).color(rgba)
+ buf.vertex(matrix, 0F, 1F, 0F).color(rgba)
+ }
+
+ private fun buildFaceXP(matrix: Matrix4f, buf: VertexConsumer, rgba: Int) {
+ buf.vertex(matrix, 1F, 0F, 0F).color(rgba)
+ buf.vertex(matrix, 1F, 1F, 0F).color(rgba)
+ buf.vertex(matrix, 1F, 1F, 1F).color(rgba)
+ buf.vertex(matrix, 1F, 0F, 1F).color(rgba)
+ }
+
+ private fun buildFaceXN(matrix: Matrix4f, buf: VertexConsumer, rgba: Int) {
+ buf.vertex(matrix, 0F, 0F, 0F).color(rgba)
+ buf.vertex(matrix, 0F, 0F, 1F).color(rgba)
+ buf.vertex(matrix, 0F, 1F, 1F).color(rgba)
+ buf.vertex(matrix, 0F, 1F, 0F).color(rgba)
}
+ private fun buildFaceYN(matrix: Matrix4f, buf: VertexConsumer, rgba: Int) {
+ buf.vertex(matrix, 0F, 0F, 0F).color(rgba)
+ buf.vertex(matrix, 0F, 0F, 1F).color(rgba)
+ buf.vertex(matrix, 1F, 0F, 1F).color(rgba)
+ buf.vertex(matrix, 1F, 0F, 0F).color(rgba)
+ }
+
+ private fun buildFaceYP(matrix: Matrix4f, buf: VertexConsumer, rgba: Int) {
+ buf.vertex(matrix, 0F, 1F, 0F).color(rgba)
+ buf.vertex(matrix, 1F, 1F, 0F).color(rgba)
+ buf.vertex(matrix, 1F, 1F, 1F).color(rgba)
+ buf.vertex(matrix, 0F, 1F, 1F).color(rgba)
+ }
+
+ private fun buildCube(matrix4f: Matrix4f, buf: VertexConsumer, rgba: Int) {
+ buildFaceXP(matrix4f, buf, rgba)
+ buildFaceXN(matrix4f, buf, rgba)
+ buildFaceYP(matrix4f, buf, rgba)
+ buildFaceYN(matrix4f, buf, rgba)
+ buildFaceZP(matrix4f, buf, rgba)
+ buildFaceZN(matrix4f, buf, rgba)
+ }
fun renderInWorld(event: WorldRenderLastEvent, block: RenderInWorldContext. () -> Unit) {
// TODO: there should be *no more global state*. the only thing we should be doing is render layers. that includes settings like culling, blending, shader color, and depth testing