Lots of fixes

This commit is contained in:
Sebastian Hartte
2020-07-23 02:38:32 +02:00
parent 1933b4b10d
commit 9fcfbf31be
100 changed files with 1771 additions and 1866 deletions
@@ -0,0 +1,118 @@
/*
* This file is part of CodeChickenLib.
* Copyright (c) 2018, covers1624, All rights reserved.
*
* CodeChickenLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* CodeChickenLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CodeChickenLib. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.thirdparty.codechicken.lib.math;
/**
* @author covers1624
*/
public class InterpHelper {
private float[][] posCache = new float[4][2];
private float[] valCache = new float[4];
private float x0;
private float x1;
private float y0;
private float y1;
private float rX;
private float rY;
private int p00;
private int p10;
private int p11;
private int p01;
/**
* Resets the interp helper with the given quad. Does not care what order the
* vertices are in.
*/
public void reset(float dx0, float dy0, float dx1, float dy1, float dx2, float dy2, float dx3, float dy3) {
float[] vec0 = this.posCache[0];
float[] vec1 = this.posCache[1];
float[] vec2 = this.posCache[2];
float[] vec3 = this.posCache[3];
vec0[0] = dx0;
vec1[0] = dx1;
vec2[0] = dx2;
vec3[0] = dx3;
vec0[1] = dy0;
vec1[1] = dy1;
vec2[1] = dy2;
vec3[1] = dy3;
}
/**
* Call when you are ready to use the InterpHelper.
*/
public void setup() {
this.p00 = 0;// Bottom Left is always first.
this.x0 = this.posCache[this.p00][0];
this.y0 = this.posCache[this.p00][1];
for (int i = 1; i < 4; i++) {
float x = this.posCache[i][0];
float y = this.posCache[i][1];
if (this.y0 == y) {
this.p10 = i;// Bottom right.
this.x1 = x;
} else if (this.x0 == x) {
this.p01 = i;// Top left.
this.y1 = y;
} else {
// Top right.
this.p11 = i;
}
}
}
/**
* Computes the coefficients for the interpolation.
*
* @param x X interp location.
* @param y Y interp location.
*/
public void locate(float x, float y) {
this.rX = (x - this.x0) / (this.x1 - this.x0);
this.rY = (y - this.y0) / (this.y1 - this.y0);
}
/**
* Interpolates using the already computed coefficients.
*
* @param q0 Value at dx0 dy0
* @param q1 Value at dx1 dy1
* @param q2 Value at dx2 dy2
* @param q3 Value at dx3 dy3
*
* @return The result.
*/
public float interpolate(float q0, float q1, float q2, float q3) {
this.valCache[0] = q0;
this.valCache[1] = q1;
this.valCache[2] = q2;
this.valCache[3] = q3;
float f0 = (this.valCache[this.p00] * (1 - this.rX)) + (this.valCache[this.p10] * this.rX);
float f1 = (this.valCache[this.p01] * (1 - this.rX)) + (this.valCache[this.p11] * this.rX);
return (f0 * (1 - this.rY)) + (f1 * this.rY);
}
}
@@ -0,0 +1,47 @@
/*
* This file is part of CodeChickenLib.
* Copyright (c) 2018, covers1624, All rights reserved.
*
* CodeChickenLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* CodeChickenLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CodeChickenLib. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.thirdparty.codechicken.lib.model.pipeline.transformers;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
/**
* This transformer simply overrides the alpha of the quad.
*
* @author covers1624
*/
public class QuadAlphaOverride implements RenderContext.QuadTransform {
private static final int INV_ALPHA_MASK = 0x00_FF_FF_FF;
private final int alphaOverride;
public QuadAlphaOverride(float alphaOverride) {
this.alphaOverride = (int) (alphaOverride * 255) << 24;
}
@Override
public boolean transform(MutableQuadView quad) {
for (int i = 0; i < 4; i++) {
int color = (quad.spriteColor(i, 0) & INV_ALPHA_MASK) | alphaOverride;
quad.spriteColor(i, 0, color);
}
return true;
}
}
@@ -0,0 +1,107 @@
/*
* This file is part of CodeChickenLib.
* Copyright (c) 2018, covers1624, All rights reserved.
*
* CodeChickenLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* CodeChickenLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CodeChickenLib. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.thirdparty.codechicken.lib.model.pipeline.transformers;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
/**
* This transformer simply clamps the vertices inside the provided box. You
* probably want to Re-Interpolate the UV's, Color, and Lmap, see
* {@link QuadReInterpolator}
*
* @author covers1624
*/
public class QuadClamper implements RenderContext.QuadTransform {
private final Box clampBounds;
private final Vector3f pos = new Vector3f();
public QuadClamper(Box clampBounds) {
this.clampBounds = clampBounds;
}
@Override
public boolean transform(MutableQuadView quad) {
int s = quad.nominalFace().ordinal() >> 1;
clamp(quad, this.clampBounds);
// Check if the quad would be invisible and cull it.
float x1 = quad.posByIndex(0, dx(s));
float x2 = quad.posByIndex(1, dx(s));
float x3 = quad.posByIndex(2, dx(s));
float x4 = quad.posByIndex(3, dx(s));
float y1 = quad.posByIndex(0, dy(s));
float y2 = quad.posByIndex(1, dy(s));
float y3 = quad.posByIndex(2, dy(s));
float y4 = quad.posByIndex(3, dy(s));
// These comparisons are safe as we are comparing clamped values.
boolean flag1 = x1 == x2 && x2 == x3 && x3 == x4;
boolean flag2 = y1 == y2 && y2 == y3 && y3 == y4;
return !flag1 && !flag2;
}
private void clamp(MutableQuadView quad, Box bb) {
for (int i = 0; i < 4; i++) {
quad.copyPos(i, pos);
pos.set(
(float) MathHelper.clamp(pos.getX(), bb.minX, bb.maxX),
(float) MathHelper.clamp(pos.getY(), bb.minY, bb.maxY),
(float) MathHelper.clamp(pos.getZ(), bb.minZ, bb.maxZ)
);
quad.pos(i, pos);
}
}
/**
* Gets the 2d X coord for the given axis.
*
* @param s The axis. side >> 1
* @return The x coord.
*/
private static int dx(int s) {
if (s <= 1) {
return 0;
} else {
return 2;
}
}
/**
* Gets the 2d Y coord for the given axis.
*
* @param s The axis. side >> 1
* @return The y coord.
*/
private static int dy(int s) {
if (s > 0) {
return 1;
} else {
return 2;
}
}
}
@@ -0,0 +1,195 @@
/*
* This file is part of CodeChickenLib.
* Copyright (c) 2018, covers1624, All rights reserved.
*
* CodeChickenLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* CodeChickenLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CodeChickenLib. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.thirdparty.codechicken.lib.model.pipeline.transformers;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Direction.AxisDirection;
import net.minecraft.util.math.Vec3i;
import static net.minecraft.util.math.Direction.AxisDirection.NEGATIVE;
import static net.minecraft.util.math.Direction.AxisDirection.POSITIVE;
/**
* This transformer is a little complicated. Basically a Facade / Cover can use
* this to 'kick' the edges in of quads to fix z-Fighting in the corners. Use it
* by specifying the side of the block you are on, the bitmask for where the
* other Facades / Cover's are, the bounding box of the facade, NOT the hole
* piece, and the thickness of your Facade / Cover, this is used as the kick
* amount.
*
* @author covers1624
*/
public class QuadCornerKicker implements RenderContext.QuadTransform {
public static final QuadCornerKicker INSTANCE = new QuadCornerKicker();
// Simple horizonal lookups.
public static int[][] horizonals = new int[][]{
// Around Y axis, NSWE.
{2, 3, 4, 5}, //
{2, 3, 4, 5}, //
// Around Z axis, DUWE.
{0, 1, 4, 5}, //
{0, 1, 4, 5}, //
// Around X axis, DUNS.
{0, 1, 2, 3}, //
{0, 1, 2, 3}};
private int mySide;
private int facadeMask;
private Box box;
private double thickness;
public QuadCornerKicker() {
super();
}
/**
* Set's the side this Facade / Cover is attached to.
*
* @param side The side.
*/
public void setSide(int side) {
this.mySide = side;
}
/**
* Sets the bitmask of Facades / Covers in the blockspace. This is as simple as,
* mask = (1 << side)
*
* @param mask The mask.
*/
public void setFacadeMask(int mask) {
this.facadeMask = mask;
}
/**
* Sets the bounding box of the Facade / Cover, this should be the full box, not
* just a piece of the hole's 'ring'.
*
* @param box The BoundingBox.
*/
public void setBox(Box box) {
this.box = box;
}
/**
* Sets the amount to kick the vertex in by, this is your facades thickness.
*
* @param thickness The thickness.
*/
public void setThickness(double thickness) {
this.thickness = thickness;
}
@Override
public boolean transform(MutableQuadView quad) {
int side = quad.nominalFace().ordinal();
if (side != this.mySide && side != (this.mySide ^ 1)) {
for (int hoz : horizonals[this.mySide]) {
if (side != hoz && side != (hoz ^ 1)) {
if ((this.facadeMask & (1 << hoz)) != 0) {
Corner corner = Corner.fromSides(this.mySide ^ 1, side, hoz);
for (int i = 0; i < 4; i++) {
float x = quad.posByIndex(i, 0);
float y = quad.posByIndex(i, 1);
float z = quad.posByIndex(i, 2);
if (epsComp(x, corner.pX(this.box)) && epsComp(y, corner.pY(this.box))
&& epsComp(z, corner.pZ(this.box))) {
Vec3i vec = Direction.values()[hoz].getVector();
x -= vec.getX() * this.thickness;
y -= vec.getY() * this.thickness;
z -= vec.getZ() * this.thickness;
quad.pos(i, x, y, z);
}
}
}
}
}
}
return true;
}
public enum Corner {
MIN_X_MIN_Y_MIN_Z(NEGATIVE, NEGATIVE, NEGATIVE), MIN_X_MIN_Y_MAX_Z(NEGATIVE, NEGATIVE, POSITIVE),
MIN_X_MAX_Y_MIN_Z(NEGATIVE, POSITIVE, NEGATIVE), MIN_X_MAX_Y_MAX_Z(NEGATIVE, POSITIVE, POSITIVE),
MAX_X_MIN_Y_MIN_Z(POSITIVE, NEGATIVE, NEGATIVE), MAX_X_MIN_Y_MAX_Z(POSITIVE, NEGATIVE, POSITIVE),
MAX_X_MAX_Y_MIN_Z(POSITIVE, POSITIVE, NEGATIVE), MAX_X_MAX_Y_MAX_Z(POSITIVE, POSITIVE, POSITIVE);
private AxisDirection xAxis;
private AxisDirection yAxis;
private AxisDirection zAxis;
private static final int[] sideMask = {0, 2, 0, 1, 0, 4};
Corner(AxisDirection xAxis, AxisDirection yAxis, AxisDirection zAxis) {
this.xAxis = xAxis;
this.yAxis = yAxis;
this.zAxis = zAxis;
}
/**
* Used to find what corner is at the 3 sides. This method assumes you pass in
* the X axis side, Y axis side, and Z axis side, it will NOT complain about an
* invalid side, you will just get garbage data. This method also does not care
* what order the 3 axes are in.
*
* @param sideA Side one.
* @param sideB Side two.
* @param sideC Side three.
* @return The corner at the 3 sides.
*/
public static Corner fromSides(int sideA, int sideB, int sideC) {
// <3 Chicken-Bones.
return values()[sideMask[sideA] | sideMask[sideB] | sideMask[sideC]];
}
public float pX(Box box) {
return (float) (this.xAxis == NEGATIVE ? box.minX : box.maxX);
}
public float pY(Box box) {
return (float) (this.yAxis == NEGATIVE ? box.minY : box.maxY);
}
public float pZ(Box box) {
return (float) (this.zAxis == NEGATIVE ? box.minZ : box.maxZ);
}
}
// Should be small enough.
private final static double EPSILON = 0.00001;
private static boolean epsComp(float a, float b) {
if (a == b) {
return true;
} else {
return Math.abs(a - b) < EPSILON;
}
}
}
@@ -0,0 +1,107 @@
/*
* This file is part of CodeChickenLib.
* Copyright (c) 2018, covers1624, All rights reserved.
*
* CodeChickenLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* CodeChickenLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CodeChickenLib. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.thirdparty.codechicken.lib.model.pipeline.transformers;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Direction.AxisDirection;
import static net.minecraft.util.math.Direction.AxisDirection.POSITIVE;
/**
* This transformer strips quads that are on faces. Simply set the bounds for
* the faces, and the strip mask.
*
* @author covers1624
*/
public class QuadFaceStripper implements RenderContext.QuadTransform {
private Box bounds;
private int mask;
QuadFaceStripper() {
super();
}
public QuadFaceStripper(Box bounds, int mask) {
this.bounds = bounds;
this.mask = mask;
}
/**
* The bounds of the faces, used as the .. bounds, if all vertices of a quad lay
* on the bounds, it is up for stripping.
*
* @param bounds The bounds.
*/
public void setBounds(Box bounds) {
this.bounds = bounds;
}
/**
* The mask to strip edges. This is an opt in system, the mask is simple 'mask =
* (1 << side)'.
*
* @param mask The mask.
*/
public void setMask(int mask) {
this.mask = mask;
}
@Override
public boolean transform(MutableQuadView quad) {
if (this.mask == 0) {
return true;// No mask, nothing changes.
}
// If the bit for this quad is set, then check if we should strip.
Direction face = quad.nominalFace();
if ((this.mask & (1 << face.ordinal())) != 0) {
AxisDirection dir = face.getDirection();
switch (face.getAxis()) {
case X: {
float bound = (float) (dir == POSITIVE ? this.bounds.maxX : this.bounds.minX);
float x1 = quad.posByIndex(0, 0);
float x2 = quad.posByIndex(1, 0);
float x3 = quad.posByIndex(2, 0);
float x4 = quad.posByIndex(3, 0);
return x1 != x2 || x2 != x3 || x3 != x4 || x4 != bound;
}
case Y: {
float bound = (float) (dir == POSITIVE ? this.bounds.maxY : this.bounds.minY);
float y1 = quad.posByIndex(0, 1);
float y2 = quad.posByIndex(1, 1);
float y3 = quad.posByIndex(2, 1);
float y4 = quad.posByIndex(3, 1);
return y1 != y2 || y2 != y3 || y3 != y4 || y4 != bound;
}
case Z: {
float bound = (float) (dir == POSITIVE ? this.bounds.maxZ : this.bounds.minZ);
float z1 = quad.posByIndex(0, 2);
float z2 = quad.posByIndex(1, 2);
float z3 = quad.posByIndex(2, 2);
float z4 = quad.posByIndex(3, 2);
return z1 != z2 || z2 != z3 || z3 != z4 || z4 != bound;
}
}
}
return true;
}
}
@@ -0,0 +1,85 @@
/*
* This file is part of CodeChickenLib.
* Copyright (c) 2018, covers1624, All rights reserved.
*
* CodeChickenLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* CodeChickenLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CodeChickenLib. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.thirdparty.codechicken.lib.model.pipeline.transformers;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.client.util.math.Vector4f;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Matrix4f;
/**
* Created by covers1624 on 2/6/20.
*/
public class QuadMatrixTransformer implements RenderContext.QuadTransform {
private static final Matrix4f identity;
static {
identity = new Matrix4f();
identity.loadIdentity();
}
private final Vector3f storage3 = new Vector3f();
private final Vector4f storage = new Vector4f();
private Matrix4f matrix;
private boolean identityMatrix;
QuadMatrixTransformer() {
super();
}
public QuadMatrixTransformer(Matrix4f matrix) {
this.matrix = matrix;
this.identityMatrix = matrix.equals(identity);
}
public void setMatrix(Matrix4f matrix) {
this.matrix = matrix;
this.identityMatrix = matrix.equals(identity);
}
@Override
public boolean transform(MutableQuadView quad) {
if (identityMatrix) {
return true;
}
for (int i = 0; i < 4; i++) {
quad.copyPos(i, storage3);
storage.set(storage3.getX(), storage3.getY(), storage3.getZ(), 1);
storage.transform(matrix);
quad.pos(i, storage.getX(), storage.getY(), storage.getZ());
if (quad.hasNormal(i)) {
quad.copyNormal(i, storage3);
storage.set(storage3.getX(), storage3.getY(), storage3.getZ(), 0);
storage.transform(matrix);
storage.normalize();
quad.normal(i, storage.getX(), storage.getY(), storage.getZ());
if (i == 0) {
Direction face = Direction.getFacing(storage.getX(), storage.getY(), storage.getZ());
quad.nominalFace(face);
quad.cullFace(face);
}
}
}
return true;
}
}
@@ -0,0 +1,180 @@
/*
* This file is part of CodeChickenLib.
* Copyright (c) 2018, covers1624, All rights reserved.
*
* CodeChickenLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* CodeChickenLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CodeChickenLib. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.thirdparty.codechicken.lib.model.pipeline.transformers;
import appeng.thirdparty.codechicken.lib.math.InterpHelper;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadView;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.fabricmc.fabric.impl.client.indigo.renderer.mesh.EncodingFormat;
import net.fabricmc.fabric.impl.client.indigo.renderer.mesh.MutableQuadViewImpl;
/**
* This transformer Re-Interpolates the Color, UV's and LightMaps. Use this
* after all transformations that translate vertices in the pipeline.
* <p>
* This Transformation can only be used in the BakedPipeline.
*
* @author covers1624
*/
public class QuadReInterpolator implements RenderContext.QuadTransform {
private final InterpHelper interpHelper = new InterpHelper();
private final MutableQuadViewImpl bufferQuad = new MutableQuadViewImpl() {
{
data = new int[EncodingFormat.TOTAL_STRIDE];
}
@Override
public QuadEmitter emit() {
throw new UnsupportedOperationException();
}
};
public QuadReInterpolator() {
super();
}
public void setInputQuad(QuadView quad) {
int s = quad.nominalFace().ordinal() >> 1;
int xIdx = dx(s);
int yIdx = dy(s);
interpHelper.reset( //
quad.posByIndex(0, xIdx), quad.posByIndex(0, yIdx), //
quad.posByIndex(1, xIdx), quad.posByIndex(1, yIdx), //
quad.posByIndex(2, xIdx), quad.posByIndex(2, yIdx), //
quad.posByIndex(3, xIdx), quad.posByIndex(3, yIdx));
quad.copyTo(bufferQuad);
}
@Override
public boolean transform(MutableQuadView quad) {
int s = quad.nominalFace().ordinal() >> 1;
int xIdx = dx(s);
int yIdx = dy(s);
this.interpHelper.setup();
for (int i = 0; i < 4; i++) {
float x = quad.posByIndex(i, xIdx);
float y = quad.posByIndex(i, yIdx);
this.interpHelper.locate(x, y);
interpColorFrom(quad, i);
interpUVFrom(quad, i);
interpLightMapFrom(quad, i);
}
return true;
}
/**
* Interpolates the new color values for this Vertex using the others as a
* reference.
*/
public void interpColorFrom(MutableQuadView quad, int vertexIndex) {
int p1 = bufferQuad.spriteColor(0, 0);
int p2 = bufferQuad.spriteColor(1, 0);
int p3 = bufferQuad.spriteColor(2, 0);
int p4 = bufferQuad.spriteColor(3, 0);
if (p1 == p2 && p2 == p3 && p3 == p4) {
return; // Don't bother for uniformly colored quads
}
// Interpolate each color component separately
int color = 0;
int mask = 0xFF;
for (int i = 0; i < 4; i++) {
float p1c = (float) (p1 & mask);
float p2c = (float) (p2 & mask);
float p3c = (float) (p3 & mask);
float p4c = (float) (p4 & mask);
int interp = (int) interpHelper.interpolate(p1c, p2c, p3c, p4c);
color |= interp & mask;
mask <<= 8;
}
quad.spriteColor(vertexIndex, 0, color);
}
/**
* Interpolates the new UV values for this Vertex using the others as a
* reference.
*/
public void interpUVFrom(MutableQuadView quad, int vertexIndex) {
float p1 = bufferQuad.spriteU(0, 0);
float p2 = bufferQuad.spriteU(1, 0);
float p3 = bufferQuad.spriteU(2, 0);
float p4 = bufferQuad.spriteU(3, 0);
float u = interpHelper.interpolate(p1, p2, p3, p4);
p1 = bufferQuad.spriteV(0, 0);
p2 = bufferQuad.spriteV(1, 0);
p3 = bufferQuad.spriteV(2, 0);
p4 = bufferQuad.spriteV(3, 0);
float v = interpHelper.interpolate(p1, p2, p3, p4);
quad.sprite(vertexIndex, 0, u, v);
}
/**
* Interpolates the new LightMap values for this Vertex using the others as a
* reference.
*
* @return The same Vertex.
*/
public void interpLightMapFrom(MutableQuadView quad, int vertexIndex) {
for (int e = 0; e < 2; e++) {
// FIXME float p1 = others[0].lightmap[e];
// FIXME float p2 = others[1].lightmap[e];
// FIXME float p3 = others[2].lightmap[e];
// FIXME float p4 = others[3].lightmap[e];
// FIXME if (p1 != p2 || p2 != p3 || p3 != p4) {
// FIXME this.lightmap[e] = interpHelper.interpolate(p1, p2, p3, p4);
// FIXME }
}
}
/**
* Gets the 2d X coord for the given axis.
*
* @param s The axis. side >> 1
* @return The x coord.
*/
private static int dx(int s) {
if (s <= 1) {
return 0;
} else {
return 2;
}
}
/**
* Gets the 2d Y coord for the given axis.
*
* @param s The axis. side >> 1
* @return The y coord.
*/
private static int dy(int s) {
if (s > 0) {
return 1;
} else {
return 2;
}
}
}
@@ -0,0 +1,59 @@
/*
* This file is part of CodeChickenLib.
* Copyright (c) 2018, covers1624, All rights reserved.
*
* CodeChickenLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* CodeChickenLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CodeChickenLib. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.thirdparty.codechicken.lib.model.pipeline.transformers;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.fabricmc.fabric.impl.client.indigo.renderer.helper.ColorHelper;
/**
* This transformer tints quads.. Feed it the output of
* BlockColors.colorMultiplier.
*
* @author covers1624
*/
public class QuadTinter implements RenderContext.QuadTransform {
private int tint;
QuadTinter() {
super();
}
public QuadTinter(int tint) {
this.tint = tint | 0xFF000000;
}
public QuadTinter setTint(int tint) {
this.tint = tint;
return this;
}
@Override
public boolean transform(MutableQuadView quad) {
// Nuke tintIndex.
quad.colorIndex(-1);
for (int i = 0; i < 4; i++) {
int color = quad.spriteColor(i, 0);
color = ColorHelper.multiplyColor(color, tint);
quad.spriteColor(i, 0, color);
}
return true;
}
}