mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-10-25 20:22:22 +00:00
Use actual camera when doing cloud related culling and fuctions (#2139)
This commit is contained in:
1 parent
44c930f4ab
commit
7f3fb35ebb
4 files changed
+30
-22
No files matched your search
@@ -204,9 +204,9 @@ final class CloudLayerRenderer {
|
||||
final float cellHeightBlocks = layer.cellHeight() * scaleMult;
|
||||
final float coordinateWidth = layer.coordinateWidth() * scaleMult;
|
||||
|
||||
final float cameraY = (float) (viewEntity.lastTickPosY + (viewEntity.posY - viewEntity.lastTickPosY) * partialTicks);
|
||||
final double cameraCellX = CloudDisc.cellCoordinate(viewEntity.prevPosX + (viewEntity.posX - viewEntity.prevPosX) * partialTicks, coordinateWidth, layer.offsetX());
|
||||
final double cameraCellZ = CloudDisc.cellCoordinate(viewEntity.prevPosZ + (viewEntity.posZ - viewEntity.prevPosZ) * partialTicks, coordinateWidth, layer.offsetZ());
|
||||
final float cameraY = (float) (viewEntity.lastTickPosY + (viewEntity.posY - viewEntity.lastTickPosY) * partialTicks + cloudView.offsetY);
|
||||
final double cameraCellX = CloudDisc.cellCoordinate(viewEntity.prevPosX + (viewEntity.posX - viewEntity.prevPosX) * partialTicks + cloudView.offsetX, coordinateWidth, layer.offsetX());
|
||||
final double cameraCellZ = CloudDisc.cellCoordinate(viewEntity.prevPosZ + (viewEntity.posZ - viewEntity.prevPosZ) * partialTicks + cloudView.offsetZ, coordinateWidth, layer.offsetZ());
|
||||
|
||||
final float cloudBaseRelativeY = layer.height() - cameraY + 0.33F;
|
||||
final float cellFractionX = (float) (cameraCellX - MathHelper.floor_double(cameraCellX));
|
||||
@@ -339,15 +339,18 @@ final class CloudLayerRenderer {
|
||||
final float anchorDriftX = (float) (anchorX - anchorCellX);
|
||||
final float anchorDriftZ = (float) (anchorZ - anchorCellZ);
|
||||
// Face wedges are re-bucketed around the current cell; vertex wedges keep their build anchor.
|
||||
final double cameraDriftX = (faceMeshActive ? 0 : anchorDriftX) + cellFractionX + cloudView.offsetX / cellWidthBlocks;
|
||||
final double cameraDriftZ = (faceMeshActive ? 0 : anchorDriftZ) + cellFractionZ + cloudView.offsetZ / cellWidthBlocks;
|
||||
final double cameraDriftX = (faceMeshActive ? 0 : anchorDriftX) + cellFractionX;
|
||||
final double cameraDriftZ = (faceMeshActive ? 0 : anchorDriftZ) + cellFractionZ;
|
||||
driftCells = Math.hypot(cameraDriftX, cameraDriftZ);
|
||||
final double baseFromEye = cloudBaseRelativeY - cloudView.offsetY;
|
||||
cullingHeightCells = Math.max(Math.abs(baseFromEye), Math.abs(baseFromEye + cellHeightBlocks)) / cellWidthBlocks;
|
||||
cullingHeightCells = Math.max(Math.abs(cloudBaseRelativeY), Math.abs(cloudBaseRelativeY + cellHeightBlocks)) / cellWidthBlocks;
|
||||
|
||||
interiorDriftX = anchorDriftX;
|
||||
interiorDriftZ = anchorDriftZ;
|
||||
|
||||
final float entityToCameraX = cloudView.offsetX / cellWidthBlocks;
|
||||
final float entityToCameraZ = cloudView.offsetZ / cellWidthBlocks;
|
||||
final float deckBaseY = cloudBaseRelativeY + cloudView.offsetY;
|
||||
|
||||
if (!shadersActive) {
|
||||
program.bind();
|
||||
final CloudUniforms uniforms = program.getInterface();
|
||||
@@ -356,11 +359,11 @@ final class CloudLayerRenderer {
|
||||
modelView.scale(cellWidthBlocks, 1.0f, cellWidthBlocks);
|
||||
if (interiorActive) {
|
||||
modelView.pushMatrix();
|
||||
modelView.translate(-cellFractionX, cloudBaseRelativeY, -cellFractionZ);
|
||||
modelView.translate(entityToCameraX - cellFractionX, deckBaseY, entityToCameraZ - cellFractionZ);
|
||||
GLStateManager.getProjectionMatrix().mul(modelView, mvpInteriorScratch);
|
||||
modelView.popMatrix();
|
||||
}
|
||||
modelView.translate(-(cellFractionX + anchorDriftX), cloudBaseRelativeY, -(cellFractionZ + anchorDriftZ));
|
||||
modelView.translate(entityToCameraX - (cellFractionX + anchorDriftX), deckBaseY, entityToCameraZ - (cellFractionZ + anchorDriftZ));
|
||||
modelViewScratch.set(modelView);
|
||||
GLStateManager.getProjectionMatrix().mul(modelView, mvpScratch);
|
||||
modelView.popMatrix();
|
||||
@@ -376,7 +379,7 @@ final class CloudLayerRenderer {
|
||||
} else {
|
||||
GLStateManager.glPushMatrix();
|
||||
GLStateManager.glScalef(cellWidthBlocks, 1.0f, cellWidthBlocks);
|
||||
GLStateManager.glTranslatef(-(cellFractionX + anchorDriftX), cloudBaseRelativeY, -(cellFractionZ + anchorDriftZ));
|
||||
GLStateManager.glTranslatef(entityToCameraX - (cellFractionX + anchorDriftX), deckBaseY, entityToCameraZ - (cellFractionZ + anchorDriftZ));
|
||||
drawClouds(r, g, b, true);
|
||||
GLStateManager.glPopMatrix();
|
||||
}
|
||||
|
||||
@@ -150,11 +150,11 @@ public class CloudRenderer implements IResourceManagerReloadListener {
|
||||
return true;
|
||||
});
|
||||
|
||||
final Entity view = mc.renderViewEntity;
|
||||
final double cameraY = view.lastTickPosY + (view.posY - view.lastTickPosY) * partialTicks;
|
||||
drawOrder.sort((a, b) -> Double.compare(distanceToLayer(b.layer, cameraY), distanceToLayer(a.layer, cameraY)));
|
||||
final ViewportState viewport = GLStateManager.getViewportState();
|
||||
cloudView.update(GLStateManager.getProjectionMatrix(), GLStateManager.getModelViewMatrix(), viewport.width, viewport.height);
|
||||
final Entity view = mc.renderViewEntity;
|
||||
final double cameraY = view.lastTickPosY + (view.posY - view.lastTickPosY) * partialTicks + cloudView.offsetY;
|
||||
drawOrder.sort((a, b) -> Double.compare(distanceToLayer(b.layer, cameraY), distanceToLayer(a.layer, cameraY)));
|
||||
boolean rendered = descriptions.isEmpty();
|
||||
for (CloudLayerRenderer renderer : drawOrder) rendered |= renderer.render(partialTicks, cloudView);
|
||||
return rendered;
|
||||
@@ -198,7 +198,7 @@ public class CloudRenderer implements IResourceManagerReloadListener {
|
||||
float radius = (radiusChunks + marginChunks) * CELLS_PER_CHUNK * width;
|
||||
if (cloudMode != MODE_FANCY) radius *= (float) Math.sqrt(2);
|
||||
radius += MARGIN_CELLS * width;
|
||||
final float cameraY = view == null ? 0.0f : (float) view.posY;
|
||||
final float cameraY = view == null ? 0.0f : (float) (view.posY + cloudView.offsetY);
|
||||
final float verticalSlack = Math.abs(layer.height() + 0.33f - cameraY) + layer.cellHeight() * scaleMult;
|
||||
required = Math.max(required, Math.min(radius + verticalSlack, MAX_FAR_PLANE_DISTANCE));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.gtnewhorizons.angelica.render;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Matrix4fc;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
final class CloudView {
|
||||
|
||||
private final Matrix4f inverseModelView = new Matrix4f();
|
||||
private final Vector3f cameraOffset = new Vector3f();
|
||||
private float lastForwardX = Float.NaN, lastForwardZ = Float.NaN;
|
||||
double pixelsPerRadian;
|
||||
double facing;
|
||||
@@ -34,13 +38,13 @@ final class CloudView {
|
||||
|
||||
private boolean updateCamera(Matrix4fc modelView) {
|
||||
offsetX = offsetY = offsetZ = 0.0f;
|
||||
if (!modelView.isFinite() || modelView.m03() != 0.0f || modelView.m13() != 0.0f
|
||||
|| modelView.m23() != 0.0f || modelView.m33() != 1.0f || !rigid(modelView)) return false;
|
||||
final float tx = modelView.m30(), ty = modelView.m31(), tz = modelView.m32();
|
||||
offsetX = -(modelView.m00() * tx + modelView.m01() * ty + modelView.m02() * tz);
|
||||
offsetY = -(modelView.m10() * tx + modelView.m11() * ty + modelView.m12() * tz);
|
||||
offsetZ = -(modelView.m20() * tx + modelView.m21() * ty + modelView.m22() * tz);
|
||||
if (!Float.isFinite(offsetX) || !Float.isFinite(offsetY) || !Float.isFinite(offsetZ)) return false;
|
||||
if (!modelView.isFinite() || !modelView.isAffine()) return false;
|
||||
modelView.invertAffine(inverseModelView).getTranslation(cameraOffset);
|
||||
if (!cameraOffset.isFinite()) return false;
|
||||
offsetX = cameraOffset.x;
|
||||
offsetY = cameraOffset.y;
|
||||
offsetZ = cameraOffset.z;
|
||||
if (!rigid(modelView)) return false;
|
||||
final float forwardX = -modelView.m02(), forwardZ = -modelView.m22();
|
||||
if (forwardX != lastForwardX || forwardZ != lastForwardZ) {
|
||||
facing = Math.atan2(forwardZ, forwardX);
|
||||
|
||||
+2
-1
@@ -98,7 +98,8 @@ public abstract class MixinEntityRenderer implements IResourceManagerReloadListe
|
||||
|
||||
@ModifyConstant(method = "renderWorld(FJ)V", constant = @Constant(doubleValue = 128.0D), expect = 2)
|
||||
private double iris$alwaysRenderCloudsLate(double cloudHeightCheck) {
|
||||
return IrisApi.getInstance().isShaderPackInUse() ? Double.NEGATIVE_INFINITY : SettingsManager.cloudRenderOrderHeight();
|
||||
if (IrisApi.getInstance().isShaderPackInUse()) return Double.NEGATIVE_INFINITY;
|
||||
return SettingsManager.cloudRenderOrderHeight() - Camera.INSTANCE.getOffset().y;
|
||||
}
|
||||
|
||||
@Inject(method = "renderWorld(FJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;renderSky(F)V"))
|
||||
|
||||
Reference in new issue
Block a user