From c8e6a56467017a1c1e64092a9e2afb753b3d6026 Mon Sep 17 00:00:00 2001 From: coolGi Date: Fri, 21 Jul 2023 19:51:15 +0930 Subject: [PATCH] Changed noiseDropoff to an int, and changed the order of noise and fog --- .../client/IDhApiNoiseTextureConfig.java | 8 +- .../client/DhApiNoiseTextureConfig.java | 4 +- .../distanthorizons/core/config/Config.java | 11 +- .../core/render/fog/LodFogConfig.java | 4 +- .../main/resources/shaders/flat_shaded.frag | 130 ++++++++++-------- 5 files changed, 84 insertions(+), 73 deletions(-) diff --git a/api/src/main/java/com/seibel/distanthorizons/api/interfaces/config/client/IDhApiNoiseTextureConfig.java b/api/src/main/java/com/seibel/distanthorizons/api/interfaces/config/client/IDhApiNoiseTextureConfig.java index fc0598b1d..bf490429d 100644 --- a/api/src/main/java/com/seibel/distanthorizons/api/interfaces/config/client/IDhApiNoiseTextureConfig.java +++ b/api/src/main/java/com/seibel/distanthorizons/api/interfaces/config/client/IDhApiNoiseTextureConfig.java @@ -40,11 +40,9 @@ public interface IDhApiNoiseTextureConfig extends IDhApiConfigGroup IDhApiConfigValue noiseIntensity(); /** - * Defines how far should the noise texture render before it fades away.

- * - * 0.0 - the noise texture will render the entire LOD render distance.
- * 3.0 - the noise texture will fade away at 1/3 of the LOD render distance. + * Defines how far should the noise texture render before it fades away. (in blocks)
+ * Set to 0 to disable noise from fading away */ - IDhApiConfigValue noiseDropoff(); + IDhApiConfigValue noiseDropoff(); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiNoiseTextureConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiNoiseTextureConfig.java index eff0162a2..a29637de8 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiNoiseTextureConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiNoiseTextureConfig.java @@ -45,7 +45,7 @@ public class DhApiNoiseTextureConfig implements IDhApiNoiseTextureConfig { return new DhApiConfigValue(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseIntensity); } @Override - public IDhApiConfigValue noiseDropoff() - { return new DhApiConfigValue(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseDropoff); } + public IDhApiConfigValue noiseDropoff() + { return new DhApiConfigValue(Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseDropoff); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java index 33f325060..9376024cc 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java @@ -468,14 +468,11 @@ public class Config + "How intense should the noise should be?") .build(); - public static ConfigEntry noiseDropoff = new ConfigEntry.Builder() // TODO: Make this a float (the ClassicConfigGUI doesn't support floats) - .setMinDefaultMax(0d, 3d, null) + public static ConfigEntry noiseDropoff = new ConfigEntry.Builder() // TODO: Make this a float (the ClassicConfigGUI doesn't support floats) + .setMinDefaultMax(0, 1024, null) .comment("" - + "How far should the noise texture render before it fades away? \n" - + "\n" - + "0.0 - the noise texture will render the entire LOD render distance. \n" - + "3.0 - the noise texture will fade away at 1/3 of the LOD render distance. \n" - + "") + + "Defines how far should the noise texture render before it fades away. (in blocks) \n" + + "Set to 0 to disable noise from fading away") .build(); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/fog/LodFogConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/render/fog/LodFogConfig.java index 4d44bc0ba..1b606638d 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/fog/LodFogConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/fog/LodFogConfig.java @@ -60,7 +60,7 @@ public class LodFogConfig public final boolean noiseEnable; public final int noiseSteps; public final float noiseIntensity; - public final float noiseDropoff; + public final int noiseDropoff; public static LodFogConfig generateFogConfig() @@ -82,7 +82,7 @@ public class LodFogConfig noiseEnable = Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseEnabled.get(); noiseSteps = Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseSteps.get(); noiseIntensity = Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseIntensity.get().floatValue(); - noiseDropoff = Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseDropoff.get().floatValue(); + noiseDropoff = Config.Client.Advanced.Graphics.NoiseTextureSettings.noiseDropoff.get(); if (fogDrawMode != EFogDrawMode.FOG_DISABLED) diff --git a/core/src/main/resources/shaders/flat_shaded.frag b/core/src/main/resources/shaders/flat_shaded.frag index 3d7632a2b..e16dc3936 100644 --- a/core/src/main/resources/shaders/flat_shaded.frag +++ b/core/src/main/resources/shaders/flat_shaded.frag @@ -6,16 +6,21 @@ in vec4 vPos; out vec4 fragColor; +// Fog uniforms uniform float fogScale; uniform float fogVerticalScale; uniform float nearFogStart; uniform float nearFogLength; uniform int fullFogMode; +// Noise uniforms uniform bool noiseEnabled; uniform int noiseSteps; uniform float noiseIntensity; -uniform float noiseDropoff; +uniform int noiseDropoff; + +// SSAO uniforms +//uniform bool ssaoEnabled; /* ========MARCO DEFINED BY RUNTIME CODE GEN========= @@ -84,20 +89,82 @@ vec3 HSV2RGB(vec3 c) { } -/** +/** * Fragment Shader - * + * * author: James Seibel * author: coolGi * version: 7-2-2023 */ void main() { - vec4 returnColor; + fragColor = vertexColor; + + // TODO: Move into its own function instead of in an if statement + if (noiseEnabled) { + // This bit of code is required to fix the vertex position problem cus of floats in the verted world position varuable + vec3 vertexNormal = normalize(cross(dFdx(vPos.xyz), dFdy(vPos.xyz))); + vec3 fixedVPos = vec3( + vPos.x - vertexNormal.x * 0.001, + vPos.y - vertexNormal.y * 0.001, + vPos.z - vertexNormal.z * 0.001 + ); + float noiseAmplification = noiseIntensity / 100; + noiseAmplification = (-1 * pow(2*((fragColor.x + fragColor.y + fragColor.z) / 3) - 1, 2) + 1) * noiseAmplification; // Lessen the effect on depending on how dark the object is, equasion for this is -(2x-1)^{2}+1 + noiseAmplification *= fragColor.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) + )) + * 2. * noiseAmplification - noiseAmplification; + + + // 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 = fragColor.rgb + (vec3(1.0) - fragColor.rgb) * randomValue; + + // Clamps it and turns it back into a vec4 + if (noiseDropoff == 0) + fragColor = vec4( + clamp(newCol.r, 0., 1.), + clamp(newCol.g, 0., 1.), + clamp(newCol.b, 0., 1.), + fragColor.w + ); + else + fragColor = mix( + vec4( + clamp(newCol.r, 0., 1.), + clamp(newCol.g, 0., 1.), + clamp(newCol.b, 0., 1.), + fragColor.w + ), fragColor, + clamp(length(vertexWorldPos) / noiseDropoff, 0., 1.) // The further away it gets, the less noise gets applied + ); + + // For testing + // if (fragColor.r != 69420.) { + // fragColor = vec4( + // mod(fixedVPos.x, 1), + // mod(fixedVPos.y, 1), + // mod(fixedVPos.z, 1), + // fragColor.w); + // } + } + +// // TODO: Move into its own function instead of in an if statement +// if (ssaoEnabled) { +// +// } + + // TODO: Move into its own function instead of in an if statement if (fullFogMode != 0) { - returnColor = vec4(fogColor.rgb, 1.0); + fragColor = vec4(fogColor.rgb, 1.0); } else { // TODO: add a white texture to support Optifine shaders //vec4 textureColor = texture(texImage, textureCoord); @@ -115,59 +182,8 @@ void main() float mixedFogThickness = clamp(mixFogThickness( nearFogThickness, farFogThickness, heightFogThickness), 0.0, 1.0); - returnColor = mix(vertexColor, vec4(fogColor.rgb, 1.0), mixedFogThickness); + fragColor = mix(fragColor, vec4(fogColor.rgb, 1.0), mixedFogThickness); } - - if (noiseEnabled) { - // This bit of code is required to fix the vertex position problem cus of floats in the verted world position varuable - vec3 vertexNormal = normalize(cross(dFdx(vPos.xyz), dFdy(vPos.xyz))); - vec3 fixedVPos = vec3( - vPos.x - vertexNormal.x * 0.001, - vPos.y - vertexNormal.y * 0.001, - vPos.z - vertexNormal.z * 0.001 - ); - - - float noiseAmplification = noiseIntensity / 100; - noiseAmplification = (-1 * pow(2*((returnColor.x + returnColor.y + returnColor.z) / 3) - 1, 2) + 1) * noiseAmplification; // Lessen the effect on depending on how dark the object is, equasion for this is -(2x-1)^{2}+1 - 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) - )) - * 2. * noiseAmplification - noiseAmplification; - - - // 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; - - // 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 -// 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 - fragColor = returnColor; }