Add IDhApiShadowCullingFrustum and a config for shadow culling

This commit is contained in:
James Seibel
2024-02-10 21:37:59 -06:00
parent 46740f51a7
commit b4269afc9f
6 changed files with 150 additions and 60 deletions
@@ -112,19 +112,6 @@ public interface IDhApiGraphicsConfig extends IDhApiConfigGroup
// advanced graphic settings //
//===========================//
/**
* Sets whether LODs outside the view frustum culling will
* be culled. <br><br>
*
* Disabling this will prevent LODs not rendering on the corner
* of the users vision and may fix issues if LODs appear to
* start/stop rendering incorrectly based on the camera direction,
* but will also reduce FPS.
*
* @since API 1.1.0
*/
IDhApiConfigValue<Boolean> disableFrustumCulling();
/**
* Sets the distance used by the near clip plane to reduce
* overdraw. <br>
@@ -187,4 +174,30 @@ public interface IDhApiGraphicsConfig extends IDhApiConfigGroup
*/
IDhApiConfigValue<ELodShading> lodShading();
/**
* Sets whether LODs outside the view frustum culling will
* be culled. <br><br>
*
* Disabling this will prevent LODs not rendering on the corner
* of the users vision and may fix issues if LODs appear to
* start/stop rendering incorrectly based on the camera direction,
* but will also reduce FPS.
*
* @since API 1.1.0
* @see IDhApiGraphicsConfig#disableShadowFrustumCulling()
*/
IDhApiConfigValue<Boolean> disableFrustumCulling();
/**
* Identical to the other frustum culling option, except that it is
* only used when a shader mod is present using the DH API
* and the shadow pass is being rendered. <br><br>
*
* Disable this if shadows render incorrectly.
*
* @since API 1.1.0
* @see IDhApiGraphicsConfig#disableFrustumCulling()
*/
IDhApiConfigValue<Boolean> disableShadowFrustumCulling();
}
@@ -0,0 +1,40 @@
/*
* This file is part of the Distant Horizons mod
* licensed under the GNU LGPL v3 License.
*
* Copyright (C) 2020-2023 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.distanthorizons.api.interfaces.override.rendering;
import com.seibel.distanthorizons.api.enums.EDhApiDetailLevel;
import com.seibel.distanthorizons.api.interfaces.override.IDhApiOverrideable;
import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
/**
* The culling frustum used during Distant Horizons' shadow pass
* if another mod has enabled Distant Horizons' shadow
* pass via the API.
*
* @see IDhApiCullingFrustum
*
* @author James Seibel
* @version 2024-2-10
* @since API 1.1.0
*/
public interface IDhApiShadowCullingFrustum extends IDhApiCullingFrustum
{
// should be identical to the parent culling frustum
}
@@ -105,10 +105,6 @@ public class DhApiGraphicsConfig implements IDhApiGraphicsConfig
// advanced graphic settings //
//===========================//
@Override
public IDhApiConfigValue<Boolean> disableFrustumCulling()
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Graphics.AdvancedGraphics.disableFrustumCulling); }
@Deprecated
@Override
public IDhApiConfigValue<EOverdrawPrevention> overdrawPrevention()
@@ -150,6 +146,14 @@ public class DhApiGraphicsConfig implements IDhApiGraphicsConfig
public IDhApiConfigValue<ELodShading> lodShading()
{ return new DhApiConfigValue<ELodShading, ELodShading>(Config.Client.Advanced.Graphics.AdvancedGraphics.lodShading); }
@Override
public IDhApiConfigValue<Boolean> disableFrustumCulling()
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Graphics.AdvancedGraphics.disableFrustumCulling); }
@Override
public IDhApiConfigValue<Boolean> disableShadowFrustumCulling()
{ return new DhApiConfigValue<Boolean, Boolean>(Config.Client.Advanced.Graphics.AdvancedGraphics.disableShadowPassFrustumCulling); }
}
@@ -534,18 +534,6 @@ public class Config
public static class AdvancedGraphics
{
public static ConfigEntry<Boolean> disableFrustumCulling = new ConfigEntry.Builder<Boolean>()
.set(false)
.comment(""
+ "If false LODs outside the player's camera \n"
+ "aren't drawn, increasing GPU performance. \n"
+ "\n"
+ "If true all LODs are drawn, even those behind \n"
+ "the player's camera, decreasing GPU performance. \n"
+ "\n"
+ "Disable this if you see LODs disappearing at the corners of your vision.")
.build();
/**
* @deprecated Use overdrawPrevention instead, will be removed when DH updates to MC 1.21 <br>
* After removal a float value will be used to control overdraw instead. <br>
@@ -666,6 +654,29 @@ public class Config
.setPerformance(EConfigEntryPerformance.NONE)
.build();
public static ConfigEntry<Boolean> disableFrustumCulling = new ConfigEntry.Builder<Boolean>()
.set(false)
.comment(""
+ "If false LODs outside the player's camera \n"
+ "aren't drawn, increasing GPU performance. \n"
+ "\n"
+ "If true all LODs are drawn, even those behind \n"
+ "the player's camera, decreasing GPU performance. \n"
+ "\n"
+ "Disable this if you see LODs disappearing at the corners of your vision.")
.build();
public static ConfigEntry<Boolean> disableShadowPassFrustumCulling = new ConfigEntry.Builder<Boolean>()
.set(false)
.comment(""
+ "Identical to the other frustum culling option\n"
+ "only used when a shader mod is present using the DH API\n"
+ "and the shadow pass is being rendered.\n"
+ "\n"
+ "Disable this if shadows render incorrectly.")
.build();
}
}
@@ -20,7 +20,9 @@
package com.seibel.distanthorizons.core.render;
import com.seibel.distanthorizons.api.DhApi;
import com.seibel.distanthorizons.api.interfaces.override.IDhApiOverrideable;
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiCullingFrustum;
import com.seibel.distanthorizons.api.interfaces.override.rendering.IDhApiShadowCullingFrustum;
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
@@ -74,7 +76,6 @@ public class RenderBufferHandler implements AutoCloseable
public F3Screen.MultiDynamicMessage f3Message;
private final IDhApiCullingFrustum cameraFrustum;
private int visibleBufferCount;
private int culledBufferCount;
private int shadowVisibleBufferCount;
@@ -90,7 +91,11 @@ public class RenderBufferHandler implements AutoCloseable
{
this.lodQuadTree = lodQuadTree;
this.cameraFrustum = new DhFrustumBounds();
IDhApiCullingFrustum coreFrustum = DhApi.overrides.get(IDhApiCullingFrustum.class, IOverrideInjector.CORE_PRIORITY);
if (coreFrustum == null)
{
DhApi.overrides.bind(IDhApiCullingFrustum.class, new DhFrustumBounds());
}
this.f3Message = new F3Screen.MultiDynamicMessage(
() ->
@@ -237,35 +242,48 @@ public class RenderBufferHandler implements AutoCloseable
// update the frustum if necessary
boolean enableFrustumCulling = !Config.Client.Advanced.Graphics.AdvancedGraphics.disableFrustumCulling.get();
//====================================//
// get and update the culling frustum //
//====================================//
// get the culling frustum
boolean enableFrustumCulling;
IDhApiCullingFrustum frustum;
boolean isShadowPass = (IRIS_ACCESSOR != null && IRIS_ACCESSOR.isRenderingShadowPass());
if (isShadowPass)
{
enableFrustumCulling = !Config.Client.Advanced.Graphics.AdvancedGraphics.disableShadowPassFrustumCulling.get();
frustum = DhApi.overrides.get(IDhApiShadowCullingFrustum.class);
}
else
{
enableFrustumCulling = !Config.Client.Advanced.Graphics.AdvancedGraphics.disableFrustumCulling.get();
frustum = DhApi.overrides.get(IDhApiCullingFrustum.class);
}
// use the core frustum if no override is present
if (frustum == null)
{
frustum = DhApi.overrides.get(IDhApiCullingFrustum.class, IOverrideInjector.CORE_PRIORITY);
}
IDhApiCullingFrustum frustum = this.cameraFrustum;
// update the frustum if necessary
if (enableFrustumCulling)
{
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));
}
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));
}
@@ -265,10 +265,6 @@
"distanthorizons.config.client.advanced.graphics.advancedGraphics":
"Advanced Graphics Options",
"distanthorizons.config.client.advanced.graphics.advancedGraphics.disableFrustumCulling":
"Disable Frustum Culling",
"distanthorizons.config.client.advanced.graphics.advancedGraphics.disableFrustumCulling.@tooltip":
"If false LODs outside the player's camera \naren't drawn, increasing GPU performance. \n\nIf true all LODs are drawn, even those behind \nthe player's camera, decreasing GPU performance. \n\nDisable this if you see LODs disappearing at the corners of your vision.",
"distanthorizons.config.client.advanced.graphics.advancedGraphics.overdrawPrevention":
"Overdraw Prevention",
"distanthorizons.config.client.advanced.graphics.advancedGraphics.overdrawPrevention.@tooltip":
@@ -305,7 +301,15 @@
"LOD Shading",
"distanthorizons.config.client.advanced.graphics.advancedGraphics.lodShading.@tooltip":
"Defines how LODs should be shaded. \nCan be used to improve shader compatibility.",
"distanthorizons.config.client.advanced.graphics.advancedGraphics.disableFrustumCulling":
"Disable Frustum Culling",
"distanthorizons.config.client.advanced.graphics.advancedGraphics.disableFrustumCulling.@tooltip":
"If false LODs outside the player's camera \naren't drawn, increasing GPU performance. \n\nIf true all LODs are drawn, even those behind \nthe player's camera, decreasing GPU performance. \n\nDisable this if you see LODs disappearing at the corners of your vision.",
"distanthorizons.config.client.advanced.graphics.advancedGraphics.disableShadowPassFrustumCulling":
"Disable Shadow Pass Frustum Culling",
"distanthorizons.config.client.advanced.graphics.advancedGraphics.disableShadowPassFrustumCulling.@tooltip":
"Identical to the other frustum culling option except that it is \nonly used when a shader mod is present using the DH API \nand the shadow pass is being rendered. \n\nDisable this if shadows render incorrectly.",
"distanthorizons.config.client.advanced.worldGenerator":
"World Generator",