Skip to content

Commit 2e1be1d

Browse files
committed
Merge branch 'master' into master-java8
2 parents f733569 + 8f46c96 commit 2e1be1d

6 files changed

Lines changed: 76 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## [1.1.0] - 2025-11-29
4+
5+
### Changed
6+
7+
- Improved the implementation of fast fog, now with better mod compat
8+
9+
### Added
10+
11+
- Added a fog bias config when using ChunkDrawMode=Fast, which can pull in the fog and reduce pop-in
12+
313
## [1.0.7] - 2025-11-24
414

515
### Changed

build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,9 @@ dependencies {
9696

9797
// netherlicious-3.2.8.jar
9898
compileOnly(deobfCurse("netherlicious-385860:4363437"))
99+
100+
101+
// WelcomeToTheJungle-1.0.9-1.7.10.jar
102+
// Here for testing the Fast Fog implementation
103+
// runtimeOnly(deobfCurse("welcometothejungle-246895:2775633"))
99104
}

src/main/java/com/ventooth/beddium/config/TerrainRenderingConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ public final class TerrainRenderingConfig {
6868
@Config.DefaultEnum("Vanilla")
6969
public static DrawModeEnum ChunkDrawMode;
7070

71+
@Config.Name("FastChunkDrawModeFogBias")
72+
@Config.Comment({
73+
"Adds a bias (in blocks) to the fog distance when using Fast Chunk Edge Mode.",
74+
"The default value is set to hide all pop in, but can be adjusted to taste.",
75+
})
76+
@Config.LangKey("config.beddium.terrainrendering.FastChunkDrawModeFogBias")
77+
@Config.DefaultDouble(-16D)
78+
@Config.RangeDouble(min = -16D,
79+
max = 0D)
80+
public static double FastChunkDrawModeFogBias;
81+
7182
@Config.Name("UseMultiDrawIndirect")
7283
@Config.Comment({
7384
"Controls if chunks should be drawn using MultiDrawIndirect.",

src/main/java/com/ventooth/beddium/mixin/mixins/client/TerrainRendering/EntityRendererMixin.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,64 @@
2222

2323
package com.ventooth.beddium.mixin.mixins.client.TerrainRendering;
2424

25+
import com.falsepattern.lib.util.MathUtil;
2526
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
2627
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
2728
import com.ventooth.beddium.config.TerrainRenderingConfig;
2829
import com.ventooth.beddium.modules.TerrainRendering.fog.FogStateTracker;
30+
import lombok.val;
31+
import org.lwjgl.opengl.GL11;
2932
import org.spongepowered.asm.mixin.Mixin;
33+
import org.spongepowered.asm.mixin.Shadow;
3034
import org.spongepowered.asm.mixin.injection.At;
35+
import org.spongepowered.asm.mixin.injection.Inject;
36+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3137

3238
import net.minecraft.client.renderer.EntityRenderer;
3339

3440
import java.nio.FloatBuffer;
3541

3642
@Mixin(EntityRenderer.class)
3743
public abstract class EntityRendererMixin {
44+
@Shadow
45+
private float farPlaneDistance;
46+
47+
@Inject(method = "setupFog",
48+
at = @At(value = "RETURN"))
49+
private void applyFogBias(CallbackInfo ci) {
50+
val fogBias = (float) TerrainRenderingConfig.FastChunkDrawModeFogBias;
51+
if (TerrainRenderingConfig.ChunkDrawMode != TerrainRenderingConfig.DrawModeEnum.Fast || MathUtil.epsilonEquals(fogBias, 0F)) {
52+
return;
53+
}
54+
55+
float fogEnd;
56+
float fogStart;
57+
if (TerrainRenderingConfig.FastFog) {
58+
fogEnd = FogStateTracker.end;
59+
fogStart = FogStateTracker.start;
60+
} else {
61+
fogEnd = GL11.glGetInteger(GL11.GL_FOG_END);
62+
fogStart = GL11.glGetInteger(GL11.GL_FOG_START);
63+
}
64+
val maxFogEnd = this.farPlaneDistance + fogBias;
65+
66+
if (maxFogEnd >= fogEnd || fogStart > fogEnd) {
67+
return;
68+
}
69+
70+
val biasRatio = maxFogEnd / fogEnd;
71+
fogEnd = maxFogEnd;
72+
fogStart *= biasRatio;
73+
74+
GL11.glFogf(GL11.GL_FOG_END, fogEnd);
75+
GL11.glFogf(GL11.GL_FOG_START, fogStart);
76+
77+
if (TerrainRenderingConfig.FastFog) {
78+
FogStateTracker.end = fogEnd;
79+
FogStateTracker.start = fogStart;
80+
}
81+
}
82+
3883
@WrapOperation(method = "setupFog",
3984
at = @At(value = "INVOKE",
4085
target = "Lorg/lwjgl/opengl/GL11;glFog(ILjava/nio/FloatBuffer;)V"))
@@ -75,7 +120,6 @@ private void track_glEnable(int cap, Operation<Void> original) {
75120
original.call(cap);
76121
}
77122

78-
79123
@WrapOperation(method = "renderWorld",
80124
at = @At(value = "INVOKE",
81125
target = "Lorg/lwjgl/opengl/GL11;glDisable(I)V"))

src/main/java/com/ventooth/beddium/modules/TerrainRendering/fog/FogStateTracker.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
public final class FogStateTracker {
3535
static final FloatBuffer color = BufferUtils.createFloatBuffer(16);
3636

37-
static float end = 1000F;
38-
static float start = 1000F;
37+
public static float end = 1000F;
38+
public static float start = 1000F;
3939
static float density = 0.1F;
4040

4141
static boolean isEnabled = false;
@@ -55,7 +55,6 @@ public static void setFromGl() {
5555
density = GL11.glGetInteger(GL11.GL_FOG_DENSITY);
5656
}
5757

58-
@SuppressWarnings("unused")
5958
public static void glFog(int pname, FloatBuffer params) {
6059
if (pname == GL11.GL_FOG_COLOR) {
6160
FogStateTracker.color.put(0, params.get(0));
@@ -65,7 +64,6 @@ public static void glFog(int pname, FloatBuffer params) {
6564
}
6665
}
6766

68-
@SuppressWarnings("unused")
6967
public static void glFogf(int pname, float param) {
7068
switch (pname) {
7169
case GL11.GL_FOG_END -> FogStateTracker.end = param;
@@ -74,21 +72,18 @@ public static void glFogf(int pname, float param) {
7472
}
7573
}
7674

77-
@SuppressWarnings("unused")
7875
public static void glEnable(int cap) {
7976
if (cap == GL11.GL_FOG) {
8077
FogStateTracker.isEnabled = true;
8178
}
8279
}
8380

84-
@SuppressWarnings("unused")
8581
public static void glDisable(int cap) {
8682
if (cap == GL11.GL_FOG) {
8783
FogStateTracker.isEnabled = false;
8884
}
8985
}
9086

91-
@SuppressWarnings("unused")
9287
public static void glFogi(int pname, int param) {
9388
if (pname == GL11.GL_FOG_MODE) {
9489
FogStateTracker.mode = FogStateTracker.fromGLMode(param);

src/main/resources/assets/beddium/lang/en_US.lang

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ config.beddium.terrainrendering.MEGAChunks.tooltip=Larger chunk renderers. One m
2424
config.beddium.terrainrendering.ChunkDrawMode=Chunk Edge Mode
2525
config.beddium.terrainrendering.ChunkDrawMode.tooltip=Changes the way chunks at the world edge are rendered.\nVanilla: Renders "chunk cliffs" at the world edge. Slightly slower,\n but fixes issues such as invisible chunks in minigame servers,\n or reduced render distance.\nFast: Only renders chunks if all of the neighboring chunks are loaded.\n A bit faster than safe, but on some servers this might cause missing\n chunks at map edges,\n and it reduces visual render distance by 1 (the chunks are still present).",
2626

27+
config.beddium.terrainrendering.FastChunkDrawModeFogBias=Fast Chunk Edge Mode Fog Bias
28+
config.beddium.terrainrendering.FastChunkDrawModeFogBias.tooltip=Adds a bias (in blocks) to the fog distance when using Fast Chunk Edge Mode.\nThe default value is set to hide all pop in, but can be adjusted to taste.
29+
2730
config.beddium.terrainrendering.UseMultiDrawIndirect=Multi-Draw Indirect
2831
config.beddium.terrainrendering.UseMultiDrawIndirect.tooltip=Controls if chunks should be drawn using MultiDrawIndirect.\nThis option is a trade off between CPU and GPU overhead when rendering chunks.\nIt is best left disabled in most cases, particularly on Intel iGPUs.\nCan improve performance on render distances beyond 16 if you are CPU limited.
2932

0 commit comments

Comments
 (0)