Add far fade

This commit is contained in:
James Seibel
2026-03-04 07:38:49 -06:00
parent 225c2df8df
commit c3dce412fa
5 changed files with 106 additions and 9 deletions
@@ -38,7 +38,7 @@ import com.seibel.distanthorizons.core.util.objects.Pair;
import com.seibel.distanthorizons.core.util.objects.RollingAverage; import com.seibel.distanthorizons.core.util.objects.RollingAverage;
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil; import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.render.IMcFadeRenderer; import com.seibel.distanthorizons.core.wrapperInterfaces.render.IMcVanillaFadeRenderer;
import com.seibel.distanthorizons.core.wrapperInterfaces.render.IMcTestRenderer; import com.seibel.distanthorizons.core.wrapperInterfaces.render.IMcTestRenderer;
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector; import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
import com.seibel.distanthorizons.core.config.Config; import com.seibel.distanthorizons.core.config.Config;
@@ -645,7 +645,7 @@ public class ClientApi
*/ */
public void renderFadeOpaque() public void renderFadeOpaque()
{ {
IMcFadeRenderer fadeRenderer = SingletonInjector.INSTANCE.get(IMcFadeRenderer.class); IMcVanillaFadeRenderer fadeRenderer = SingletonInjector.INSTANCE.get(IMcVanillaFadeRenderer.class);
if (fadeRenderer == null) if (fadeRenderer == null)
{ {
return; return;
@@ -674,7 +674,7 @@ public class ClientApi
*/ */
public void renderFadeTransparent() public void renderFadeTransparent()
{ {
IMcFadeRenderer fadeRenderer = SingletonInjector.INSTANCE.get(IMcFadeRenderer.class); IMcVanillaFadeRenderer fadeRenderer = SingletonInjector.INSTANCE.get(IMcVanillaFadeRenderer.class);
if (fadeRenderer == null) if (fadeRenderer == null)
{ {
return; return;
@@ -150,6 +150,7 @@ public class McLodRenderer
IMcLodRenderer lodRenderer = SingletonInjector.INSTANCE.get(IMcLodRenderer.class); IMcLodRenderer lodRenderer = SingletonInjector.INSTANCE.get(IMcLodRenderer.class);
IMcSsaoRenderer ssaoRenderer = SingletonInjector.INSTANCE.get(IMcSsaoRenderer.class); IMcSsaoRenderer ssaoRenderer = SingletonInjector.INSTANCE.get(IMcSsaoRenderer.class);
IMcFogRenderer fogRenderer = SingletonInjector.INSTANCE.get(IMcFogRenderer.class); IMcFogRenderer fogRenderer = SingletonInjector.INSTANCE.get(IMcFogRenderer.class);
IMcFarFadeRenderer farFadeRenderer = SingletonInjector.INSTANCE.get(IMcFarFadeRenderer.class);
@@ -205,10 +206,9 @@ public class McLodRenderer
// far plane clip fading // far plane clip fading
if (Config.Client.Advanced.Graphics.Quality.dhFadeFarClipPlane.get()) if (Config.Client.Advanced.Graphics.Quality.dhFadeFarClipPlane.get())
{ {
//profiler.popPush("Fade Far Clip Fade"); profiler.popPush("Fade Far Clip Fade");
//DhFadeRenderer.INSTANCE.render( farFadeRenderer.render(
// new Mat4f(renderParams.mcModelViewMatrix), new Mat4f(renderParams.mcProjectionMatrix), new Mat4f(renderParams.mcModelViewMatrix), new Mat4f(renderParams.mcProjectionMatrix));
// renderParams.partialTicks, profiler);
} }
// fog // fog
@@ -0,0 +1,31 @@
/*
* This file is part of the Distant Horizons mod
* licensed under the GNU LGPL v3 License.
*
* Copyright (C) 2020 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.core.wrapperInterfaces.render;
import com.seibel.distanthorizons.core.util.math.Mat4f;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
public interface IMcFarFadeRenderer extends IBindable
{
void render(Mat4f mcModelViewMatrix, Mat4f mcProjectionMatrix);
}
@@ -19,12 +19,11 @@
package com.seibel.distanthorizons.core.wrapperInterfaces.render; package com.seibel.distanthorizons.core.wrapperInterfaces.render;
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
import com.seibel.distanthorizons.core.util.math.Mat4f; import com.seibel.distanthorizons.core.util.math.Mat4f;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable; import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
public interface IMcFadeRenderer extends IBindable public interface IMcVanillaFadeRenderer extends IBindable
{ {
void render(Mat4f mcModelViewMatrix, Mat4f mcProjectionMatrix, IClientLevelWrapper level); void render(Mat4f mcModelViewMatrix, Mat4f mcProjectionMatrix, IClientLevelWrapper level);
@@ -0,0 +1,67 @@
#version 150 core
in vec2 TexCoord;
out vec4 fragColor;
layout (std140) uniform fragUniformBlock
{
float uStartFadeBlockDistance;
float uEndFadeBlockDistance;
// inverted model view matrix and projection matrix
mat4 uDhInvMvmProj;
};
uniform sampler2D uMcColorTexture;
uniform sampler2D uDhDepthTexture;
uniform sampler2D uDhColorTexture;
vec3 calcViewPosition(float fragmentDepth, mat4 invMvmProj)
{
// normalized device coordinates
vec4 ndc = vec4(TexCoord.xy, fragmentDepth, 1.0);
ndc.xyz = ndc.xyz * 2.0 - 1.0;
vec4 eyeCoord = invMvmProj * ndc;
return eyeCoord.xyz / eyeCoord.w;
}
/**
* Used to fade out vanilla chunks so the transition
* between DH and vanilla is smoother.
*/
void main()
{
// includes both the vanilla chunks as well as DH
vec4 combinedMcDhColor = texture(uMcColorTexture, TexCoord);
// just the DH render pass
vec4 dhColor = texture(uDhColorTexture, TexCoord);
// the DH texture will have white if nothing was written to that pixel.
if (dhColor == vec4(1))
{
// if not done vanilla clouds will render incorrectly at night
dhColor = combinedMcDhColor;
}
float dhFragmentDepth = texture(uDhDepthTexture, TexCoord).r;
vec3 dhVertexWorldPos = calcViewPosition(dhFragmentDepth, uDhInvMvmProj);
float dhFragmentDistance = length(dhVertexWorldPos.xzy);
float startFade = uEndFadeBlockDistance;
float endFade = uStartFadeBlockDistance;
// Smoothly transition between combinedMcDhColor and uDhColorTexture
// as the depth increases from the camera
float fadeStep = smoothstep(startFade, endFade, dhFragmentDistance);
fragColor = mix(combinedMcDhColor, dhColor, fadeStep);
fragColor.a = 1.0;
}