Optimised the lod noise and added drop off for it

This commit is contained in:
coolGi
2023-02-07 19:33:46 +10:30
parent 0f5efa2036
commit 3efeea8987
5 changed files with 59 additions and 37 deletions
@@ -41,6 +41,7 @@ public class Config
// | |-> Quality
// | |-> FogQuality
// | |-> AdvancedGraphics
// | |-> NoiseSettings
// |
// |-> World Generation
// |
@@ -205,7 +206,7 @@ public class Config
public static class AdvancedFog {
// TODO: Make some of the option here floats rather than doubles (the ClassicConfigGUI dosnt support floats)
// TODO: Make some of the option here floats rather than doubles (the ClassicConfigGUI doesnt support floats)
private static final Double FOG_RANGE_MIN = 0.0;
private static final Double FOG_RANGE_MAX = Math.sqrt(2.0);
@@ -410,7 +411,7 @@ public class Config
.setPerformance(ConfigEntryPerformance.NONE)
.build();
public static ConfigEntry<Double> brightnessMultiplier = new ConfigEntry.Builder<Double>() // TODO: Make this a float (the ClassicConfigGUI dosnt support floats)
public static ConfigEntry<Double> brightnessMultiplier = new ConfigEntry.Builder<Double>() // TODO: Make this a float (the ClassicConfigGUI doesnt support floats)
.set(1.0)
.comment(""
+ "How bright fake chunk colors are. \n"
@@ -420,7 +421,7 @@ public class Config
+ " 2 = near white")
.build();
public static ConfigEntry<Double> saturationMultiplier = new ConfigEntry.Builder<Double>() // TODO: Make this a float (the ClassicConfigGUI dosnt support floats)
public static ConfigEntry<Double> saturationMultiplier = new ConfigEntry.Builder<Double>() // TODO: Make this a float (the ClassicConfigGUI doesnt support floats)
.set(1.0)
.comment(""
+ "How saturated fake chunk colors are. \n"
@@ -484,10 +485,17 @@ public class Config
.comment("How many steps of noise should be on each block")
.build();
public static ConfigEntry<Double> noiseIntensity = new ConfigEntry.Builder<Double>() // TODO: Make this a float (the ClassicConfigGUI dosnt support floats)
.set(12.5d)
public static ConfigEntry<Double> noiseIntensity = new ConfigEntry.Builder<Double>() // TODO: Make this a float (the ClassicConfigGUI doesnt support floats)
.setMinDefaultMax(0d, 20d, 100d) // TODO: Once this becomes a float make it 0-1 instead of 0-100 (I did this cus doubles only allow 2 decimal places)
.comment("How intense the noise should be")
.build();
public static ConfigEntry<Double> noiseDropoff = new ConfigEntry.Builder<Double>() // TODO: Make this a float (the ClassicConfigGUI doesnt support floats)
.setMinDefaultMax(0d, 1d, null)
.comment(""
+ "How fast the noise should drop off to no noise based upon your lod render distance \n"
+ "Eg, if you set it to 3, then the noise effect would completely go away after 1/3 of your render distance")
.build();
}
}
}
@@ -64,6 +64,7 @@ public class LodFogConfig
public final boolean noiseEnable;
public final int noiseSteps;
public final float noiseIntensity;
public final float noiseDropoff;
public static LodFogConfig generateFogConfig()
@@ -85,6 +86,7 @@ public class LodFogConfig
noiseEnable = Config.Client.Graphics.AdvancedGraphics.NoiseSettings.noiseEnable.get();
noiseSteps = Config.Client.Graphics.AdvancedGraphics.NoiseSettings.noiseSteps.get();
noiseIntensity = Config.Client.Graphics.AdvancedGraphics.NoiseSettings.noiseIntensity.get().floatValue();
noiseDropoff = Config.Client.Graphics.AdvancedGraphics.NoiseSettings.noiseDropoff.get().floatValue();
if (fogDrawMode != EFogDrawMode.FOG_DISABLED)
@@ -440,12 +442,12 @@ public class LodFogConfig
heightFogMode == that.heightFogMode
// TODO: Move these out of here
&& earthCurveRatio == that.earthCurveRatio
&& noiseEnable == that.noiseEnable && noiseSteps == that.noiseSteps && noiseIntensity == that.noiseIntensity;
&& noiseEnable == that.noiseEnable && noiseSteps == that.noiseSteps && noiseIntensity == that.noiseIntensity && noiseDropoff == that.noiseDropoff;
}
@Override
public int hashCode()
{
return Objects.hash(farFogSetting, heightFogSetting, heightFogMixMode, heightFogMode, heightFogHeight, drawNearFog, earthCurveRatio, noiseEnable, noiseSteps, noiseIntensity);
return Objects.hash(farFogSetting, heightFogSetting, heightFogMixMode, heightFogMode, heightFogHeight, drawNearFog, earthCurveRatio, noiseEnable, noiseSteps, noiseIntensity, noiseDropoff);
}
}
@@ -64,6 +64,7 @@ public class LodRenderProgram extends ShaderProgram {
public final int noiseEnabledUniform;
public final int noiseStepsUniform;
public final int noiseIntensityUniform;
public final int noiseDropoffUniform;
public final LodFogConfig fogConfig;
@@ -96,6 +97,7 @@ public class LodRenderProgram extends ShaderProgram {
noiseEnabledUniform = getUniformLocation("noiseEnabled");
noiseStepsUniform = getUniformLocation("noiseSteps");
noiseIntensityUniform = getUniformLocation("noiseIntensity");
noiseDropoffUniform = getUniformLocation("noiseDropoff");
// TODO: Add better use of the LODFormat thing
int vertexByteCount = LodUtil.LOD_VERTEX_FORMAT.getByteSize();
@@ -122,6 +124,7 @@ public class LodRenderProgram extends ShaderProgram {
setUniform(noiseEnabledUniform, fogConfig.noiseEnable);
setUniform(noiseStepsUniform, fogConfig.noiseSteps);
setUniform(noiseIntensityUniform, fogConfig.noiseIntensity);
setUniform(noiseDropoffUniform, fogConfig.noiseDropoff);
}
// If not usable, return a new LodFogConfig to be constructed
@@ -204,6 +204,10 @@
"Noise Intensity",
"lod.config.client.graphics.advancedGraphics.noiseSettings.noiseIntensity.@tooltip":
"How clearly you can see the noise on the lod's.\nIt gets more intense the lower the value gets and less noticeable when it gets higher.",
"lod.config.client.graphics.advancedGraphics.noiseSettings.noiseDropoff":
"Noise Drop Off",
"lod.config.client.graphics.advancedGraphics.noiseSettings.noiseDropoff.@tooltip":
"How fast the noise should drop off to no noise based upon your lod render distance\nEg, if you set it to 3, then the noise effect would completely go away after 1/3 of your render distance",
"lod.config.client.graphics.advancedGraphics.earthCurveRatio.@tooltip":
"This is the earth size ratio when applying the curvature shader effect. \n\n§6NOTE§r: This feature is just for fun and is VERY experimental! \nPlease don't report any issues related to this feature. \n\n0 = flat/disabled \n1 = 1 to 1 (6,371,000 blocks) \n100 = 1 to 100 (63,710 blocks) \n10000 = 1 to 10000 (637.1 blocks) \n\n§6NOTE§r: due to current limitations, the min value is 50 \n and the max value is 5000. Any values outside this range \n will be set to 0(disabled).",
@@ -15,6 +15,7 @@ uniform int fullFogMode;
uniform bool noiseEnabled;
uniform int noiseSteps;
uniform float noiseIntensity;
uniform float noiseDropoff;
/* ========MARCO DEFINED BY RUNTIME CODE GEN=========
@@ -60,10 +61,12 @@ float quantize(float val, int stepSize) {
}
// The modulus function dosnt exist in GLSL so I made my own
float mod(float x, float y) {
// To speed up the mod function, this only accepts full numbers for y
float mod(float x, int y) {
return x - y * floor(x/y);
}
// Some HSV functions I stole somewhere online
vec3 RGB2HSV(vec3 c) {
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
@@ -86,12 +89,13 @@ vec3 HSV2RGB(vec3 c) {
*
* author: James Seibel
* author: coolGi
* version: 24-1-2023
* version: 7-2-2023
*/
void main()
{
vec4 returnColor;
if (fullFogMode != 0) {
returnColor = vec4(fogColor.rgb, 1.0);
} else {
@@ -112,7 +116,6 @@ void main()
nearFogThickness, farFogThickness, heightFogThickness), 0.0, 1.0);
returnColor = mix(vertexColor, vec4(fogColor.rgb, 1.0), mixedFogThickness);
}
if (noiseEnabled) {
@@ -125,48 +128,50 @@ void main()
);
float noiseAmplification = noiseIntensity / 100;
noiseAmplification = (returnColor.x + returnColor.y + returnColor.z) / 3 * noiseAmplification; // Lessen the effect on depending on how dark the object is
// noiseAmplification *= returnColor.w; // The effect would lessen on transparent objects
// Random value for each position
float randomValue = rand(vec3(
quantize(fixedVPos.x, noiseSteps),
quantize(fixedVPos.y, noiseSteps),
quantize(fixedVPos.z, noiseSteps)
));
float randomHue = rand(randomValue); // Dont bother with the larger random function, just use its value to get a new random value
))
* 2. * noiseAmplification - noiseAmplification;
float noiseAmplification = (2. - (returnColor.x + returnColor.y + returnColor.z) / 3) * noiseIntensity;
// noiseAmplification *= returnColor.w; // The effect would lessen on transparent objects
// Modifies the color
// A value of 0 on the randomValue will result in the original color, while a value of 1 will result in a fully bright color
vec3 newCol = returnColor.rgb + (vec3(1.0) - returnColor.rgb) * randomValue;
randomValue = (randomValue - 0.5) / noiseAmplification;
randomHue = (randomHue - 0.5) / noiseAmplification / 2;
vec3 returnHSV = RGB2HSV(returnColor.rgb); // HSV has some control which makes it easier to do some stuff like change the brightness
returnHSV.z += randomValue; // Change the val (which controlls the brightness)
returnHSV.z = clamp(returnHSV.z, 0., 1.);
returnHSV.x += randomHue; // Changes the hue (which controlls the color)
returnHSV.x = clamp(returnHSV.x, 0., 1.);
vec3 returnRGB = HSV2RGB(returnHSV); // Change it back to rgb
returnColor = vec4(
returnRGB.r,
returnRGB.g,
returnRGB.b,
returnColor.w);
// Clamps it and turns it back into a vec4
returnColor = mix(
vec4(
clamp(newCol.r, 0., 1.),
clamp(newCol.g, 0., 1.),
clamp(newCol.b, 0., 1.),
returnColor.w
), returnColor,
clamp(length(vertexWorldPos) * fogScale * noiseDropoff, 0., 1.) // The further away it gets, the less noise gets applied
);
// For testing
// returnColor = vec4(
// mod(fixedVPos.x, 1.),
// mod(fixedVPos.y, 1.),
// mod(fixedVPos.z, 1.),
// returnColor.w);
// if (returnColor.r != 69420.) {
// returnColor = vec4(
// mod(fixedVPos.x, 1),
// mod(fixedVPos.y, 1),
// mod(fixedVPos.z, 1),
// returnColor.w);
// }
}
// If "w" is just set to just 1 then it would crash
// If "w" is just set to just 1. then it would crash
fragColor = returnColor;
}
float linearFog(float x, float fogStart, float fogLength, float fogMin, float fogRange) {
x = clamp((x-fogStart)/fogLength, 0.0, 1.0);
return fogMin + fogRange * x;