aabb only

This commit is contained in:
NULL511
2024-01-25 18:34:17 -05:00
parent 7e287dab71
commit 23b9f16747
3 changed files with 28 additions and 22 deletions
@@ -1,26 +1,33 @@
package com.seibel.distanthorizons.core.pos;
import org.joml.Math;
import org.joml.Matrix4f;
import org.joml.Vector3f;
public class DhFrustumBounds
{
//private final FrustumIntersection frustum;
private final Vector3f boundsMin = new Vector3f();
private final Vector3f boundsMax = new Vector3f();
private final float worldMinY;
private final float worldMaxY;
public DhFrustumBounds(Matrix4f matViewProjectionInv)
public DhFrustumBounds(Matrix4f matViewProjection, float minY, float maxY)
{
Matrix4f matViewProjectionInv = new Matrix4f(matViewProjection);
matViewProjectionInv.invert();
//this.frustum = new FrustumIntersection();
//this.frustum.set(matViewProjection);
matViewProjectionInv.frustumAabb(this.boundsMin, this.boundsMax);
this.worldMinY = minY;
this.worldMaxY = maxY;
}
public boolean Intersects(DhLodPos lodBounds)
{
// TODO
float worldMinY = 0f;
float worldMaxY = 0f;
int lodPosX = lodBounds.getX().toBlockWidth();
int lodPosZ = lodBounds.getZ().toBlockWidth();
int lodSize = lodBounds.getBlockWidth();
@@ -28,10 +35,11 @@ public class DhFrustumBounds
Vector3f lodMin = new Vector3f(lodPosX, worldMinY, lodPosZ);
Vector3f lodMax = new Vector3f(lodPosX + lodSize, worldMaxY, lodPosZ + lodSize);
if (lodMax.x < boundsMin.x || lodMin.x > boundsMax.x) return false;
//if (lodMax.y < boundsMin.y || lodMin.y > boundsMax.y) return false;
if (lodMax.z < boundsMin.z || lodMin.z > boundsMax.z) return false;
if (lodMax.x < this.boundsMin.x || lodMin.x > this.boundsMax.x) return false;
if (lodMax.z < this.boundsMin.z || lodMin.z > this.boundsMax.z) return false;
if (this.worldMaxY < this.boundsMin.y || this.worldMinY > this.boundsMax.y) return false;
//return frustum.intersectAab(lodMin, lodMax) != FrustumIntersection.OUTSIDE;
return true;
}
}
@@ -31,6 +31,7 @@ import com.seibel.distanthorizons.core.util.LodUtil;
import com.seibel.distanthorizons.core.util.objects.SortedArraySet;
import com.seibel.distanthorizons.core.util.objects.quadTree.QuadNode;
import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
import com.seibel.distanthorizons.coreapi.util.math.Vec3f;
import org.apache.logging.log4j.Logger;
@@ -87,7 +88,7 @@ public class RenderBufferHandler implements AutoCloseable
* TODO: This might get locked by update() causing move() call. Is there a way to avoid this?
* Maybe dupe the base list and use atomic swap on render? Or is this not worth it?
*/
public void buildRenderListAndUpdateSections(Matrix4f matViewProjectionInv, Vector3f lookForwardVector)
public void buildRenderListAndUpdateSections(IClientLevelWrapper clientLevelWrapper, Matrix4f matViewProjection, Vec3f lookForwardVector)
{
EDhDirection[] axisDirections = new EDhDirection[3];
@@ -192,7 +193,9 @@ public class RenderBufferHandler implements AutoCloseable
// Build the sorted list
this.loadedNearToFarBuffers = new SortedArraySet<>((a, b) -> -farToNearComparator.compare(a, b)); // TODO is the comparator named wrong?
DhFrustumBounds frustumBounds = new DhFrustumBounds(matViewProjectionInv);
float worldMinY = clientLevelWrapper.getMinHeight();
float worldHeight = clientLevelWrapper.getHeight();
DhFrustumBounds frustumBounds = new DhFrustumBounds(matViewProjection, worldMinY, worldMinY + worldHeight);
// Update the sections
boolean rebuildAllBuffers = this.rebuildAllBuffers.getAndSet(false);
@@ -48,7 +48,6 @@ import com.seibel.distanthorizons.coreapi.util.math.Vec3d;
import com.seibel.distanthorizons.coreapi.util.math.Vec3f;
import org.apache.logging.log4j.LogManager;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.lwjgl.opengl.GL32;
import java.awt.*;
@@ -332,19 +331,15 @@ public class LodRenderer
if (renderingFirstPass)
{
final Vector3f WorldUp = new Vector3f(0f, 1f, 0f);
Vec3f viewDir = this.getLookVector();
Vec3d viewPos = MC_RENDER.getCameraExactPosition();
Vec3f _lookAt = this.getLookVector();
Vector3f lookAt = new Vector3f(_lookAt.x, _lookAt.y, _lookAt.z);
Vec3d cameraPos = MC_RENDER.getCameraExactPosition();
Matrix4f matViewProjectionInv = new Matrix4f()
Matrix4f matViewProjection = new Matrix4f()
.setTransposed(projectionMatrix.getValuesAsArray())
.lookAlong(lookAt, WorldUp)
.translate(-(float)cameraPos.x, -(float)cameraPos.y, -(float)cameraPos.z)
.invert();
.lookAlong(viewDir.x, viewDir.y, viewDir.z, 0f, 1f, 0f)
.translate(-(float)viewPos.x, -(float)viewPos.y, -(float)viewPos.z);
this.bufferHandler.buildRenderListAndUpdateSections(matViewProjectionInv, lookAt);
this.bufferHandler.buildRenderListAndUpdateSections(clientLevelWrapper, matViewProjection, viewDir);
transparencyEnabled = Config.Client.Advanced.Graphics.Quality.transparency.get().transparencyEnabled;
fakeOceanFloor = Config.Client.Advanced.Graphics.Quality.transparency.get().fakeTransparencyEnabled;