Skip to content

Commit

Permalink
Tweak LOD cable texture stretching
Browse files Browse the repository at this point in the history
  • Loading branch information
FoundationGames committed Aug 2, 2023
1 parent 4471518 commit 6244dc2
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ public static void renderConnection(PhonosClientConfig config, World world, Cabl
float g = conn.color != null ? conn.color.getColorComponents()[1] : 1;
float b = conn.color != null ? conn.color.getColorComponents()[2] : 1;
float length = cableStPt.distance(cableEnPt);
int segments = Math.max((int) Math.ceil(4 * length * config.cableLODNearDetail), 1);

double detail = config.cableLODNearDetail;
int segments = Math.max((int) Math.ceil(4 * length * detail), 1);

if (config.cableLODs) {
float cx = (cableStPt.x + cableEnPt.x) * 0.5f;
Expand All @@ -103,11 +105,13 @@ public static void renderConnection(PhonosClientConfig config, World world, Cabl
double sqDist = MinecraftClient.getInstance().gameRenderer.getCamera().getPos()
.squaredDistanceTo(cx, cy, cz);
double delta = MathHelper.clamp(sqDist / (length * length * 4), 0, 1);
double detail = MathHelper.lerp(delta, config.cableLODNearDetail, config.cableLODFarDetail);
detail = MathHelper.lerp(delta, config.cableLODNearDetail, config.cableLODFarDetail);

segments = Math.max((int) Math.ceil(4 * length * detail), Math.min(3, segments));
}

final float texUWid = (float) (0.25 / detail);

cableRotAxis.set(cableEnPt.z - cableStPt.z, 0, cableEnPt.x - cableStPt.x);

float cablePitch = (float) Math.atan2(cableEnPt.y - cableStPt.y, cableRotAxis.length());
Expand Down Expand Up @@ -159,13 +163,13 @@ public static void renderConnection(PhonosClientConfig config, World world, Cabl
var nml = cableNormal[i];

buffer.vertex(currCableStart[i].x, currCableStart[i].y, currCableStart[i].z).color(r, g, b, 1)
.texture(0.25f, 0.3125f + vOffset2).overlay(overlay).light(segStartLight).normal(nml.x, nml.y, nml.z).next();
.texture(texUWid, 0.3125f + vOffset2).overlay(overlay).light(segStartLight).normal(nml.x, nml.y, nml.z).next();
buffer.vertex(currCableEnd[i].x, currCableEnd[i].y, currCableEnd[i].z).color(r, g, b, 1)
.texture(0, 0.3125f + vOffset2).overlay(overlay).light(segEndLight).normal(nml.x, nml.y, nml.z).next();
buffer.vertex(currCableEnd[next].x, currCableEnd[next].y, currCableEnd[next].z).color(r, g, b, 1)
.texture(0, 0.375f + vOffset2).overlay(overlay).light(segEndLight).normal(nml.x, nml.y, nml.z).next();
buffer.vertex(currCableStart[next].x, currCableStart[next].y, currCableStart[next].z).color(r, g, b, 1)
.texture(0.25f, 0.375f + vOffset2).overlay(overlay).light(segStartLight).normal(nml.x, nml.y, nml.z).next();
.texture(texUWid, 0.375f + vOffset2).overlay(overlay).light(segStartLight).normal(nml.x, nml.y, nml.z).next();
}
}

Expand Down

0 comments on commit 6244dc2

Please sign in to comment.