add EDhRenderDepth
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.seibel.distanthorizons.core.render;
|
||||
|
||||
/**
|
||||
* FORWARD_Z, <br>
|
||||
* REVERSE_Z, <br>
|
||||
*/
|
||||
public enum EDhRenderDepth
|
||||
{
|
||||
/**
|
||||
* AKA Zero to One <br>
|
||||
* MC 26.1.2 and older (OpenGL) = false (near = 0.0f, far = 1.0f)
|
||||
*/
|
||||
FORWARD_Z(0.0f, 1.0f),
|
||||
/**
|
||||
* AKA One to Zero <br>
|
||||
* MC 26.2.0 and newer (Vulkan/GL) = true (near = 1.0f, far = 0.0f)
|
||||
*/
|
||||
REVERSE_Z(1.0f, 0.0f);
|
||||
|
||||
|
||||
public final float nearDepth;
|
||||
public final float farDepth;
|
||||
|
||||
EDhRenderDepth(float nearDepth, float farDepth)
|
||||
{
|
||||
this.nearDepth = nearDepth;
|
||||
this.farDepth = farDepth;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -27,9 +27,11 @@ import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.logging.DhLogger;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.render.EDhRenderDepth;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IIrisAccessor;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
||||
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||
@@ -45,6 +47,7 @@ public class RenderUtil
|
||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
|
||||
private static final IIrisAccessor IRIS_ACCESSOR = ModAccessorInjector.INSTANCE.get(IIrisAccessor.class);
|
||||
private static final AbstractDhRenderApiDefinition RENDER_API_DEF = SingletonInjector.INSTANCE.get(AbstractDhRenderApiDefinition.class);
|
||||
|
||||
/**
|
||||
* all speeds are measured in blocks per second
|
||||
@@ -91,8 +94,18 @@ public class RenderUtil
|
||||
|
||||
// Create a copy of the current matrix, so it won't be modified.
|
||||
Mat4f lodProj = new Mat4f(mcProjMat);
|
||||
|
||||
|
||||
// Set new far and near clip plane values.
|
||||
lodProj.setClipPlanes(nearClipDist, farClipDist);
|
||||
if (RENDER_API_DEF.getRenderDepth() == EDhRenderDepth.FORWARD_Z)
|
||||
{
|
||||
lodProj.setClipPlanes(nearClipDist, farClipDist, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
lodProj.setClipPlanes(farClipDist, nearClipDist, false);
|
||||
}
|
||||
|
||||
return lodProj;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
package com.seibel.distanthorizons.core.util.math;
|
||||
|
||||
import com.seibel.distanthorizons.api.objects.math.DhApiMat4f;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.AbstractDhRenderApiDefinition;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Matrix4fc;
|
||||
|
||||
@@ -234,14 +236,11 @@ public class Mat4f extends DhApiMat4f
|
||||
* @param nearClip New near clipping plane value.
|
||||
* @param farClip New far clipping plane value.
|
||||
*/
|
||||
public void setClipPlanes(float nearClip, float farClip)
|
||||
public void setClipPlanes(float nearClip, float farClip, boolean zZeroToOne)
|
||||
{
|
||||
//convert to matrix values, formula copied from a textbook / openGL specification.
|
||||
float matNearClip = -((farClip + nearClip) / (farClip - nearClip));
|
||||
float matFarClip = -((2 * farClip * nearClip) / (farClip - nearClip));
|
||||
//set new values for the clip planes.
|
||||
this.m22 = matNearClip;
|
||||
this.m23 = matFarClip;
|
||||
//convert to matrix values, formula copied JOML's implementation to match Minecraft
|
||||
this.m22 = (zZeroToOne ? farClip : farClip + nearClip) / (nearClip - farClip);
|
||||
this.m23 = (zZeroToOne ? farClip : farClip + farClip) * nearClip / (nearClip - farClip);
|
||||
}
|
||||
|
||||
public Mat4f copy() { return new Mat4f(this); }
|
||||
|
||||
+3
@@ -2,6 +2,7 @@ package com.seibel.distanthorizons.core.wrapperInterfaces.render;
|
||||
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.jar.EPlatform;
|
||||
import com.seibel.distanthorizons.core.render.EDhRenderDepth;
|
||||
import com.seibel.distanthorizons.core.render.renderer.AbstractDebugWireframeRenderer;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.IDhGenericObjectVertexBufferContainer;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.render.objects.ILodContainerUniformBufferWrapper;
|
||||
@@ -29,6 +30,8 @@ public abstract class AbstractDhRenderApiDefinition implements IBindable
|
||||
*/
|
||||
public boolean useSingleIbo() { return this.useSingleIbo; }
|
||||
|
||||
public abstract EDhRenderDepth getRenderDepth();
|
||||
|
||||
//endregion
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user