Merge branch 'distant-horizons-core-shadow.cull.fix'
This commit is contained in:
+34
-14
@@ -24,6 +24,7 @@ import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiCullin
|
||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||
@@ -35,12 +36,15 @@ import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
|
||||
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.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IIrisAccessor;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IOverrideInjector;
|
||||
import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
|
||||
import com.seibel.distanthorizons.coreapi.util.math.Vec3d;
|
||||
import com.seibel.distanthorizons.coreapi.util.math.Vec3f;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Matrix4fc;
|
||||
|
||||
import java.util.Comparator;
|
||||
@@ -56,6 +60,8 @@ public class RenderBufferHandler implements AutoCloseable
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||
|
||||
private static final IIrisAccessor IRIS_ACCESSOR = ModAccessorInjector.INSTANCE.get(IIrisAccessor.class);
|
||||
|
||||
/** contains all relevant data */
|
||||
@@ -68,6 +74,7 @@ public class RenderBufferHandler implements AutoCloseable
|
||||
|
||||
public F3Screen.MultiDynamicMessage f3Message;
|
||||
|
||||
private final IDhApiCullingFrustum cameraFrustum;
|
||||
private int visibleBufferCount;
|
||||
private int culledBufferCount;
|
||||
private int shadowVisibleBufferCount;
|
||||
@@ -82,14 +89,8 @@ public class RenderBufferHandler implements AutoCloseable
|
||||
public RenderBufferHandler(LodQuadTree lodQuadTree)
|
||||
{
|
||||
this.lodQuadTree = lodQuadTree;
|
||||
this.culledBufferCount = 0;
|
||||
|
||||
IDhApiCullingFrustum coreFrustum = DhApi.overrides.get(IDhApiCullingFrustum.class, IOverrideInjector.CORE_PRIORITY);
|
||||
if (coreFrustum == null)
|
||||
{
|
||||
DhApi.overrides.bind(IDhApiCullingFrustum.class, new DhFrustumBounds());
|
||||
}
|
||||
|
||||
this.cameraFrustum = new DhFrustumBounds();
|
||||
|
||||
this.f3Message = new F3Screen.MultiDynamicMessage(
|
||||
() ->
|
||||
@@ -131,7 +132,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(IClientLevelWrapper clientLevelWrapper, Matrix4fc matWorldViewProjection, Vec3f lookForwardVector)
|
||||
public void buildRenderListAndUpdateSections(IClientLevelWrapper clientLevelWrapper, DhApiRenderParam renderEventParam, Vec3f lookForwardVector)
|
||||
{
|
||||
EDhDirection[] axisDirections = new EDhDirection[3];
|
||||
|
||||
@@ -238,13 +239,33 @@ public class RenderBufferHandler implements AutoCloseable
|
||||
|
||||
// update the frustum if necessary
|
||||
boolean enableFrustumCulling = !Config.Client.Advanced.Graphics.AdvancedGraphics.disableFrustumCulling.get();
|
||||
IDhApiCullingFrustum frustum = DhApi.overrides.get(IDhApiCullingFrustum.class, IOverrideInjector.CORE_PRIORITY);
|
||||
boolean isShadowPass = (IRIS_ACCESSOR != null && IRIS_ACCESSOR.isRenderingShadowPass());
|
||||
|
||||
IDhApiCullingFrustum frustum = this.cameraFrustum;
|
||||
|
||||
if (enableFrustumCulling)
|
||||
{
|
||||
int worldMinY = clientLevelWrapper.getMinHeight();
|
||||
int worldHeight = clientLevelWrapper.getHeight();
|
||||
|
||||
frustum.update(worldMinY, worldMinY + worldHeight, new Mat4f(matWorldViewProjection));
|
||||
if (isShadowPass) {
|
||||
frustum = DhApi.overrides.get(IDhApiCullingFrustum.class, IOverrideInjector.CORE_PRIORITY);
|
||||
if (frustum == null) enableFrustumCulling = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
int worldMinY = clientLevelWrapper.getMinHeight();
|
||||
int worldHeight = clientLevelWrapper.getHeight();
|
||||
|
||||
Vec3d cameraPos = MC_RENDER.getCameraExactPosition();
|
||||
|
||||
Matrix4fc matWorldView = new Matrix4f()
|
||||
.setTransposed(renderEventParam.mcModelViewMatrix.getValuesAsArray())
|
||||
.translate(-(float) cameraPos.x, -(float) cameraPos.y, -(float) cameraPos.z);
|
||||
|
||||
Matrix4fc matWorldViewProjection = new Matrix4f()
|
||||
.setTransposed(renderEventParam.dhProjectionMatrix.getValuesAsArray())
|
||||
.mul(matWorldView);
|
||||
|
||||
frustum.update(worldMinY, worldMinY + worldHeight, new Mat4f(matWorldViewProjection));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -253,7 +274,6 @@ public class RenderBufferHandler implements AutoCloseable
|
||||
// Update the section list //
|
||||
//=========================//
|
||||
|
||||
boolean isShadowPass = (IRIS_ACCESSOR != null && IRIS_ACCESSOR.isRenderingShadowPass());
|
||||
if (isShadowPass)
|
||||
{
|
||||
this.shadowCulledBufferCount = 0;
|
||||
|
||||
@@ -351,14 +351,7 @@ public class LodRenderer
|
||||
|
||||
if (renderingFirstPass)
|
||||
{
|
||||
Matrix4f matWorldView = new Matrix4f()
|
||||
.setTransposed(MC_RENDER.getWorldViewMatrix().getValuesAsArray());
|
||||
|
||||
Matrix4fc matWorldViewProjection = new Matrix4f()
|
||||
.setTransposed(renderEventParam.dhProjectionMatrix.getValuesAsArray())
|
||||
.mul(matWorldView);
|
||||
|
||||
this.bufferHandler.buildRenderListAndUpdateSections(clientLevelWrapper, matWorldViewProjection, MC_RENDER.getLookAtVector());
|
||||
this.bufferHandler.buildRenderListAndUpdateSections(clientLevelWrapper, renderEventParam, MC_RENDER.getLookAtVector());
|
||||
|
||||
transparencyEnabled = Config.Client.Advanced.Graphics.Quality.transparency.get().transparencyEnabled;
|
||||
fakeOceanFloor = Config.Client.Advanced.Graphics.Quality.transparency.get().fakeTransparencyEnabled;
|
||||
|
||||
Reference in New Issue
Block a user