Skip to content

Commit

Permalink
Use normal to calculate quad facing
Browse files Browse the repository at this point in the history
  • Loading branch information
xCollateral committed Oct 13, 2024
1 parent a7ffe3d commit 0ef9f9a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
11 changes: 3 additions & 8 deletions src/main/java/net/vulkanmod/mixin/render/block/BakedQuadM.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,9 @@ public class BakedQuadM implements ModelQuadView {
private void onInit(int[] vertices, int tintIndex, Direction face, TextureAtlasSprite textureAtlasSprite, boolean shade, CallbackInfo ci) {
this.flags = ModelQuadFlags.getQuadFlags(this, face);

if (face != null) {
this.facing = QuadFacing.fromDirection(face);
this.normal = NormalHelper.packedNormalFromDirection(face);
} else {
int packedNormal = NormalHelper.computePackedNormal(this);
this.facing = QuadFacing.fromNormal(packedNormal);
this.normal = packedNormal;
}
int packedNormal = NormalHelper.computePackedNormal(this);
this.normal = packedNormal;
this.facing = QuadFacing.fromNormal(packedNormal);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void load() {
isGeometryInvalid = false;
nominalFace = lightFace();
NormalHelper.unpackNormal(packedFaceNormal(), faceNormal);
facing = QuadFacing.fromDirection(lightFace());
facing = QuadFacing.fromNormal(faceNormal);
}

protected void computeGeometry() {
Expand All @@ -90,7 +90,7 @@ protected void computeGeometry() {
// depends on light face
data[baseIndex + HEADER_BITS] = EncodingFormat.geometryFlags(data[baseIndex + HEADER_BITS], ModelQuadFlags.getQuadFlags(this, lightFace));

facing = QuadFacing.fromDirection(lightFace);
facing = QuadFacing.fromNormal(faceNormal);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/net/vulkanmod/render/chunk/cull/QuadFacing.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.vulkanmod.render.vertex.format.I32_SNorm;
import org.joml.Vector3f;

public enum QuadFacing {
X_POS,
Expand Down Expand Up @@ -32,6 +33,14 @@ public static QuadFacing fromNormal(int packedNormal) {
final float y = I32_SNorm.unpackY(packedNormal);
final float z = I32_SNorm.unpackZ(packedNormal);

return fromNormal(x, y, z);
}

public static QuadFacing fromNormal(Vector3f normal) {
return fromNormal(normal.x(), normal.y(), normal.z());
}

public static QuadFacing fromNormal(float x, float y, float z) {
final float absX = Math.abs(x);
final float absY = Math.abs(y);
final float absZ = Math.abs(z);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/net/vulkanmod/render/model/quad/ModelQuad.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import net.minecraft.core.Direction;
import net.vulkanmod.render.chunk.cull.QuadFacing;

/**
* Only used by FluidRenderer
*/
public class ModelQuad implements ModelQuadView {
public static final int VERTEX_SIZE = 8;

Expand Down

0 comments on commit 0ef9f9a

Please sign in to comment.