mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-21 12:52:19 +00:00
Update Celeritas (#2087)
This commit is contained in:
1 parent
2845c9e078
commit
3b4ebcf611
165 files changed
+6776
-3036
No files matched your search
@@ -67,9 +67,9 @@ public class IrisCeleritasShaderProvider implements IrisShaderProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preSubmitShadowGraph(int frame, boolean spectator) {
|
||||
public void preSubmitShadowGraph(int frame) {
|
||||
final WorldRenderingPipeline pipeline = Iris.getPipelineManager().getPipelineNullable();
|
||||
if (pipeline != null) pipeline.preSubmitShadowGraph(frame, spectator);
|
||||
if (pipeline != null) pipeline.preSubmitShadowGraph(frame);
|
||||
}
|
||||
|
||||
public void deleteShaders() {
|
||||
|
||||
@@ -1908,8 +1908,8 @@ public class DeferredWorldRenderingPipeline implements WorldRenderingPipeline, R
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preSubmitShadowGraph(int frame, boolean spectator) {
|
||||
if (shadowRenderer != null) shadowRenderer.preSubmitGraphUpdate(frame, spectator);
|
||||
public void preSubmitShadowGraph(int frame) {
|
||||
if (shadowRenderer != null) shadowRenderer.preSubmitGraphUpdate(frame);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -127,15 +127,41 @@ public class ShadowRenderer {
|
||||
private final CelestialUniforms celestialUniforms;
|
||||
|
||||
|
||||
private static final class MemoizedBoxCuller {
|
||||
private BoxCuller culler;
|
||||
private double lastDistance;
|
||||
|
||||
BoxCuller get(double distance) {
|
||||
if (culler == null) {
|
||||
culler = new BoxCuller(distance);
|
||||
lastDistance = distance;
|
||||
} else if (lastDistance != distance) {
|
||||
culler.setMaxDistance(distance);
|
||||
lastDistance = distance;
|
||||
}
|
||||
return culler;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class FrustumCaches {
|
||||
final AdvancedShadowCullingFrustum advancedFrustum = new AdvancedShadowCullingFrustum();
|
||||
BoxCuller boxCuller;
|
||||
final MemoizedBoxCuller boxCuller = new MemoizedBoxCuller();
|
||||
final MemoizedBoxCuller advancedBoxCuller = new MemoizedBoxCuller();
|
||||
final MemoizedBoxCuller safeZoneDistanceCuller = new MemoizedBoxCuller();
|
||||
SafeZoneCullingFrustum safeZoneFrustum;
|
||||
BoxCullingFrustum boxCullingFrustum;
|
||||
BoxCuller advancedBoxCuller;
|
||||
double lastBoxCullerDistance = -1;
|
||||
double lastAdvancedBoxCullerDistance = -1;
|
||||
String distanceInfo = "(unavailable)";
|
||||
String cullingInfo = "(unavailable)";
|
||||
int infoBranch = -1;
|
||||
double infoDistance = Double.NaN;
|
||||
int infoRenderDistanceBlocks = -1;
|
||||
boolean infoHasSafeZone;
|
||||
boolean infoPackSetter;
|
||||
}
|
||||
|
||||
private static final int INFO_BRANCH_DISTANCE_ONLY = 0;
|
||||
private static final int INFO_BRANCH_ADVANCED = 1;
|
||||
|
||||
private static final long SHADOW_RELAY_MAX_AGE_NANOS = 250_000_000L;
|
||||
|
||||
public static boolean SHADOW_TERRAIN_RELAID = true;
|
||||
@@ -145,7 +171,7 @@ public class ShadowRenderer {
|
||||
private final FrustumCaches entityFrustumCaches = new FrustumCaches();
|
||||
private float lastGraphShadowAngle = Float.NaN;
|
||||
private float relayShadowAngle = Float.NaN;
|
||||
private FrustumHolder preSubmitFrustumHolder = new FrustumHolder();
|
||||
private FrustumHolder preSubmitFrustumHolder = new FrustumHolder("preSubmit");
|
||||
private final FrustumCaches preSubmitFrustumCaches = new FrustumCaches();
|
||||
private boolean preSubmitActive;
|
||||
private float preSubmittedShadowAngle = Float.NaN;
|
||||
@@ -159,29 +185,28 @@ public class ShadowRenderer {
|
||||
AngelicaConfig.shadowGraphHorizonScale);
|
||||
}
|
||||
|
||||
public void preSubmitGraphUpdate(int frame, boolean spectator) {
|
||||
public void preSubmitGraphUpdate(int frame) {
|
||||
final AngelicaRenderSectionManager rsm = CeleritasWorldRenderer.getInstance().getRenderSectionManager();
|
||||
final float currentShadowAngle = getShadowAngle();
|
||||
if (ShadowGraphGate.shouldMarkDirty(lastGraphShadowAngle, currentShadowAngle, shadowAngleDelta())) {
|
||||
rsm.markShadowGraphDirty();
|
||||
lastGraphShadowAngle = currentShadowAngle;
|
||||
}
|
||||
if (!rsm.isShadowGraphDirty()) return;
|
||||
if (!rsm.canSubmitShadowGraphSearch()) return;
|
||||
|
||||
preSubmitFrustumHolder = createShadowFrustum(renderDistanceMultiplier, preSubmitFrustumHolder, preSubmitFrustumCaches);
|
||||
if (!(preSubmitFrustumHolder.getFrustum() instanceof ViewportProvider provider)) return;
|
||||
final Vector3d entityPos = Camera.INSTANCE.getEntityPos();
|
||||
preSubmitFrustumHolder.getFrustum().setPosition(entityPos.x, entityPos.y, entityPos.z);
|
||||
|
||||
if (rsm.preSubmitShadowGraphUpdate(provider.sodium$createViewport(), frame, spectator)) {
|
||||
if (rsm.submitShadowGraphSearch(provider.sodium$createViewport(), frame)) {
|
||||
preSubmittedShadowAngle = lastGraphShadowAngle;
|
||||
preSubmitActive = true;
|
||||
}
|
||||
}
|
||||
private long lastRelayNanos;
|
||||
private final Vector3f shadowLightVectorCache = new Vector3f();
|
||||
private BoxCuller cachedTileEntityCuller;
|
||||
private double lastTileEntityCullerDistance = -1;
|
||||
private final MemoizedBoxCuller tileEntityCuller = new MemoizedBoxCuller();
|
||||
private final boolean shouldRenderDH;
|
||||
private final float nearPlane, farPlane;
|
||||
private final BooleanSupplier packUsesShadowtex1;
|
||||
@@ -214,8 +239,8 @@ public class ShadowRenderer {
|
||||
|
||||
debugStringOverall = "half plane = " + halfPlaneLength + " meters @ " + resolution + "x" + resolution;
|
||||
|
||||
this.terrainFrustumHolder = new FrustumHolder();
|
||||
this.entityFrustumHolder = new FrustumHolder();
|
||||
this.terrainFrustumHolder = new FrustumHolder("terrain");
|
||||
this.entityFrustumHolder = new FrustumHolder("entity");
|
||||
|
||||
this.fov = shadowDirectives.getFov();
|
||||
this.targets = shadowRenderTargets;
|
||||
@@ -390,117 +415,122 @@ public class ShadowRenderer {
|
||||
|
||||
private FrustumHolder createShadowFrustum(float renderMultiplier, FrustumHolder holder, FrustumCaches caches) {
|
||||
// TODO: Cull entities / block entities with Advanced Frustum Culling even if voxelization is detected.
|
||||
String distanceInfo;
|
||||
String cullingInfo;
|
||||
final int renderDistanceBlocks = Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16;
|
||||
|
||||
if ((packCullingState == ShadowCullState.DISTANCE || packHasVoxelization) && packCullingState != ShadowCullState.ADVANCED && packCullingState != ShadowCullState.SAFE_ZONE) {
|
||||
double distance = halfPlaneLength * renderMultiplier;
|
||||
final double distance = halfPlaneLength * renderMultiplier;
|
||||
final boolean packSetter = packCullingState == ShadowCullState.DISTANCE;
|
||||
final boolean capped = distance <= 0 || distance > renderDistanceBlocks;
|
||||
|
||||
String reason;
|
||||
if (infoInputsChanged(caches, INFO_BRANCH_DISTANCE_ONLY, distance, renderDistanceBlocks, false, packSetter)) {
|
||||
final String reason = packSetter ? "(set by shader pack)" : "(voxelization detected)";
|
||||
|
||||
if (packCullingState == ShadowCullState.DISTANCE) {
|
||||
reason = "(set by shader pack)";
|
||||
} else /*if (packHasVoxelization)*/ {
|
||||
reason = "(voxelization detected)";
|
||||
if (capped) {
|
||||
caches.distanceInfo = renderDistanceBlocks + " blocks (capped by normal render distance)";
|
||||
caches.cullingInfo = "disabled " + reason;
|
||||
} else {
|
||||
caches.distanceInfo = distance + " blocks (set by shader pack)";
|
||||
caches.cullingInfo = "distance only " + reason;
|
||||
}
|
||||
}
|
||||
|
||||
if (distance <= 0 || distance > Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16) {
|
||||
distanceInfo = Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16
|
||||
+ " blocks (capped by normal render distance)";
|
||||
cullingInfo = "disabled " + reason;
|
||||
return holder.setInfo(NON_CULLING_FRUSTUM, distanceInfo, cullingInfo);
|
||||
} else {
|
||||
distanceInfo = distance + " blocks (set by shader pack)";
|
||||
cullingInfo = "distance only " + reason;
|
||||
holder.setInfo(getOrCreateBoxCullingFrustum(distance, caches), distanceInfo, cullingInfo);
|
||||
if (capped) {
|
||||
return applyInfo(holder, NON_CULLING_FRUSTUM, caches);
|
||||
}
|
||||
|
||||
return applyInfo(holder, getOrCreateBoxCullingFrustum(distance, caches), caches);
|
||||
} else {
|
||||
BoxCuller boxCuller;
|
||||
|
||||
boolean hasSafeZone = packCullingState == ShadowCullState.SAFE_ZONE;
|
||||
final boolean hasSafeZone = packCullingState == ShadowCullState.SAFE_ZONE;
|
||||
|
||||
if (hasSafeZone && renderMultiplier < 0) renderMultiplier = 1.0f;
|
||||
|
||||
final boolean userSetter = renderMultiplier < 0;
|
||||
double distance = (hasSafeZone ? voxelDistance : halfPlaneLength) * renderMultiplier;
|
||||
String setter = "(set by shader pack)";
|
||||
|
||||
if (renderMultiplier < 0) {
|
||||
if (userSetter) {
|
||||
// TODO: GUI
|
||||
distance = IrisVideoSettings.shadowDistance * 16; // can be zero :(
|
||||
setter = "(set by user)";
|
||||
}
|
||||
|
||||
if (distance >= Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16 && !hasSafeZone) {
|
||||
distanceInfo = Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16
|
||||
+ " blocks (capped by normal render distance)";
|
||||
boxCuller = null;
|
||||
} else {
|
||||
distanceInfo = distance + " blocks " + setter;
|
||||
final boolean capped = distance >= renderDistanceBlocks && !hasSafeZone;
|
||||
final boolean cullEverything = !capped && distance == 0.0 && !hasSafeZone;
|
||||
|
||||
if (distance == 0.0 && !hasSafeZone) {
|
||||
cullingInfo = "no shadows rendered";
|
||||
return holder.setInfo(CULL_EVERYTHING_FRUSTUM, distanceInfo, cullingInfo);
|
||||
if (infoInputsChanged(caches, INFO_BRANCH_ADVANCED, distance, renderDistanceBlocks, hasSafeZone, !userSetter)) {
|
||||
if (capped) {
|
||||
caches.distanceInfo = renderDistanceBlocks + " blocks (capped by normal render distance)";
|
||||
} else {
|
||||
caches.distanceInfo = distance + " blocks " + (userSetter ? "(set by user)" : "(set by shader pack)");
|
||||
}
|
||||
|
||||
boxCuller = getOrCreateAdvancedBoxCuller(distance, caches);
|
||||
if (cullEverything) {
|
||||
caches.cullingInfo = "no shadows rendered";
|
||||
} else {
|
||||
caches.cullingInfo = hasSafeZone ? "Safe Zone Frustum Culling enabled" : "Advanced Occlusion Culling enabled";
|
||||
}
|
||||
}
|
||||
|
||||
cullingInfo = (hasSafeZone ? "Safe Zone" : "Advanced") + " Frustum Culling enabled";
|
||||
if (cullEverything) {
|
||||
return applyInfo(holder, CULL_EVERYTHING_FRUSTUM, caches);
|
||||
}
|
||||
|
||||
final BoxCuller boxCuller = capped ? null : caches.advancedBoxCuller.get(distance);
|
||||
|
||||
final Vector4f shadowLightPosition = celestialUniforms.getShadowLightPositionInWorldSpace();
|
||||
shadowLightVectorCache.set(shadowLightPosition.x(), shadowLightPosition.y(), shadowLightPosition.z());
|
||||
shadowLightVectorCache.normalize();
|
||||
|
||||
Matrix4fc projView = ((shouldRenderDH && DHCompat.hasRenderingEnabled()) ? DHCompat.getProjection() : RenderingState.INSTANCE.getProjectionMatrix());
|
||||
final Matrix4fc projView = ((shouldRenderDH && DHCompat.hasRenderingEnabled()) ? DHCompat.getProjection() : RenderingState.INSTANCE.getProjectionMatrix());
|
||||
|
||||
if (hasSafeZone) {
|
||||
BoxCuller distanceCuller = new BoxCuller(halfPlaneLength * renderMultiplier);
|
||||
SafeZoneCullingFrustum safeZoneFrustum = new SafeZoneCullingFrustum(
|
||||
RenderingState.INSTANCE.getModelViewMatrix(), projView,
|
||||
shadowLightVectorCache, boxCuller, distanceCuller);
|
||||
return holder.setInfo(safeZoneFrustum, distanceInfo, cullingInfo);
|
||||
if (caches.safeZoneFrustum == null) {
|
||||
caches.safeZoneFrustum = new SafeZoneCullingFrustum();
|
||||
}
|
||||
caches.safeZoneFrustum.init(RenderingState.INSTANCE.getModelViewMatrix(), projView, shadowLightVectorCache,
|
||||
boxCuller, caches.safeZoneDistanceCuller.get(halfPlaneLength * renderMultiplier));
|
||||
return applyInfo(holder, caches.safeZoneFrustum, caches);
|
||||
} else {
|
||||
caches.advancedFrustum.init(RenderingState.INSTANCE.getModelViewMatrix(), projView, shadowLightVectorCache, boxCuller);
|
||||
return holder.setInfo(caches.advancedFrustum, distanceInfo, cullingInfo);
|
||||
return applyInfo(holder, caches.advancedFrustum, caches);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean infoInputsChanged(FrustumCaches caches, int branch, double distance, int renderDistanceBlocks, boolean hasSafeZone, boolean packSetter) {
|
||||
if (caches.infoBranch == branch && caches.infoDistance == distance
|
||||
&& caches.infoRenderDistanceBlocks == renderDistanceBlocks
|
||||
&& caches.infoHasSafeZone == hasSafeZone && caches.infoPackSetter == packSetter) {
|
||||
return false;
|
||||
}
|
||||
|
||||
caches.infoBranch = branch;
|
||||
caches.infoDistance = distance;
|
||||
caches.infoRenderDistanceBlocks = renderDistanceBlocks;
|
||||
caches.infoHasSafeZone = hasSafeZone;
|
||||
caches.infoPackSetter = packSetter;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static FrustumHolder applyInfo(FrustumHolder holder, Frustrum frustum, FrustumCaches caches) {
|
||||
final boolean changed = !caches.cullingInfo.equals(holder.getCullingInfo())
|
||||
|| !caches.distanceInfo.equals(holder.getDistanceInfo());
|
||||
holder.setInfo(frustum, caches.distanceInfo, caches.cullingInfo);
|
||||
|
||||
if (changed) {
|
||||
Iris.logger.info("Shadow culling ({}): {}, {}", holder.getRole(), caches.cullingInfo, caches.distanceInfo);
|
||||
}
|
||||
|
||||
return holder;
|
||||
}
|
||||
|
||||
private static BoxCullingFrustum getOrCreateBoxCullingFrustum(double distance, FrustumCaches caches) {
|
||||
if (caches.boxCuller == null) {
|
||||
caches.boxCuller = new BoxCuller(distance);
|
||||
caches.boxCullingFrustum = new BoxCullingFrustum(caches.boxCuller);
|
||||
caches.lastBoxCullerDistance = distance;
|
||||
} else if (caches.lastBoxCullerDistance != distance) {
|
||||
caches.boxCuller.setMaxDistance(distance);
|
||||
caches.lastBoxCullerDistance = distance;
|
||||
final BoxCuller culler = caches.boxCuller.get(distance);
|
||||
|
||||
if (caches.boxCullingFrustum == null) {
|
||||
caches.boxCullingFrustum = new BoxCullingFrustum(culler);
|
||||
}
|
||||
return caches.boxCullingFrustum;
|
||||
}
|
||||
|
||||
private static BoxCuller getOrCreateAdvancedBoxCuller(double distance, FrustumCaches caches) {
|
||||
if (caches.advancedBoxCuller == null) {
|
||||
caches.advancedBoxCuller = new BoxCuller(distance);
|
||||
caches.lastAdvancedBoxCullerDistance = distance;
|
||||
} else if (caches.lastAdvancedBoxCullerDistance != distance) {
|
||||
caches.advancedBoxCuller.setMaxDistance(distance);
|
||||
caches.lastAdvancedBoxCullerDistance = distance;
|
||||
}
|
||||
return caches.advancedBoxCuller;
|
||||
}
|
||||
|
||||
private BoxCuller getOrCreateTileEntityCuller(double distance) {
|
||||
if (cachedTileEntityCuller == null) {
|
||||
cachedTileEntityCuller = new BoxCuller(distance);
|
||||
lastTileEntityCullerDistance = distance;
|
||||
} else if (lastTileEntityCullerDistance != distance) {
|
||||
cachedTileEntityCuller.setMaxDistance(distance);
|
||||
lastTileEntityCullerDistance = distance;
|
||||
}
|
||||
return cachedTileEntityCuller;
|
||||
}
|
||||
|
||||
private void setupGlState(Matrix4f projMatrix) {
|
||||
GLStateManager.glViewport(0, 0, resolution, resolution);
|
||||
|
||||
@@ -780,7 +810,7 @@ public class ShadowRenderer {
|
||||
BoxCuller culler = null;
|
||||
if (hasEntityFrustum) {
|
||||
double distance = halfPlaneLength * (renderDistanceMultiplier * entityShadowDistanceMultiplier);
|
||||
culler = getOrCreateTileEntityCuller(distance);
|
||||
culler = tileEntityCuller.get(distance);
|
||||
culler.setPosition(cameraX, cameraY, cameraZ);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.OptionalInt;
|
||||
public interface WorldRenderingPipeline {
|
||||
void beginLevelRendering();
|
||||
void renderShadows(EntityRenderer levelRenderer, Camera camera);
|
||||
default void preSubmitShadowGraph(int frame, boolean spectator) {}
|
||||
default void preSubmitShadowGraph(int frame) {}
|
||||
void addDebugText(List<String> messages);
|
||||
OptionalInt getForcedShadowRenderDistanceChunksForDisplay();
|
||||
|
||||
|
||||
@@ -96,4 +96,10 @@ public class BoxCuller {
|
||||
|
||||
return maxZ < this.minRelZ || minZ > this.maxRelZ;
|
||||
}
|
||||
|
||||
public boolean isFullyInsideViewRelative(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
||||
return minX >= this.minRelX && maxX <= this.maxRelX
|
||||
&& minY >= this.minRelY && maxY <= this.maxRelY
|
||||
&& minZ >= this.minRelZ && maxZ <= this.maxRelZ;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,11 @@ public class CullEverythingFrustum extends Frustrum implements ViewportProvider,
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int intersectAab(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
||||
return OUTSIDE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Viewport sodium$createViewport() {
|
||||
return new Viewport(this, position.set(xPosition, yPosition, zPosition));
|
||||
|
||||
@@ -3,10 +3,15 @@ package net.coderbot.iris.shadows.frustum;
|
||||
import net.minecraft.client.renderer.culling.Frustrum;
|
||||
|
||||
public class FrustumHolder {
|
||||
private final String role;
|
||||
private Frustrum frustum;
|
||||
private String distanceInfo = "(unavailable)";
|
||||
private String cullingInfo = "(unavailable)";
|
||||
|
||||
public FrustumHolder(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public FrustumHolder setInfo(Frustrum frustum, String distanceInfo, String cullingInfo) {
|
||||
this.frustum = frustum;
|
||||
this.distanceInfo = distanceInfo;
|
||||
@@ -14,6 +19,10 @@ public class FrustumHolder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public Frustrum getFrustum() {
|
||||
return frustum;
|
||||
}
|
||||
|
||||
+61
-1
@@ -9,6 +9,7 @@ import net.minecraft.util.AxisAlignedBB;
|
||||
import org.embeddedt.embeddium.impl.render.viewport.Viewport;
|
||||
import org.embeddedt.embeddium.impl.render.viewport.ViewportProvider;
|
||||
import org.embeddedt.embeddium.impl.render.viewport.frustum.Frustum;
|
||||
import org.embeddedt.embeddium.impl.render.viewport.frustum.ShadowSearchFrustum;
|
||||
import org.joml.Math;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Matrix4fc;
|
||||
@@ -37,7 +38,7 @@ import org.joml.Vector4f;
|
||||
* cost of slightly more computations.</p>
|
||||
*/
|
||||
@Optional.Interface(modid = "distanthorizons", iface = "com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiShadowCullingFrustum")
|
||||
public class AdvancedShadowCullingFrustum extends Frustrum implements ViewportProvider, Frustum, IDhApiShadowCullingFrustum {
|
||||
public class AdvancedShadowCullingFrustum extends Frustrum implements ViewportProvider, Frustum, ShadowSearchFrustum, IDhApiShadowCullingFrustum {
|
||||
private static final int MAX_CLIPPING_PLANES = 13;
|
||||
|
||||
/**
|
||||
@@ -279,11 +280,47 @@ public class AdvancedShadowCullingFrustum extends Frustrum implements ViewportPr
|
||||
return checkCornerVisibility(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int intersectAab(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
||||
if (boxCuller != null && boxCuller.isCulledViewRelative(minX, minY, minZ, maxX, maxY, maxZ)) {
|
||||
return OUTSIDE;
|
||||
}
|
||||
|
||||
final int result = intersectCorners(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
|
||||
if (result == FULLY_INSIDE && boxCuller != null
|
||||
&& !boxCuller.isFullyInsideViewRelative(minX, minY, minZ, maxX, maxY, maxZ)) {
|
||||
return PARTIALLY_INSIDE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Viewport sodium$createViewport() {
|
||||
return new Viewport(this, position.set(xPosition, yPosition, zPosition));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsOcclusionSearch() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float shadowLightX() {
|
||||
return this.shadowLightVectorFromOrigin.x();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float shadowLightY() {
|
||||
return this.shadowLightVectorFromOrigin.y();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float shadowLightZ() {
|
||||
return this.shadowLightVectorFromOrigin.z();
|
||||
}
|
||||
|
||||
protected boolean isVisible(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
|
||||
return this.checkCornerVisibility((float)(minX - xPosition), (float)(minY - yPosition), (float)(minZ - zPosition),
|
||||
(float)(maxX - xPosition), (float)(maxY - yPosition), (float)(maxZ - zPosition));
|
||||
@@ -306,6 +343,29 @@ public class AdvancedShadowCullingFrustum extends Frustrum implements ViewportPr
|
||||
return true;
|
||||
}
|
||||
|
||||
protected int intersectCorners(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
||||
boolean inside = true;
|
||||
|
||||
for (int i = 0; i < planeCount; ++i) {
|
||||
final Vector4f plane = this.planes[i];
|
||||
|
||||
final float px = plane.x();
|
||||
final float py = plane.y();
|
||||
final float pz = plane.z();
|
||||
final float pw = plane.w();
|
||||
|
||||
if (Math.fma(px, px < 0 ? minX : maxX, Math.fma(py, py < 0 ? minY : maxY, pz * (pz < 0 ? minZ : maxZ))) < -pw) {
|
||||
return OUTSIDE;
|
||||
}
|
||||
|
||||
if (Math.fma(px, px < 0 ? maxX : minX, Math.fma(py, py < 0 ? maxY : minY, pz * (pz < 0 ? maxZ : minZ))) < -pw) {
|
||||
inside = false;
|
||||
}
|
||||
}
|
||||
|
||||
return inside ? FULLY_INSIDE : PARTIALLY_INSIDE;
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "distanthorizons")
|
||||
@Override
|
||||
public void update(int worldMinBlockY, int worldMaxBlockY, DhApiMat4f worldViewProjection) {
|
||||
|
||||
+55
-4
@@ -7,14 +7,18 @@ import org.joml.Matrix4fc;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class SafeZoneCullingFrustum extends AdvancedShadowCullingFrustum {
|
||||
private final BoxCuller distanceCuller;
|
||||
private BoxCuller distanceCuller;
|
||||
|
||||
public SafeZoneCullingFrustum(Matrix4fc playerView, Matrix4fc playerProjection, Vector3f shadowLightVector, BoxCuller voxelCuller, BoxCuller distanceCuller) {
|
||||
super();
|
||||
init(playerView, playerProjection, shadowLightVector, voxelCuller);
|
||||
public void init(Matrix4fc playerView, Matrix4fc playerProjection, Vector3f shadowLightVector, BoxCuller voxelCuller, BoxCuller distanceCuller) {
|
||||
super.init(playerView, playerProjection, shadowLightVector, voxelCuller);
|
||||
this.distanceCuller = distanceCuller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsOcclusionSearch() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(double cameraX, double cameraY, double cameraZ) {
|
||||
if (this.distanceCuller != null) {
|
||||
@@ -53,4 +57,51 @@ public class SafeZoneCullingFrustum extends AdvancedShadowCullingFrustum {
|
||||
|
||||
return checkCornerVisibility(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int intersectAab(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
||||
int distanceResult = FULLY_INSIDE;
|
||||
|
||||
if (distanceCuller != null) {
|
||||
distanceResult = intersectCuller(distanceCuller, minX, minY, minZ, maxX, maxY, maxZ);
|
||||
|
||||
if (distanceResult == OUTSIDE) {
|
||||
return OUTSIDE;
|
||||
}
|
||||
}
|
||||
|
||||
int safeZoneResult = OUTSIDE;
|
||||
|
||||
if (boxCuller != null) {
|
||||
safeZoneResult = intersectCuller(boxCuller, minX, minY, minZ, maxX, maxY, maxZ);
|
||||
|
||||
if (safeZoneResult == FULLY_INSIDE && distanceResult == FULLY_INSIDE) {
|
||||
return FULLY_INSIDE;
|
||||
}
|
||||
}
|
||||
|
||||
if (distanceResult == PARTIALLY_INSIDE && safeZoneResult == PARTIALLY_INSIDE) {
|
||||
return PARTIALLY_INSIDE;
|
||||
}
|
||||
|
||||
final int frustumResult = intersectCorners(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
|
||||
if (safeZoneResult == OUTSIDE && frustumResult == OUTSIDE) {
|
||||
return OUTSIDE;
|
||||
}
|
||||
|
||||
if (frustumResult == FULLY_INSIDE && distanceResult == FULLY_INSIDE) {
|
||||
return FULLY_INSIDE;
|
||||
}
|
||||
|
||||
return PARTIALLY_INSIDE;
|
||||
}
|
||||
|
||||
private static int intersectCuller(BoxCuller culler, float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
||||
if (culler.isCulledViewRelative(minX, minY, minZ, maxX, maxY, maxZ)) {
|
||||
return OUTSIDE;
|
||||
}
|
||||
|
||||
return culler.isFullyInsideViewRelative(minX, minY, minZ, maxX, maxY, maxZ) ? FULLY_INSIDE : PARTIALLY_INSIDE;
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,15 @@ public class BoxCullingFrustum extends Frustrum implements ViewportProvider, Fru
|
||||
return !boxCuller.isCulledViewRelative(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int intersectAab(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
||||
if (boxCuller.isCulledViewRelative(minX, minY, minZ, maxX, maxY, maxZ)) {
|
||||
return OUTSIDE;
|
||||
}
|
||||
|
||||
return boxCuller.isFullyInsideViewRelative(minX, minY, minZ, maxX, maxY, maxZ) ? FULLY_INSIDE : PARTIALLY_INSIDE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Viewport sodium$createViewport() {
|
||||
return new Viewport(this, position.set(xPosition, yPosition, zPosition));
|
||||
|
||||
@@ -24,6 +24,11 @@ public class NonCullingFrustum extends Frustrum implements ViewportProvider, Fru
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int intersectAab(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
||||
return FULLY_INSIDE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Viewport sodium$createViewport() {
|
||||
return new Viewport(this, position.set(xPosition, yPosition, zPosition));
|
||||
|
||||
Reference in new issue
Block a user