Improve terrain fog quality and refactor cloud rendering #52

Merged
embeddedt merged 8 commits from rdh/celeritas:sky-fog into stonecutter 2026-11-19 21:51:49 -05:00
23 changed files with 357 additions and 68 deletions
Showing only changes of commit 438e706fe8 - Show all commits

No files matched your search

@@ -87,7 +87,7 @@ public class TerrainDrawBench {
} }
@Override @Override
public ChunkShaderComponent.Factory<?> getFogMode() { public ChunkShaderComponent.Factory<?> getBaseFogMode() {
return ChunkFogMode.NONE; return ChunkFogMode.NONE;
} }
}; };
@@ -99,6 +99,8 @@ public class SodiumGameOptions implements OptionStorage<SodiumGameOptions> {
public int chunkFadeInDuration = 0; public int chunkFadeInDuration = 0;
public boolean useSkyFog = false;
public boolean useRgssTextureFiltering = false; public boolean useRgssTextureFiltering = false;
public int legacyBiomeBlendRadius = 0; public int legacyBiomeBlendRadius = 0;
@@ -37,6 +37,14 @@ public class CommonOptionPages {
.setBinding((opts, value) -> opts.quality.chunkFadeInDuration = value, opts -> opts.quality.chunkFadeInDuration) .setBinding((opts, value) -> opts.quality.chunkFadeInDuration = value, opts -> opts.quality.chunkFadeInDuration)
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD) .setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
.build()) .build())
.add(OptionImpl.createBuilder(boolean.class, sodiumOpts)
.setId(StandardOptions.Option.SKY_FOG.cast())
.setName(TextComponent.translatable("celeritas.options.sky_fog.name"))
.setTooltip(TextComponent.translatable("celeritas.options.sky_fog.tooltip"))
.setControl(TickBoxControl::new)
.setImpact(OptionImpact.LOW)
.setBinding((opts, value) -> opts.quality.useSkyFog = value, opts -> opts.quality.useSkyFog)
.build())
.build(); .build();
} }
@@ -14,5 +14,22 @@ public interface FogService {
int getFogShapeIndex(); int getFogShapeIndex();
float getFogCutoff(); float getFogCutoff();
float[] getFogColor(); float[] getFogColor();
ChunkShaderComponent.Factory<?> getFogMode();
ChunkShaderComponent.Factory<?> getBaseFogMode();
default ChunkShaderComponent.Factory<?> getFogMode() {
return SkyFog.select(this.getBaseFogMode());
}
default boolean useSkyFog() {
return false;
}
default float getSkyFogEdgeStart() {
return this.getFogStart();
}
default float getSkyFogEdgeEnd() {
return this.getFogEnd();
}
} }
@@ -0,0 +1,134 @@
package org.embeddedt.embeddium.impl.render.chunk.fog;
import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformInt;
import org.embeddedt.embeddium.impl.render.ShaderModBridge;
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderComponent;
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderEnvironment;
import org.taumc.celeritas.lwjgl.GL11;
import org.taumc.celeritas.lwjgl.GL13;
import java.util.ArrayList;
import java.util.Collection;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import static org.taumc.celeritas.lwjgl.LWJGLServiceProvider.LWJGL;
public final class SkyFog {
public static final int TEXTURE_UNIT = 14;
private static final Map<ChunkShaderComponent.Factory<?>, Variant> VARIANTS = new IdentityHashMap<>();
private static int texture, width, height;
private static boolean captured;
private SkyFog() {
}
public static boolean isEnabled(FogService fogService) {
return fogService.useSkyFog() && !ShaderModBridge.areShadersEnabled();
}
public static boolean isCaptured() {
return captured;
}
public static void invalidate() {
captured = false;
}
public static void capture(int width, int height) {
int previous = bind();
if (SkyFog.width != width || SkyFog.height != height) {
SkyFog.width = width;
SkyFog.height = height;
LWJGL.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, null);
// texelFetch ignores filtering, but the default mipmapped min filter would leave the texture incomplete
LWJGL.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
LWJGL.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
}
LWJGL.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height);
LWJGL.glActiveTexture(previous);
captured = true;
}
public static ChunkShaderComponent.Factory<?> select(ChunkShaderComponent.Factory<?> fog) {
if (!captured) {
return fog;
}
Collection<String> defines = fog.getDefines();
if (!defines.contains("USE_FOG_SMOOTH") && !defines.contains("USE_FOG_POSTMODERN")) {
return fog;
}
return VARIANTS.computeIfAbsent(fog, Variant::new);
}
public static void delete() {
if (texture != 0) {
LWJGL.glDeleteTextures(texture);
texture = 0;
width = 0;
height = 0;
}
captured = false;
}
private static int bind() {
if (texture == 0) {
texture = LWJGL.glGenTextures();
}
int previous = LWJGL.glGetInteger(GL13.GL_ACTIVE_TEXTURE);
LWJGL.glActiveTexture(GL13.GL_TEXTURE0 + TEXTURE_UNIT);
LWJGL.glBindTexture(GL11.GL_TEXTURE_2D, texture);
return previous;
}
private static final class Variant implements ChunkShaderComponent.Factory<ChunkShaderComponent> {
private final ChunkShaderComponent.Factory<?> fog;
private final List<String> defines;
private Variant(ChunkShaderComponent.Factory<?> fog) {
this.fog = fog;
this.defines = new ArrayList<>(fog.getDefines());
this.defines.add("USE_SKY_FOG");
}
@Override
public ChunkShaderComponent create(ShaderBindingContext context, ChunkShaderEnvironment environment) {
ChunkShaderComponent fog = this.fog.create(context, environment);
FogService fogService = environment.fogService();
GlUniformInt sampler = context.bindUniformIfPresent("u_SkyTex", GlUniformInt::new);
GlUniformFloat edgeStart = context.bindUniformIfPresent("u_SkyFogEdgeStart", GlUniformFloat::new);
GlUniformFloat edgeEnd = context.bindUniformIfPresent("u_SkyFogEdgeEnd", GlUniformFloat::new);
return () -> {
fog.setup();
if (sampler != null) {
sampler.setInt(TEXTURE_UNIT);
LWJGL.glActiveTexture(bind());
}
if (edgeStart != null) {
edgeStart.setFloat(fogService.getSkyFogEdgeStart());
edgeEnd.setFloat(fogService.getSkyFogEdgeEnd());
}
};
}
@Override
public Collection<String> getDefines() {
return this.defines;
}
}
}
@@ -81,7 +81,7 @@ public abstract class ChunkShaderFogComponent implements ChunkShaderComponent {
super(environment.fogService()); super(environment.fogService());
this.uFogColor = context.bindUniform("u_FogColor", GlUniformFloat4v::new); this.uFogColor = context.bindUniform("u_FogColor", GlUniformFloat4v::new);
this.uFogShape = context.bindUniform("u_FogShape", GlUniformInt::new); this.uFogShape = context.bindUniformIfPresent("u_FogShape", GlUniformInt::new);
this.uFogStart = context.bindUniform("u_FogStart", GlUniformFloat::new); this.uFogStart = context.bindUniform("u_FogStart", GlUniformFloat::new);
this.uFogEnd = context.bindUniform("u_FogEnd", GlUniformFloat::new); this.uFogEnd = context.bindUniform("u_FogEnd", GlUniformFloat::new);
} }
@@ -89,7 +89,9 @@ public abstract class ChunkShaderFogComponent implements ChunkShaderComponent {
@Override @Override
public void setup() { public void setup() {
this.uFogColor.set(this.fogService.getFogColor()); this.uFogColor.set(this.fogService.getFogColor());
if (this.uFogShape != null) {
this.uFogShape.set(this.fogService.getFogShapeIndex()); this.uFogShape.set(this.fogService.getFogShapeIndex());
}
this.uFogStart.set(this.fogService.getFogStart()); this.uFogStart.set(this.fogService.getFogStart());
this.uFogEnd.set(this.fogService.getFogEnd()); this.uFogEnd.set(this.fogService.getFogEnd());
@@ -8,6 +8,7 @@ import org.embeddedt.embeddium.impl.render.chunk.ChunkRenderMatrices;
import org.embeddedt.embeddium.impl.render.chunk.RenderPassConfiguration; import org.embeddedt.embeddium.impl.render.chunk.RenderPassConfiguration;
import org.embeddedt.embeddium.impl.render.chunk.RenderSectionManager; import org.embeddedt.embeddium.impl.render.chunk.RenderSectionManager;
import org.embeddedt.embeddium.impl.render.chunk.data.MinecraftBuiltRenderSectionData; import org.embeddedt.embeddium.impl.render.chunk.data.MinecraftBuiltRenderSectionData;
import org.embeddedt.embeddium.impl.render.chunk.fog.SkyFog;
import org.embeddedt.embeddium.impl.render.chunk.lists.ChunkRenderList; import org.embeddedt.embeddium.impl.render.chunk.lists.ChunkRenderList;
import org.embeddedt.embeddium.impl.render.chunk.lists.SortedRenderLists; import org.embeddedt.embeddium.impl.render.chunk.lists.SortedRenderLists;
import org.embeddedt.embeddium.impl.render.chunk.map.ChunkTracker; import org.embeddedt.embeddium.impl.render.chunk.map.ChunkTracker;
@@ -18,10 +19,13 @@ import org.embeddedt.embeddium.impl.render.viewport.Viewport;
import org.embeddedt.embeddium.impl.util.*; import org.embeddedt.embeddium.impl.util.*;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.taumc.celeritas.lwjgl.GL11;
import java.util.*; import java.util.*;
import java.util.function.Consumer; import java.util.function.Consumer;
import static org.taumc.celeritas.lwjgl.LWJGLServiceProvider.LWJGL;
/** /**
* Provides an extension to a game's regular world renderer. * Provides an extension to a game's regular world renderer.
*/ */
@@ -64,6 +68,8 @@ public abstract class SimpleWorldRenderer<WORLD, SECTIONMANAGER extends RenderSe
} }
protected void unloadWorld() { protected void unloadWorld() {
SkyFog.delete();
if (this.renderSectionManager != null) { if (this.renderSectionManager != null) {
this.renderSectionManager.destroy(); this.renderSectionManager.destroy();
this.renderSectionManager = null; this.renderSectionManager = null;
@@ -113,6 +119,7 @@ public abstract class SimpleWorldRenderer<WORLD, SECTIONMANAGER extends RenderSe
@Deprecated(forRemoval = true) int frame, @Deprecated(forRemoval = true) int frame,
boolean spectator, boolean spectator,
boolean updateChunksImmediately) { boolean updateChunksImmediately) {
SkyFog.invalidate();
NativeBuffer.reclaim(false); NativeBuffer.reclaim(false);
// When a shadow pass preceded this one, it joined the previous frame's searches, applied the chunk events // When a shadow pass preceded this one, it joined the previous frame's searches, applied the chunk events
@@ -209,6 +216,10 @@ public abstract class SimpleWorldRenderer<WORLD, SECTIONMANAGER extends RenderSe
* Performs a render pass for the given {@link LAYER} and draws all visible chunks for it. * Performs a render pass for the given {@link LAYER} and draws all visible chunks for it.
*/ */
public void drawChunkLayer(LAYER renderLayer, double x, double y, double z) { public void drawChunkLayer(LAYER renderLayer, double x, double y, double z) {
if (!SkyFog.isCaptured() && SkyFog.isEnabled(this.renderSectionManager.getFogService())) {
this.captureSkyFog();
}
ChunkRenderMatrices matrices = createChunkRenderMatrices(); ChunkRenderMatrices matrices = createChunkRenderMatrices();
Collection<TerrainRenderPass> passes = this.renderSectionManager.getRenderPassConfiguration().vanillaRenderStages().get(renderLayer); Collection<TerrainRenderPass> passes = this.renderSectionManager.getRenderPassConfiguration().vanillaRenderStages().get(renderLayer);
@@ -222,6 +233,12 @@ public abstract class SimpleWorldRenderer<WORLD, SECTIONMANAGER extends RenderSe
} }
} }
protected void captureSkyFog() {
int[] viewport = new int[4];
LWJGL.glGetIntegerv(GL11.GL_VIEWPORT, viewport);
SkyFog.capture(viewport[2], viewport[3]);
}
public void reload() { public void reload() {
if (this.world == null) { if (this.world == null) {
return; return;
@@ -75,6 +75,7 @@ public final class StandardOptions {
public static final OptionIdentifier<Void> USE_FASTER_CLOUDS = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "use_faster_clouds"); public static final OptionIdentifier<Void> USE_FASTER_CLOUDS = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "use_faster_clouds");
public static final OptionIdentifier<Void> ASYNC_GRAPH_SEARCH = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "async_graph_search"); public static final OptionIdentifier<Void> ASYNC_GRAPH_SEARCH = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "async_graph_search");
public static final OptionIdentifier<Void> CHUNK_FADE_IN_DURATION = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "chunk_fade_in_duration"); public static final OptionIdentifier<Void> CHUNK_FADE_IN_DURATION = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "chunk_fade_in_duration");
public static final OptionIdentifier<Void> SKY_FOG = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "sky_fog");
public static final OptionIdentifier<Void> RGSS_TEXTURE_FILTERING = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "rgss_texture_filtering"); public static final OptionIdentifier<Void> RGSS_TEXTURE_FILTERING = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "rgss_texture_filtering");
public static final OptionIdentifier<Void> RASTER_OCCLUSION_CULLING = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "raster_occlusion_culling"); public static final OptionIdentifier<Void> RASTER_OCCLUSION_CULLING = OptionIdentifier.create(EMBEDDIUM_MOD_ID, "raster_occlusion_culling");
} }
@@ -30,25 +30,6 @@ in float v_FragDistance;
uniform sampler2D u_BlockTex; // The block texture uniform sampler2D u_BlockTex; // The block texture
uniform int u_FogShape;
uniform vec4 u_FogColor; // The color of the shader fog
#ifdef USE_FOG_SMOOTH
uniform float u_FogStart; // The starting position of the shader fog
uniform float u_FogEnd; // The ending position of the shader fog
#endif
#ifdef USE_FOG_POSTMODERN
uniform float u_RenderDistFogStart;
uniform float u_RenderDistFogEnd;
uniform float u_EnvFogStart;
uniform float u_EnvFogEnd;
#endif
#if defined(USE_FOG_EXP) || defined(USE_FOG_EXP2)
uniform float u_FogDensity; // The density of the shader fog
#endif
#ifndef LEGACY #ifndef LEGACY
out vec4 fragColor; // The output fragment for the color framebuffer out vec4 fragColor; // The output fragment for the color framebuffer
#else #else
@@ -78,14 +59,14 @@ void main() {
#if defined(CHUNK_FADE_IN_DURATION_MS) && CHUNK_FADE_IN_DURATION_MS > 0 #if defined(CHUNK_FADE_IN_DURATION_MS) && CHUNK_FADE_IN_DURATION_MS > 0
// Make chunk fade in over a short duration // Make chunk fade in over a short duration
diffuseColor = vec4(mix(u_FogColor.rgb, diffuseColor.rgb, (clamp(v_ChunkAgeMs, 0, CHUNK_FADE_IN_DURATION_MS) / CHUNK_FADE_IN_DURATION_MS)), diffuseColor.a); diffuseColor = vec4(mix(_fogBackground(u_FogColor), diffuseColor.rgb, (clamp(v_ChunkAgeMs, 0, CHUNK_FADE_IN_DURATION_MS) / CHUNK_FADE_IN_DURATION_MS)), diffuseColor.a);
#endif #endif
#if defined(USE_FOG_POSTMODERN) #if defined(USE_FOG_POSTMODERN)
float fogValue = max(_linearFogValue(v_CylindricalFragDistance, u_RenderDistFogStart, u_RenderDistFogEnd), fragColor = _blendFog(diffuseColor,
_linearFogValue(v_SphericalFragDistance, u_EnvFogStart, u_EnvFogEnd)); _linearFogValue(v_SphericalFragDistance, u_EnvFogStart, u_EnvFogEnd),
_linearFogValue(v_CylindricalFragDistance, u_RenderDistFogStart, u_RenderDistFogEnd),
fragColor = vec4(mix(diffuseColor.rgb, u_FogColor.rgb, fogValue * u_FogColor.a), diffuseColor.a); u_FogColor);
#else // Legacy fog #else // Legacy fog
float fragDistance; float fragDistance;
if (u_FogShape == FOG_SHAPE_PLANAR) { if (u_FogShape == FOG_SHAPE_PLANAR) {
@@ -34,8 +34,6 @@ out float v_CylindricalFragDistance;
out float v_FragDistance; out float v_FragDistance;
#endif #endif
uniform int u_FogShape;
uniform vec3 u_RegionOffset; uniform vec3 u_RegionOffset;
#if defined(USE_FOG) && defined(CHUNK_FADE_IN_DURATION_MS) && CHUNK_FADE_IN_DURATION_MS > 0 #if defined(USE_FOG) && defined(CHUNK_FADE_IN_DURATION_MS) && CHUNK_FADE_IN_DURATION_MS > 0
@@ -4,9 +4,6 @@
uniform mat4 ProjMat; uniform mat4 ProjMat;
uniform vec4 ColorModulator; uniform vec4 ColorModulator;
uniform vec4 FogColor;
uniform float FogStart;
uniform float FogEnd;
in vec4 vertexColor; in vec4 vertexColor;
in float vertexDistance; in float vertexDistance;
@@ -21,6 +18,6 @@ void main() {
discard; discard;
} }
fragColor = _linearFog(color, vertexDistance, FogColor, FogStart, FogEnd); fragColor = _linearFog(color, vertexDistance, u_FogColor, u_FogStart, u_FogEnd);
} }
@@ -5,7 +5,6 @@ in vec4 Color;
uniform mat4 ModelViewMat; uniform mat4 ModelViewMat;
uniform mat4 ProjMat; uniform mat4 ProjMat;
uniform int FogShape;
out float vertexDistance; out float vertexDistance;
out vec4 vertexColor; out vec4 vertexColor;
@@ -2,19 +2,40 @@ const int FOG_SHAPE_SPHERICAL = 0;
const int FOG_SHAPE_CYLINDRICAL = 1; const int FOG_SHAPE_CYLINDRICAL = 1;
const int FOG_SHAPE_PLANAR = 2; const int FOG_SHAPE_PLANAR = 2;
vec4 _linearFog(vec4 fragColor, float fragDistance, vec4 fogColor, float fogStart, float fogEnd) { uniform int u_FogShape;
#ifdef USE_FOG uniform vec4 u_FogColor;
if (fragDistance <= fogStart) {
return fragColor;
}
float factor = fragDistance < fogEnd ? smoothstep(fogStart, fogEnd, fragDistance) : 1.0; // alpha value of fog is used as a weight
vec3 blended = mix(fragColor.rgb, fogColor.rgb, factor * fogColor.a);
return vec4(blended, fragColor.a); // alpha value of fragment cannot be modified #ifdef USE_FOG_SMOOTH
#else uniform float u_FogStart;
return fragColor; uniform float u_FogEnd;
#endif #endif
#ifdef USE_FOG_POSTMODERN
uniform float u_RenderDistFogStart;
uniform float u_RenderDistFogEnd;
uniform float u_EnvFogStart;
uniform float u_EnvFogEnd;
#endif
#if defined(USE_FOG_EXP) || defined(USE_FOG_EXP2)
uniform float u_FogDensity;
#endif
#if defined(USE_SKY_FOG) && defined(FRAGMENT_SHADER)
#define CELERITAS_SKY_FOG
uniform sampler2D u_SkyTex;
uniform float u_SkyFogEdgeStart;
uniform float u_SkyFogEdgeEnd;
#ifdef LEGACY
#define texelFetch texelFetch2D
#endif
vec3 _skyColor() {
return texelFetch(u_SkyTex, ivec2(gl_FragCoord.xy), 0).rgb;
} }
#endif
float _linearFogValue(float fragDistance, float fogStart, float fogEnd) { float _linearFogValue(float fragDistance, float fogStart, float fogEnd) {
#ifdef USE_FOG #ifdef USE_FOG
@@ -30,6 +51,44 @@ float _linearFogValue(float fragDistance, float fogStart, float fogEnd) {
#endif #endif
} }
vec3 _fogBackground(vec4 fogColor) {
#ifdef CELERITAS_SKY_FOG
return _skyColor();
#else
return fogColor.rgb;
#endif
}
vec4 _blendFog(vec4 fragColor, float environment, float edge, vec4 fogColor) {
float fogValue = max(environment, edge);
if (fogValue <= 0.0) {
return fragColor;
}
#ifdef CELERITAS_SKY_FOG
vec3 target = mix(fogColor.rgb, _skyColor(), max(edge / fogValue, smoothstep(0.9, 1.0, environment)));
#else
vec3 target = fogColor.rgb;
#endif
return vec4(mix(fragColor.rgb, target, fogValue * fogColor.a), fragColor.a);
}
vec4 _linearFog(vec4 fragColor, float fragDistance, vec4 fogColor, float fogStart, float fogEnd) {
#ifdef USE_FOG
float environment = _linearFogValue(fragDistance, fogStart, fogEnd);
#ifdef CELERITAS_SKY_FOG
float edge = _linearFogValue(fragDistance, u_SkyFogEdgeStart, u_SkyFogEdgeEnd);
#else
float edge = environment;
#endif
return _blendFog(fragColor, environment, edge, fogColor);
#else
return fragColor;
#endif
}
vec4 _exp2Fog(vec4 fragColor, float fragDistance, vec4 fogColor, float fogDensity) { vec4 _exp2Fog(vec4 fragColor, float fragDistance, vec4 fogColor, float fogDensity) {
#ifdef USE_FOG #ifdef USE_FOG
float dist = fragDistance * fogDensity; float dist = fragDistance * fogDensity;
@@ -10,6 +10,7 @@ import org.taumc.celeritas.api.options.control.SliderControl;
import org.taumc.celeritas.api.options.control.TickBoxControl; import org.taumc.celeritas.api.options.control.TickBoxControl;
import org.embeddedt.embeddium.impl.gui.SodiumGameOptions; import org.embeddedt.embeddium.impl.gui.SodiumGameOptions;
import org.embeddedt.embeddium.impl.gui.framework.TextComponent; import org.embeddedt.embeddium.impl.gui.framework.TextComponent;
import org.embeddedt.embeddium.impl.gui.options.CommonOptionPages;
import org.lwjgl.opengl.Display; import org.lwjgl.opengl.Display;
import org.taumc.celeritas.CeleritasVintage; import org.taumc.celeritas.CeleritasVintage;
import org.taumc.celeritas.api.options.structure.OptionFlag; import org.taumc.celeritas.api.options.structure.OptionFlag;
@@ -221,6 +222,14 @@ public class SodiumGameOptionPages {
.setBinding((opts, value) -> opts.quality.chunkFadeInDuration = value, opts -> opts.quality.chunkFadeInDuration) .setBinding((opts, value) -> opts.quality.chunkFadeInDuration = value, opts -> opts.quality.chunkFadeInDuration)
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD) .setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
.build()) .build())
.add(OptionImpl.createBuilder(boolean.class, sodiumOpts)
.setId(StandardOptions.Option.SKY_FOG.cast())
.setName(TextComponent.translatable("celeritas.options.sky_fog.name"))
.setTooltip(TextComponent.translatable("celeritas.options.sky_fog.tooltip"))
.setControl(TickBoxControl::new)
.setImpact(OptionImpact.LOW)
.setBinding((opts, value) -> opts.quality.useSkyFog = value, opts -> opts.quality.useSkyFog)
.build())
.add(OptionImpl.createBuilder(boolean.class, vanillaOpts) .add(OptionImpl.createBuilder(boolean.class, vanillaOpts)
.setId(StandardOptions.Option.ENTITY_SHADOWS.cast()) .setId(StandardOptions.Option.ENTITY_SHADOWS.cast())
.setName(TextComponent.translatable("options.entityShadows")) .setName(TextComponent.translatable("options.entityShadows"))
@@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import org.embeddedt.embeddium.impl.render.chunk.fog.FogService; import org.embeddedt.embeddium.impl.render.chunk.fog.FogService;
import org.taumc.celeritas.CeleritasVintage;
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkFogMode; import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkFogMode;
public class GLStateManagerFogService implements FogService { public class GLStateManagerFogService implements FogService {
@@ -41,10 +42,25 @@ public class GLStateManagerFogService implements FogService {
} }
@Override @Override
public ChunkFogMode getFogMode() { public ChunkFogMode getBaseFogMode() {
if (!GlStateManager.fogState.fog.currentState) { if (!GlStateManager.fogState.fog.currentState) {
return ChunkFogMode.NONE; return ChunkFogMode.NONE;
} }
return ChunkFogMode.fromGLMode(GlStateManager.fogState.mode); return ChunkFogMode.fromGLMode(GlStateManager.fogState.mode);
} }
@Override
public boolean useSkyFog() {
return CeleritasVintage.options().quality.useSkyFog;
}
@Override
public float getSkyFogEdgeStart() {
return this.getSkyFogEdgeEnd() * 0.75F;
}
@Override
public float getSkyFogEdgeEnd() {
return Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16.0F;
}
} }
@@ -17,6 +17,8 @@ celeritas.options.async_graph_search.name=Async Occlusion Culling
celeritas.options.async_graph_search.tooltip=Performs occlusion/frustum culling asynchronously, up to one frame behind the current camera position. This can improve frametimes, particularly at higher render distances, but at the cost of chunks popping into view if the camera is turned too aggressively. celeritas.options.async_graph_search.tooltip=Performs occlusion/frustum culling asynchronously, up to one frame behind the current camera position. This can improve frametimes, particularly at higher render distances, but at the cost of chunks popping into view if the camera is turned too aggressively.
celeritas.options.chunk_fade_in_duration.name=Chunk Fade-In Duration celeritas.options.chunk_fade_in_duration.name=Chunk Fade-In Duration
celeritas.options.chunk_fade_in_duration.value=%s ms celeritas.options.chunk_fade_in_duration.value=%s ms
celeritas.options.sky_fog.name=Sky Fog
celeritas.options.sky_fog.tooltip=Makes distant terrain fade into the sky behind it instead of a single fog color. This removes miscolored terrain at the edge of the render distance during sunrise and sunset, in the End, and with custom skies. Has no effect while a shader pack is active.
celeritas.options.chunk_fade_in_duration.tooltip=Controls how long it takes for newly loaded chunks to fully appear. Longer durations create a smoother transition between unloaded and loaded chunks, reducing visual popping, but may make distant terrain appear to 'fade in' more slowly. celeritas.options.chunk_fade_in_duration.tooltip=Controls how long it takes for newly loaded chunks to fully appear. Longer durations create a smoother transition between unloaded and loaded chunks, reducing visual popping, but may make distant terrain appear to 'fade in' more slowly.
celeritas.options.raster_occlusion_culling.name=Rasterized Occlusion Culling celeritas.options.raster_occlusion_culling.name=Rasterized Occlusion Culling
celeritas.options.raster_occlusion_culling.tooltip=Rasterizes nearby terrain into a small software coverage buffer and uses it to skip chunks hidden behind solid terrain, such as a valley behind a hill. This can substantially reduce the amount of terrain drawn. This helps most when the GPU is the bottleneck.\n\nChanging this rebuilds all chunks. celeritas.options.raster_occlusion_culling.tooltip=Rasterizes nearby terrain into a small software coverage buffer and uses it to skip chunks hidden behind solid terrain, such as a valley behind a hill. This can substantially reduce the amount of terrain drawn. This helps most when the GPU is the bottleneck.\n\nChanging this rebuilds all chunks.
@@ -41,7 +41,7 @@ public class GLStateManagerFogService implements FogService {
} }
@Override @Override
public ChunkFogMode getFogMode() { public ChunkFogMode getBaseFogMode() {
if (!GL11.glGetBoolean(GL11.GL_FOG)) { if (!GL11.glGetBoolean(GL11.GL_FOG)) {
return ChunkFogMode.NONE; return ChunkFogMode.NONE;
} }
@@ -321,6 +321,15 @@ public class CeleritasWorldRenderer extends SimpleWorldRenderer<ClientLevel,
/*public int nextFrame() { /*public int nextFrame() {
return this.frame++; return this.frame++;
} }
@Override
protected void captureSkyFog() {
var target = Minecraft.getInstance().getMainRenderTarget();
try (var pass = com.mojang.blaze3d.systems.RenderSystem.getDevice().createCommandEncoder()
.createRenderPass(() -> "Sky fog capture", target.getColorTextureView(), java.util.OptionalInt.empty())) {
org.embeddedt.embeddium.impl.render.chunk.fog.SkyFog.capture(target.width, target.height);
}
}
*///?} *///?}
public void setCurrentViewport(Viewport viewport) { public void setCurrentViewport(Viewport viewport) {
@@ -2,6 +2,8 @@ package org.embeddedt.embeddium.impl.gl.compat;
//? if >=1.17 //? if >=1.17
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import org.embeddedt.embeddium.impl.Celeritas;
import org.embeddedt.embeddium.impl.render.chunk.fog.FogService; import org.embeddedt.embeddium.impl.render.chunk.fog.FogService;
import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL20;
@@ -78,7 +80,7 @@ public class FogHelper implements FogService {
//?} //?}
} }
public ChunkFogMode getFogMode() { public ChunkFogMode getBaseFogMode() {
//? if <1.17 { //? if <1.17 {
/*int mode = GlStateManager.FOG.mode; /*int mode = GlStateManager.FOG.mode;
@@ -98,4 +100,29 @@ public class FogHelper implements FogService {
*///?} else *///?} else
return ChunkFogMode.SMOOTH; return ChunkFogMode.SMOOTH;
} }
@Override
public boolean useSkyFog() {
return Celeritas.options().quality.useSkyFog;
}
@Override
public float getSkyFogEdgeStart() {
float end = this.getSkyFogEdgeEnd();
//? if >=1.18 {
return end - Mth.clamp(end / 10.0F, 4.0F, 64.0F);
//?} else {
/*return end * 0.75F;
*///?}
}
@Override
public float getSkyFogEdgeEnd() {
float renderDistance = Minecraft.getInstance().gameRenderer.getRenderDistance();
//? if >=1.18 {
return Math.max(renderDistance, 32.0F);
//?} else {
/*return Math.max(renderDistance - 16.0F, 32.0F);
*///?}
}
} }
@@ -3,26 +3,31 @@ package org.embeddedt.embeddium.impl.render.immediate;
import org.embeddedt.embeddium.impl.gl.shader.*; import org.embeddedt.embeddium.impl.gl.shader.*;
import org.embeddedt.embeddium.impl.gl.shader.uniform.*; import org.embeddedt.embeddium.impl.gl.shader.uniform.*;
import org.embeddedt.embeddium.impl.gl.compat.FogHelper; import org.embeddedt.embeddium.impl.gl.compat.FogHelper;
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderComponent;
import org.embeddedt.embeddium.impl.render.chunk.shader.ChunkShaderEnvironment;
import org.embeddedt.embeddium.impl.render.shader.ShaderLoader; import org.embeddedt.embeddium.impl.render.shader.ShaderLoader;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import java.util.IdentityHashMap;
import java.util.Map;
public class CloudShader implements AutoCloseable { public class CloudShader implements AutoCloseable {
private static final int ATTRIBUTE_POSITION = 0; private static final int ATTRIBUTE_POSITION = 0;
private static final int ATTRIBUTE_COLOR = 1; private static final int ATTRIBUTE_COLOR = 1;
private static final int FRAG_COLOR = 0; private static final int FRAG_COLOR = 0;
private final GlProgram<CloudShaderInterface> program; private static final ChunkShaderEnvironment ENVIRONMENT = new ChunkShaderEnvironment(FogHelper.INSTANCE);
private static final ShaderConstants CLOUD_CONSTANTS = ShaderConstants.builder().add("USE_FOG").build(); private final Map<ChunkShaderComponent.Factory<?>, GlProgram<CloudShaderInterface>> programs = new IdentityHashMap<>();
public CloudShader() { private GlProgram<CloudShaderInterface> program;
this.program = createShader();
}
private GlProgram<CloudShaderInterface> createShader() { private static GlProgram<CloudShaderInterface> createShader(ChunkShaderComponent.Factory<?> fog) {
GlShader vertShader = ShaderLoader.loadShader(ShaderType.VERTEX, "sodium:clouds/clouds.vsh", CLOUD_CONSTANTS); ShaderConstants constants = ShaderConstants.builder().addAll(fog.getDefines()).build();
GlShader fragShader = ShaderLoader.loadShader(ShaderType.FRAGMENT, "sodium:clouds/clouds.fsh", CLOUD_CONSTANTS); GlShader vertShader = ShaderLoader.loadShader(ShaderType.VERTEX, "sodium:clouds/clouds.vsh", constants);
GlShader fragShader = ShaderLoader.loadShader(ShaderType.FRAGMENT, "sodium:clouds/clouds.fsh", constants);
try { try {
return GlProgram.builder("celeritas:cloud_shader") return GlProgram.builder("celeritas:cloud_shader")
@@ -31,7 +36,7 @@ public class CloudShader implements AutoCloseable {
.bindAttribute("Position", ATTRIBUTE_POSITION) .bindAttribute("Position", ATTRIBUTE_POSITION)
.bindAttribute("Color", ATTRIBUTE_COLOR) .bindAttribute("Color", ATTRIBUTE_COLOR)
.bindFragmentData("fragColor", FRAG_COLOR) .bindFragmentData("fragColor", FRAG_COLOR)
.link(CloudShaderInterface::new); .link(context -> new CloudShaderInterface(context, fog.create(context, ENVIRONMENT)));
} finally { } finally {
vertShader.delete(); vertShader.delete();
fragShader.delete(); fragShader.delete();
@@ -39,6 +44,7 @@ public class CloudShader implements AutoCloseable {
} }
public void prepareForDraw(Matrix4f modelViewMatrix, Matrix4f projectionMatrix, float r, float g, float b, float a) { public void prepareForDraw(Matrix4f modelViewMatrix, Matrix4f projectionMatrix, float r, float g, float b, float a) {
this.program = this.programs.computeIfAbsent(FogHelper.INSTANCE.getFogMode(), CloudShader::createShader);
this.program.bind(); this.program.bind();
this.program.getInterface().setupState(modelViewMatrix, projectionMatrix, r, g, b, a); this.program.getInterface().setupState(modelViewMatrix, projectionMatrix, r, g, b, a);
} }
@@ -49,31 +55,28 @@ public class CloudShader implements AutoCloseable {
@Override @Override
public void close() { public void close() {
this.program.delete(); this.programs.values().forEach(GlProgram::delete);
this.programs.clear();
} }
static class CloudShaderInterface { static class CloudShaderInterface {
private final GlUniformMatrix4f uniformModelViewMatrix; private final GlUniformMatrix4f uniformModelViewMatrix;
private final GlUniformMatrix4f uniformProjectionMatrix; private final GlUniformMatrix4f uniformProjectionMatrix;
private final GlUniformFloat uniformFogStart, uniformFogEnd; private final GlUniformFloat4v uniformMainColor;
private final GlUniformFloat4v uniformFogColor, uniformMainColor; private final ChunkShaderComponent fog;
public CloudShaderInterface(ShaderBindingContext context) { public CloudShaderInterface(ShaderBindingContext context, ChunkShaderComponent fog) {
this.uniformModelViewMatrix = context.bindUniform("ModelViewMat", GlUniformMatrix4f::new); this.uniformModelViewMatrix = context.bindUniform("ModelViewMat", GlUniformMatrix4f::new);
this.uniformProjectionMatrix = context.bindUniform("ProjMat", GlUniformMatrix4f::new); this.uniformProjectionMatrix = context.bindUniform("ProjMat", GlUniformMatrix4f::new);
this.uniformFogStart = context.bindUniform("FogStart", GlUniformFloat::new);
this.uniformFogEnd = context.bindUniform("FogEnd", GlUniformFloat::new);
this.uniformFogColor = context.bindUniform("FogColor", GlUniformFloat4v::new);
this.uniformMainColor = context.bindUniform("ColorModulator", GlUniformFloat4v::new); this.uniformMainColor = context.bindUniform("ColorModulator", GlUniformFloat4v::new);
this.fog = fog;
} }
public void setupState(Matrix4f modelViewMatrix, Matrix4f projectionMatrix, float r, float g, float b, float a) { public void setupState(Matrix4f modelViewMatrix, Matrix4f projectionMatrix, float r, float g, float b, float a) {
this.uniformModelViewMatrix.set(modelViewMatrix); this.uniformModelViewMatrix.set(modelViewMatrix);
this.uniformProjectionMatrix.set(projectionMatrix); this.uniformProjectionMatrix.set(projectionMatrix);
this.uniformFogStart.set(FogHelper.INSTANCE.getFogStart());
this.uniformFogEnd.set(FogHelper.INSTANCE.getFogEnd());
this.uniformFogColor.set(FogHelper.INSTANCE.getFogColor());
this.uniformMainColor.set(new float[] { r, g, b, a }); this.uniformMainColor.set(new float[] { r, g, b, a });
this.fog.setup();
} }
} }
} }
@@ -2,6 +2,7 @@ package org.embeddedt.embeddium.impl.gl.compat;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.fog.FogData; import net.minecraft.client.renderer.fog.FogData;
import org.embeddedt.embeddium.impl.Celeritas;
import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext; import org.embeddedt.embeddium.impl.gl.shader.ShaderBindingContext;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat; import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat;
import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat4v; import org.embeddedt.embeddium.impl.gl.shader.uniform.GlUniformFloat4v;
@@ -51,10 +52,15 @@ public class FogHelper implements FogService {
} }
@Override @Override
public ChunkShaderComponent.Factory<?> getFogMode() { public ChunkShaderComponent.Factory<?> getBaseFogMode() {
return PostmodernFogComponent.FACTORY; return PostmodernFogComponent.FACTORY;
} }
@Override
public boolean useSkyFog() {
return Celeritas.options().quality.useSkyFog;
}
private static class PostmodernFogComponent implements ChunkShaderComponent { private static class PostmodernFogComponent implements ChunkShaderComponent {
private static final ChunkShaderComponent.Factory<PostmodernFogComponent> FACTORY = new ChunkShaderComponent.Factory<>() { private static final ChunkShaderComponent.Factory<PostmodernFogComponent> FACTORY = new ChunkShaderComponent.Factory<>() {
@Override @Override
@@ -17,6 +17,8 @@
"celeritas.options.async_graph_search.tooltip": "Performs occlusion/frustum culling asynchronously, up to one frame behind the current camera position. This can improve frametimes, particularly at higher render distances, but at the cost of chunks popping into view if the camera is turned too aggressively.", "celeritas.options.async_graph_search.tooltip": "Performs occlusion/frustum culling asynchronously, up to one frame behind the current camera position. This can improve frametimes, particularly at higher render distances, but at the cost of chunks popping into view if the camera is turned too aggressively.",
"celeritas.options.chunk_fade_in_duration.name": "Chunk Fade-In Duration", "celeritas.options.chunk_fade_in_duration.name": "Chunk Fade-In Duration",
"celeritas.options.chunk_fade_in_duration.value": "%s ms", "celeritas.options.chunk_fade_in_duration.value": "%s ms",
"celeritas.options.sky_fog.name": "Sky Fog",
"celeritas.options.sky_fog.tooltip": "Makes distant terrain and clouds fade into the sky behind them instead of a single fog color. This removes miscolored terrain at the edge of the render distance during sunrise and sunset, in the End, and with custom skies. Has no effect while a shader pack is active.",
"celeritas.options.rgss_texture_filtering.name": "RGSS Texture Filtering", "celeritas.options.rgss_texture_filtering.name": "RGSS Texture Filtering",
"celeritas.options.rgss_texture_filtering.tooltip": "Smooths block textures in the distance by supersampling them, which reduces shimmering and jagged texel edges. Requires mipmaps, and has no effect while a shader pack is active.", "celeritas.options.rgss_texture_filtering.tooltip": "Smooths block textures in the distance by supersampling them, which reduces shimmering and jagged texel edges. Requires mipmaps, and has no effect while a shader pack is active.",
"celeritas.options.chunk_fade_in_duration.tooltip": "Controls how long it takes for newly loaded chunks to fully appear. Longer durations create a smoother transition between unloaded and loaded chunks, reducing visual popping, but may make distant terrain appear to 'fade in' more slowly.", "celeritas.options.chunk_fade_in_duration.tooltip": "Controls how long it takes for newly loaded chunks to fully appear. Longer durations create a smoother transition between unloaded and loaded chunks, reducing visual popping, but may make distant terrain appear to 'fade in' more slowly.",
@@ -40,7 +40,7 @@ public class GLStateManagerFogService implements FogService {
} }
@Override @Override
public ChunkFogMode getFogMode() { public ChunkFogMode getBaseFogMode() {
if (!GL11.glGetBoolean(GL11.GL_FOG)) { if (!GL11.glGetBoolean(GL11.GL_FOG)) {
return ChunkFogMode.NONE; return ChunkFogMode.NONE;
} }