start of vanilla fade logic

This commit is contained in:
James Seibel
2026-02-24 09:57:03 -06:00
parent 87cead607f
commit d1ba402f4d
7 changed files with 216 additions and 30 deletions
@@ -38,6 +38,7 @@ import com.seibel.distanthorizons.core.util.objects.Pair;
import com.seibel.distanthorizons.core.util.objects.RollingAverage;
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.render.IMcFadeRenderer;
import com.seibel.distanthorizons.core.wrapperInterfaces.render.IMcTestRenderer;
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
import com.seibel.distanthorizons.core.config.Config;
@@ -585,7 +586,7 @@ public class ClientApi
boolean renderingCancelled = ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeRenderEvent.class, renderParams);
if (!renderingCancelled)
{
testRenderer.render();
//testRenderer.render();
//LodRenderer.INSTANCE.render(renderParams, profiler);
}
@@ -644,20 +645,28 @@ public class ClientApi
*/
public void renderFadeOpaque()
{
// only fade when DH is rendering
if (Config.Client.Advanced.Debugging.rendererMode.get() != EDhApiRendererMode.DISABLED
&&
(
// only fade when requested
Config.Client.Advanced.Graphics.Quality.vanillaFadeMode.get() == EDhApiMcRenderingFadeMode.DOUBLE_PASS
// or if LOD-only mode is enabled (fading is used to remove the MC render pass)
|| Config.Client.Advanced.Debugging.lodOnlyMode.get()
)
// don't fade when Iris shaders are active, otherwise the rendering can get weird
&& !DhApiRenderProxy.INSTANCE.getDeferTransparentRendering())
IMcFadeRenderer fadeRenderer = SingletonInjector.INSTANCE.get(IMcFadeRenderer.class);
if (fadeRenderer == null)
{
VanillaFadeRenderer.INSTANCE.render(RENDER_STATE.mcModelViewMatrix, RENDER_STATE.mcProjectionMatrix, RENDER_STATE.partialTickTime, RENDER_STATE.clientLevelWrapper);
return;
}
fadeRenderer.render();
//// only fade when DH is rendering
//if (Config.Client.Advanced.Debugging.rendererMode.get() != EDhApiRendererMode.DISABLED
// &&
// (
// // only fade when requested
// Config.Client.Advanced.Graphics.Quality.vanillaFadeMode.get() == EDhApiMcRenderingFadeMode.DOUBLE_PASS
// // or if LOD-only mode is enabled (fading is used to remove the MC render pass)
// || Config.Client.Advanced.Debugging.lodOnlyMode.get()
// )
// // don't fade when Iris shaders are active, otherwise the rendering can get weird
// && !DhApiRenderProxy.INSTANCE.getDeferTransparentRendering())
//{
// VanillaFadeRenderer.INSTANCE.render(RENDER_STATE.mcModelViewMatrix, RENDER_STATE.mcProjectionMatrix, RENDER_STATE.partialTickTime, RENDER_STATE.clientLevelWrapper);
//}
}
/**
* The second fade pass.
@@ -666,23 +675,25 @@ public class ClientApi
*/
public void renderFadeTransparent()
{
// only fade when DH is rendering
if (Config.Client.Advanced.Debugging.rendererMode.get() != EDhApiRendererMode.DISABLED)
{
boolean renderFade =
(
// only fade when requested
Config.Client.Advanced.Graphics.Quality.vanillaFadeMode.get() != EDhApiMcRenderingFadeMode.NONE
// or if LOD-only mode is enabled (fading is used to remove the MC render pass)
|| Config.Client.Advanced.Debugging.lodOnlyMode.get()
)
// don't fade when Iris shaders are active, otherwise the rendering can get weird
&& !DhApiRenderProxy.INSTANCE.getDeferTransparentRendering();
if (renderFade)
{
VanillaFadeRenderer.INSTANCE.render(RENDER_STATE.mcModelViewMatrix, RENDER_STATE.mcProjectionMatrix, RENDER_STATE.partialTickTime, RENDER_STATE.clientLevelWrapper);
}
}
//// only fade when DH is rendering
//if (Config.Client.Advanced.Debugging.rendererMode.get() != EDhApiRendererMode.DISABLED)
//{
// boolean renderFade =
// (
// // only fade when requested
// Config.Client.Advanced.Graphics.Quality.vanillaFadeMode.get() != EDhApiMcRenderingFadeMode.NONE
// // or if LOD-only mode is enabled (fading is used to remove the MC render pass)
// || Config.Client.Advanced.Debugging.lodOnlyMode.get()
// )
// // don't fade when Iris shaders are active, otherwise the rendering can get weird
// && !DhApiRenderProxy.INSTANCE.getDeferTransparentRendering();
// if (renderFade)
// {
// VanillaFadeRenderer.INSTANCE.render(RENDER_STATE.mcModelViewMatrix, RENDER_STATE.mcProjectionMatrix, RENDER_STATE.partialTickTime, RENDER_STATE.clientLevelWrapper);
// }
//}
}
///endregion
@@ -40,6 +40,7 @@ import java.nio.ByteOrder;
* to the center of the screen to confirm DH's
* apply shader is running correctly
*/
@Deprecated
public class TestRenderer
{
public static final DhLogger LOGGER = new DhLoggerBuilder().build();
@@ -0,0 +1,29 @@
/*
* 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.coreapi.interfaces.dependencyInjection.IBindable;
public interface IMcFadeRenderer extends IBindable
{
void render();
}
@@ -0,0 +1,24 @@
#version 150 core
in vec2 TexCoord;
in vec4 fColor;
out vec4 fragColor;
uniform sampler2D uDhDepthTexture;
// DH fade frag test
void main()
{
float dhFragmentDepth = texture(uDhDepthTexture, TexCoord).r;
if (dhFragmentDepth == 0)
{
// no MC depth
fragColor = fColor;
}
else
{
// MC depth drawn
fragColor = vec4(0, 0, 1, 1); // green
}
}
@@ -0,0 +1,91 @@
#version 150 core
in vec2 TexCoord;
out vec4 fragColor;
// inverted model view matrix and projection matrix
uniform mat4 uDhInvMvmProj;
uniform mat4 uMcInvMvmProj;
uniform sampler2D uMcDepthTexture;
uniform sampler2D uDhDepthTexture;
uniform sampler2D uCombinedMcDhColorTexture;
uniform sampler2D uDhColorTexture;
uniform float uStartFadeBlockDistance;
uniform float uEndFadeBlockDistance;
uniform float uMaxLevelHeight;
uniform bool uOnlyRenderLods;
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(uCombinedMcDhColorTexture, TexCoord);
// just the DH render pass
vec4 dhColor = texture(uDhColorTexture, TexCoord);
// completely remove the MC render pass to only show LODs
// useful for debugging/troubleshooting, but doesn't improve performance since MC is still rendering
if (uOnlyRenderLods)
{
fragColor = dhColor;
return;
}
// ignore anything that DH hasn't drawn to
// We don't use DH's depth here because it would prevent the fade from running before DH has loaded
if (dhColor == vec4(1))
{
// if not done vanilla clouds will render incorrectly at night
dhColor = combinedMcDhColor;
}
float mcFragmentDepth = texture(uMcDepthTexture, TexCoord).r;
float dhFragmentDepth = texture(uDhDepthTexture, TexCoord).r;
vec3 dhVertexWorldPos = calcViewPosition(dhFragmentDepth, uDhInvMvmProj);
// this is a work around to prevent MC clouds rendering behind DH clouds
if (dhVertexWorldPos.y > uMaxLevelHeight)
{
fragColor = vec4(combinedMcDhColor.rgb, 0.0);
}
// a fragment depth of "1" means the fragment wasn't drawn to,
// we only want to fade vanilla rendered objects, not to the sky or LODs
else if (mcFragmentDepth < 1.0)
{
// fade based on distance from the camera
vec3 mcVertexWorldPos = calcViewPosition(mcFragmentDepth, uMcInvMvmProj);
float mcFragmentDistance = length(mcVertexWorldPos.xzy);
// Smoothly transition between combinedMcDhColor and uDhColorTexture
// as the depth increases from the camera
float fadeStep = smoothstep(uStartFadeBlockDistance, uEndFadeBlockDistance, mcFragmentDistance);
fragColor = mix(combinedMcDhColor, dhColor, fadeStep);
fragColor.a = 1.0;
}
else
{
fragColor = vec4(combinedMcDhColor.rgb, 0.0);
}
}
@@ -0,0 +1,15 @@
#version 150 core
in vec2 vPosition;
in vec4 vColor;
out vec4 fColor;
out vec2 TexCoord;
// DH vert fade test
void main()
{
gl_Position = vec4(vPosition, 0.0, 1.0);
fColor = vec4(vPosition, 0.0, 1.0);
TexCoord = vPosition.xy * 0.5 + 0.5;
}
@@ -0,0 +1,15 @@
#version 150 core
in vec2 vPosition;
out vec2 TexCoord;
/**
* This is specifically used by application shaders.
* IE post process or pixel transfer shaders, anything that is rendered using a single rectangle.
*/
void main()
{
gl_Position = vec4(vPosition, 1.0, 1.0);
TexCoord = vPosition.xy * 0.5 + 0.5;
}