Got Rift rendering to work correctly. Still needs alot of work.

This commit is contained in:
Waterpicker 2020-09-05 17:18:22 -05:00
parent dcf649674c
commit ab2681bc35
4 changed files with 21 additions and 17 deletions

View file

@ -1,6 +1,7 @@
package org.dimdev.dimdoors.client;
import com.flowpowered.math.TrigMath;
import net.minecraft.util.math.Matrix4f;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.block.entity.DetachedRiftBlockEntity;
import org.dimdev.dimdoors.client.tesseract.Tesseract;
@ -32,6 +33,8 @@ public class DetachedRiftBlockEntityRenderer extends BlockEntityRenderer<Detache
@Override
public void render(DetachedRiftBlockEntity rift, float tickDelta, MatrixStack matrices, VertexConsumerProvider vcs, int breakProgress, int alpha) {
Matrix4f model = matrices.peek().getModel();
if (ModConfig.GRAPHICS.showRiftCore) {
renderTesseract(vcs.getBuffer(MyRenderLayer.TESSERACT), rift, matrices, tickDelta);
} else {
@ -41,17 +44,17 @@ public class DetachedRiftBlockEntityRenderer extends BlockEntityRenderer<Detache
}
}
renderCrack(vcs.getBuffer(RenderLayer.getLightning()), matrices, rift);
renderCrack(vcs.getBuffer(MyRenderLayer.CRACK), matrices, rift);
}
private void renderCrack(VertexConsumer vc, MatrixStack matrices, DetachedRiftBlockEntity rift) {
matrices.push();
matrices.translate(0.5, 0.5, 0.5);
RiftCrackRenderer.drawCrack(vc, 0, CURVE, ModConfig.GRAPHICS.riftSize * rift.size, 0xF1234568L * rift.getPos().hashCode());
RiftCrackRenderer.drawCrack(matrices.peek().getModel(), vc, 0, CURVE, ModConfig.GRAPHICS.riftSize * rift.size, 0xF1234568L * rift.getPos().hashCode());
matrices.pop();
}
private void renderTesseract(VertexConsumer vc, DetachedRiftBlockEntity rift, MatrixStack matrices, float tickDelta) {
private void renderTesseract( VertexConsumer vc, DetachedRiftBlockEntity rift, MatrixStack matrices, float tickDelta) {
double radian = nextAngle(rift, tickDelta) * TrigMath.DEG_TO_RAD;
RGBA color = rift.getColor();
if (color == null) color = COLOR;
@ -61,7 +64,7 @@ public class DetachedRiftBlockEntityRenderer extends BlockEntityRenderer<Detache
matrices.translate(0.5, 0.5, 0.5);
matrices.scale(0.25f, 0.25f, 0.25f);
TESSERACT.draw(vc, color, radian);
TESSERACT.draw(matrices.peek().getModel(), vc, color, radian);
matrices.pop();
}

View file

@ -1,5 +1,6 @@
package org.dimdev.dimdoors.client;
import net.minecraft.util.math.Matrix4f;
import org.dimdev.dimdoors.ModConfig;
import net.minecraft.client.render.VertexConsumer;
@ -9,7 +10,7 @@ import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT)
public final class RiftCrackRenderer {
public static void drawCrack(VertexConsumer vc, float riftRotation, RiftCurves.PolygonInfo poly, double size, long riftRandom) {
public static void drawCrack(Matrix4f model, VertexConsumer vc, float riftRotation, RiftCurves.PolygonInfo poly, double size, long riftRandom) {
// Calculate the proper size for the rift render
double scale = size / (poly.maxX - poly.minX);
@ -55,7 +56,7 @@ public final class RiftCrackRenderer {
y *= scale;
z *= scale;
vc.vertex(x,y,z).color(0.08f, 0.08f, 0.08f, .3f).next();
vc.vertex(model, (float) x, (float) y, (float) z).color(0.08f, 0.08f, 0.08f, .3f).next();
}
}
}

View file

@ -17,20 +17,19 @@ public class Plane {
vectors = new Vector4f[]{vec1, vec2, vec3, vec4};
}
public void draw(VertexConsumer vc, RGBA color, double radian) {
drawVertex(vc, rotYW(vectors[0], radian), 0, 0, color);
drawVertex(vc, rotYW(vectors[1], radian), 0, 1, color);
drawVertex(vc, rotYW(vectors[2], radian), 1, 1, color);
drawVertex(vc, rotYW(vectors[3], radian), 1, 0, color);
public void draw(net.minecraft.util.math.Matrix4f model, VertexConsumer vc, RGBA color, double radian) {
drawVertex(model, vc, rotYW(vectors[0], radian), 0, 0, color);
drawVertex(model, vc, rotYW(vectors[1], radian), 0, 1, color);
drawVertex(model, vc, rotYW(vectors[2], radian), 1, 1, color);
drawVertex(model, vc, rotYW(vectors[3], radian), 1, 0, color);
}
private static void drawVertex(VertexConsumer vc, Vector4f vector, int u, int v, RGBA color) {
private static void drawVertex(net.minecraft.util.math.Matrix4f model, VertexConsumer vc, Vector4f vector, int u, int v, RGBA color) {
double scalar = 1d / (vector.getW() + 1);
Vector3f scaled = vector.toVector3().mul(scalar);
vc.vertex(scaled.getX(), scaled.getY(), scaled.getZ())
.texture(u, v)
vc.vertex(model, scaled.getX(), scaled.getY(), scaled.getZ())
.color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha())
.texture(u, v)
.next();
}

View file

@ -6,6 +6,7 @@ import net.minecraft.client.render.VertexConsumer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.util.math.Matrix4f;
import org.dimdev.dimdoors.util.RGBA;
public class Tesseract {
@ -182,9 +183,9 @@ public class Tesseract {
}
@Environment(EnvType.CLIENT)
public void draw(VertexConsumer vc, RGBA color, double radian) {
public void draw(Matrix4f model, VertexConsumer vc, RGBA color, double radian) {
for (Plane plane : planes) {
plane.draw(vc, color, radian);
plane.draw(model, vc, color, radian);
}
}
}