diff --git a/Readme.md b/Readme.md index ba593171f..668aca089 100644 --- a/Readme.md +++ b/Readme.md @@ -17,7 +17,7 @@ It should be automatically included when pulling the full mod. LZ4 for Java (data compression)\ https://github.com/lz4/lz4-java -Json & Toml for Java (config handling)\ +NightConfig for Json & Toml (config handling)\ https://github.com/TheElectronWill/night-config SVG Salamander for SVG's\ 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 4a8bba8af..67b759294 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/jar/gui/BaseJFrame.java b/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/BaseJFrame.java index 546e860ab..344d792dd 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/BaseJFrame.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/BaseJFrame.java @@ -59,7 +59,7 @@ public class BaseJFrame extends JFrame { // Creates a list with all the options in it List langsToChoose = new ArrayList<>(); try( - final InputStreamReader isr = new InputStreamReader(JarUtils.accessFile("assets/lod/lang"), StandardCharsets.UTF_8); + final InputStreamReader isr = new InputStreamReader(JarUtils.accessFile("assets/distanthorizons/lang"), StandardCharsets.UTF_8); final BufferedReader br = new BufferedReader(isr) ) { List col = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(br.lines().toArray()))); @@ -87,11 +87,11 @@ public class BaseJFrame extends JFrame { // Try to set the icons for them try { lightMode = new JButton(new ImageIcon( - new FlatSVGIcon(JarUtils.accessFile("assets/lod/textures/jar/themeLight.svg")).getImage() // Get the image + new FlatSVGIcon(JarUtils.accessFile("assets/distanthorizons/textures/jar/themeLight.svg")).getImage() // Get the image .getScaledInstance(themeButtonSize, themeButtonSize, Image.SCALE_DEFAULT) // Scale it to the correct size )); darkMode = new JButton(new ImageIcon( - new FlatSVGIcon(JarUtils.accessFile("assets/lod/textures/jar/themeDark.svg")).getImage() // Get the image + new FlatSVGIcon(JarUtils.accessFile("assets/distanthorizons/textures/jar/themeDark.svg")).getImage() // Get the image .getScaledInstance(themeButtonSize, themeButtonSize, Image.SCALE_DEFAULT) // Scale it to the correct size )); } catch (Exception e) {e.printStackTrace();} @@ -139,8 +139,7 @@ public class BaseJFrame extends JFrame { // This part of the code is taken from the official java docs at https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html // Specify the look and feel to use by defining the LOOKANDFEEL constant - // Valid values are: null (use the default), "Metal", "System", "Motif", - // and "GTK" + // Valid values are: null (use the default), "Metal", "System", "Motif", and "GTK" final static String LOOKANDFEEL = "GTK"; private static void initLookAndFeel() { String lookAndFeel = null; 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..8387d7979 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 @@ -57,10 +57,11 @@ public class LodFogConfig // TODO: Move these out of here public final int earthCurveRatio; + // Noise Values 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 +83,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/java/com/seibel/distanthorizons/core/render/renderer/LodRenderProgram.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderProgram.java index ad7e096f4..cecf49059 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderProgram.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderProgram.java @@ -53,6 +53,7 @@ public class LodRenderProgram extends ShaderProgram public final int earthRadiusUniform; public final int lightMapUniform; + // Fog Uniforms public final int fogColorUniform; public final int fogScaleUniform; @@ -85,7 +86,7 @@ public class LodRenderProgram extends ShaderProgram lightMapUniform = getUniformLocation("lightMap"); - // Fog uniforms + // Fog Uniforms fullFogModeUniform = getUniformLocation("fullFogMode"); fogColorUniform = getUniformLocation("fogColor"); fogScaleUniform = tryGetUniformLocation("fogScale"); @@ -94,12 +95,13 @@ public class LodRenderProgram extends ShaderProgram nearFogStartUniform = tryGetUniformLocation("nearFogStart"); nearFogLengthUniform = tryGetUniformLocation("nearFogLength"); - // Noise uniforms + // Noise Uniforms 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(); if (GLProxy.getInstance().VertexAttributeBufferBindingSupported) @@ -122,6 +124,7 @@ public class LodRenderProgram extends ShaderProgram if (earthRadiusUniform != -1) setUniform(earthRadiusUniform, /*6371KM*/ 6371000.0f / fogConfig.earthCurveRatio); + // Noise Uniforms setUniform(noiseEnabledUniform, fogConfig.noiseEnable); setUniform(noiseStepsUniform, fogConfig.noiseSteps); setUniform(noiseIntensityUniform, fogConfig.noiseIntensity); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderer.java index 217318e82..f622276af 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderer.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/LodRenderer.java @@ -252,7 +252,7 @@ public class LodRenderer bufferHandler.renderOpaque(this); if (Config.Client.Advanced.Graphics.Quality.ssao.get()) { -// SSAOShader.INSTANCE.render(partialTicks); +// SSAOShader.INSTANCE.render(partialTicks); // For some reason this looks slightly different :/ SSAORenderer.INSTANCE.render(partialTicks); } { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/AbstractShaderRenderer.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/AbstractShaderRenderer.java index 43b6a1704..53932bdab 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/AbstractShaderRenderer.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/AbstractShaderRenderer.java @@ -29,7 +29,7 @@ public abstract class AbstractShaderRenderer { protected final ShaderProgram shader; protected final ShaderProgram applyShader; - protected GLVertexBuffer boxBuffer; + public GLVertexBuffer boxBuffer; protected VertexAttribute va; boolean init = false; @@ -46,9 +46,8 @@ public abstract class AbstractShaderRenderer { protected AbstractShaderRenderer(ShaderProgram shader, ShaderProgram applyShader) { this.shader = shader; this.applyShader = applyShader; - - } + private void init() { if (init) return; init = true; @@ -56,7 +55,7 @@ public abstract class AbstractShaderRenderer { va = VertexAttribute.create(); va.bind(); // Pos - va.setVertexAttribute(0, 0, VertexAttribute.VertexPointer.addVec2Pointer(false)); + setVertexAttributes(); va.completeAndCheck(Float.BYTES * 2); // Some shader stuff needs to be set a bit later than @@ -65,6 +64,10 @@ public abstract class AbstractShaderRenderer { createBuffer(); } + /** Sets all the vertex attributes */ + void setVertexAttributes() { + va.setVertexAttribute(0, 0, VertexAttribute.VertexPointer.addVec2Pointer(false)); + }; /** Overwrite this to apply uniforms to the shader */ void setShaderUniforms(float partialTicks) {}; /** Overwrite this to apply uniforms to the apply shader */ diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FogShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FogShader.java index 87a5805f8..bc709d164 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FogShader.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/FogShader.java @@ -6,6 +6,7 @@ import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; import com.seibel.distanthorizons.core.render.fog.LodFogConfig; import com.seibel.distanthorizons.core.render.glObject.shader.Shader; import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram; +import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexAttribute; import com.seibel.distanthorizons.core.util.LodUtil; import com.seibel.distanthorizons.core.util.RenderUtil; import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants; @@ -21,7 +22,10 @@ public class FogShader extends AbstractShaderRenderer { // public final int modelOffsetUniform; - public final int worldYOffsetUniform; +// public final int worldYOffsetUniform; + + public final int gProjUniform; + public final int gDepthMapUniform; // Fog Uniforms public final int fogColorUniform; @@ -36,13 +40,16 @@ public class FogShader extends AbstractShaderRenderer { // This code is just a temp fix so that it looks fine for the time being // and even with the jank soloution, i cannot get it to work super(new ShaderProgram( - () -> Shader.loadFile("shaders/fog/fog.vert", false, new StringBuilder()).toString(), + () -> Shader.loadFile("shaders/normal.vert", false, new StringBuilder()).toString(), () -> fogConfig.loadAndProcessFragShader("shaders/fog/fog.frag", false).toString(), - "fragColor", new String[] { "vPosition", "vPos", "color" } + "fragColor", new String[] { "vPosition" } )); // modelOffsetUniform = this.shader.getUniformLocation("modelOffset"); - worldYOffsetUniform = this.shader.getUniformLocation("worldYOffset"); +// worldYOffsetUniform = this.shader.tryGetUniformLocation("worldYOffset"); + + gProjUniform = this.shader.getUniformLocation("gProj"); + gDepthMapUniform = this.shader.getUniformLocation("gDepthMap"); // Fog uniforms fogColorUniform = this.shader.getUniformLocation("fogColor"); fullFogModeUniform = this.shader.getUniformLocation("fullFogMode"); @@ -53,6 +60,10 @@ public class FogShader extends AbstractShaderRenderer { nearFogLengthUniform = this.shader.tryGetUniformLocation("nearFogLength"); } + @Override + void setVertexAttributes() { + va.setVertexAttribute(0, 0, VertexAttribute.VertexPointer.addVec2Pointer(false)); + }; @Override void setShaderUniforms(float partialTicks) { @@ -62,8 +73,19 @@ public class FogShader extends AbstractShaderRenderer { vanillaDrawDistance += 32; // Give it a 2 chunk boundary for near fog. - this.shader.setUniform(worldYOffsetUniform, (float) MC.getWrappedClientWorld().getMinHeight()); + Mat4f perspective = Mat4f.perspective( + (float) MC_RENDER.getFov(partialTicks), + MC_RENDER.getTargetFrameBufferViewportWidth() / (float) MC_RENDER.getTargetFrameBufferViewportHeight(), + RenderUtil.getNearClipPlaneDistanceInBlocks(partialTicks), + (float) ((lodDrawDistance + LodUtil.REGION_WIDTH) * Math.sqrt(2))); + + +// if (worldYOffsetUniform != -1) this.shader.setUniform(worldYOffsetUniform, (float) MC.getWrappedClientWorld().getMinHeight()); + + + this.shader.setUniform(this.shader.getUniformLocation("gProj"), perspective); + GL32.glUniform1i(gDepthMapUniform, 0); // Fog this.shader.setUniform(fullFogModeUniform, MC_RENDER.isFogStateSpecial() ? 1 : 0); this.shader.setUniform(fogColorUniform, MC_RENDER.isFogStateSpecial() ? getSpecialFogColor(partialTicks) : getFogColor(partialTicks)); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java index db7a18cf6..d7fb1e8d8 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java @@ -1,6 +1,7 @@ package com.seibel.distanthorizons.core.render.renderer.shaders; import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram; +import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexAttribute; import com.seibel.distanthorizons.core.util.LodUtil; import com.seibel.distanthorizons.core.util.RenderUtil; import com.seibel.distanthorizons.coreapi.util.math.Mat4f; @@ -16,9 +17,9 @@ public class SSAOShader extends AbstractShaderRenderer { public SSAOShader() { super( new ShaderProgram("shaders/normal.vert", "shaders/ssao/ao.frag", - "fragColor", new String[]{"vPos"}), + "fragColor", new String[]{"vPosition"}), new ShaderProgram("shaders/normal.vert", "shaders/ssao/apply-frag.frag", - "fragColor", new String[]{"vPos"}) + "fragColor", new String[]{"vPosition"}) ); } @@ -28,6 +29,11 @@ public class SSAOShader extends AbstractShaderRenderer { kernel = genKernel(); } + @Override + void setVertexAttributes() { + va.setVertexAttribute(0, 0, VertexAttribute.VertexPointer.addVec2Pointer(false)); + } + @Override void setShaderUniforms(float partialTicks) { Mat4f perspective = Mat4f.perspective( diff --git a/core/src/main/resources/assets/distanthorizons/lang/en_us.json b/core/src/main/resources/assets/distanthorizons/lang/en_us.json index c4da69c7b..1bdabf28d 100644 --- a/core/src/main/resources/assets/distanthorizons/lang/en_us.json +++ b/core/src/main/resources/assets/distanthorizons/lang/en_us.json @@ -224,7 +224,7 @@ "distanthorizons.config.client.advanced.graphics.noiseTextureSettings.noiseDropoff": "Noise Dropoff", "distanthorizons.config.client.advanced.graphics.noiseTextureSettings.noiseDropoff.@tooltip": - "How far should the noise texture render before it fades away? \n\n0.0 - the noise texture will render the entire LOD render distance. \n3.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). \nSet to 0 to disable noise from fading away.", "distanthorizons.config.client.advanced.graphics.advancedGraphics": diff --git a/core/src/main/resources/shaders/flat_shaded.frag b/core/src/main/resources/shaders/flat_shaded.frag index 3d7632a2b..99a6b47ec 100644 --- a/core/src/main/resources/shaders/flat_shaded.frag +++ b/core/src/main/resources/shaders/flat_shaded.frag @@ -6,16 +6,18 @@ 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; /* ========MARCO DEFINED BY RUNTIME CODE GEN========= @@ -84,20 +86,80 @@ 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) { + vec3 vertexNormal = normalize(cross(dFdx(vPos.xyz), dFdy(vPos.xyz))); + // This bit of code is required to fix the vertex position problem cus of floats in the verted world position varuable + 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 + // This is so that it can apply after the SSAO (work for this has started in the FogShader file and fog/fog.frag shader) 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 +177,8 @@ void main() float mixedFogThickness = clamp(mixFogThickness( nearFogThickness, farFogThickness, heightFogThickness), 0.0, 1.0); - returnColor = mix(vertexColor, 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); -// } + fragColor = mix(fragColor, vec4(fogColor.rgb, 1.0), mixedFogThickness); } - - // If "w" is just set to just 1. then it would crash - fragColor = returnColor; } @@ -179,13 +190,13 @@ float linearFog(float x, float fogStart, float fogLength, float fogMin, float fo } float exponentialFog(float x, float fogStart, float fogLength, - float fogMin, float fogRange, float fogDensity) { +float fogMin, float fogRange, float fogDensity) { x = max((x-fogStart)/fogLength, 0.0) * fogDensity; return fogMin + fogRange - fogRange/exp(x); } float exponentialSquaredFog(float x, float fogStart, float fogLength, - float fogMin, float fogRange, float fogDensity) { +float fogMin, float fogRange, float fogDensity) { x = max((x-fogStart)/fogLength, 0.0) * fogDensity; return fogMin + fogRange - fogRange/exp(x*x); } \ No newline at end of file diff --git a/core/src/main/resources/shaders/fog/fog.frag b/core/src/main/resources/shaders/fog/fog.frag index d4a5a4653..d19f59906 100644 --- a/core/src/main/resources/shaders/fog/fog.frag +++ b/core/src/main/resources/shaders/fog/fog.frag @@ -1,10 +1,12 @@ -in vec3 vertexWorldPos; -in float vertexYPos; -//in vec2 TexCoord; +in vec2 TexCoord; + +//in float vertexYPos; out vec4 fragColor; +uniform sampler2D gDepthMap; +uniform mat4 gProj; uniform float fogScale; uniform float fogVerticalScale; @@ -15,6 +17,20 @@ uniform int fullFogMode; uniform vec4 fogColor; +/* ========MARCO DEFINED BY RUNTIME CODE GEN========= + +float farFogStart; +float farFogLength; +float farFogMin; +float farFogRange; +float farFogDensity; + +float heightFogStart; +float heightFogLength; +float heightFogMin; +float heightFogRange; +float heightFogDensity; +*/ // method definitions // ==== The below 5 methods will be run-time generated. ==== @@ -42,6 +58,20 @@ float mod(float x, int y) { } +vec3 calcViewPosition(vec2 coords) { + float fragmentDepth = texture(gDepthMap, coords).r; + + vec4 ndc = vec4( + coords.x * 2.0 - 1.0, + coords.y * 2.0 - 1.0, + fragmentDepth * 2.0 - 1.0, + 1.0 + ); + + vec4 vs_pos = inverse(gProj) * ndc; + vs_pos.xyz = vs_pos.xyz / vs_pos.w; + return vs_pos.xyz; +} /** * Fragment shader for fog. @@ -50,6 +80,9 @@ float mod(float x, int y) { * version: 2023-6-21 */ void main() { + float vertexYPos = 100f; + vec3 vertexWorldPos = calcViewPosition(TexCoord); + if (fullFogMode != 0) { fragColor = vec4(fogColor.r, fogColor.g, fogColor.b, 1.); } else { @@ -70,16 +103,10 @@ void main() { // Testing // if (fragColor.r != 6969.) { // This line is so that the compiler doesnt delete the previos code -//// fragColor = vec4( -//// mod(vertexWorldPos.x, 1), -//// mod(vertexWorldPos.y, 1), -//// mod(vertexWorldPos.z, 1), -//// 1. -//// ); // fragColor = vec4( -// mod(vertexYPos, 1), -// mod(vertexYPos, 1), -// mod(vertexYPos, 1), +// mod(texture(gDepthMap, TexCoord).x, 1), +// mod(texture(gDepthMap, TexCoord).y, 1), +// mod(texture(gDepthMap, TexCoord).z, 1), // 1. // ); // } diff --git a/core/src/main/resources/shaders/fog/fog.vert b/core/src/main/resources/shaders/fog/fog.vert deleted file mode 100644 index 463249402..000000000 --- a/core/src/main/resources/shaders/fog/fog.vert +++ /dev/null @@ -1,19 +0,0 @@ -#version 150 core - - -//uniform vec3 modelOffset; -uniform float worldYOffset; - -in vec2 vPos; -in uvec4 vPosition; -out vec3 vertexWorldPos; -out float vertexYPos; - - -void main() -{ -// vertexWorldPos = vPosition.xyz + modelOffset; - vertexYPos = vPosition.y + worldYOffset; - - gl_Position = vec4(vPos, 1.0, 1.0); -} \ No newline at end of file diff --git a/core/src/main/resources/shaders/normal.vert b/core/src/main/resources/shaders/normal.vert index 1485baf0e..fe4bfe03b 100644 --- a/core/src/main/resources/shaders/normal.vert +++ b/core/src/main/resources/shaders/normal.vert @@ -1,11 +1,11 @@ #version 150 core -in vec2 vPos; +in vec2 vPosition; out vec2 TexCoord; void main() { - gl_Position = vec4(vPos, 1.0, 1.0); - TexCoord = vPos.xy * 0.5 + 0.5; + gl_Position = vec4(vPosition, 1.0, 1.0); + TexCoord = vPosition.xy * 0.5 + 0.5; } \ No newline at end of file diff --git a/core/src/main/resources/shaders/ssao/ao.frag b/core/src/main/resources/shaders/ssao/ao.frag index d8d77ccf0..15f648764 100644 --- a/core/src/main/resources/shaders/ssao/ao.frag +++ b/core/src/main/resources/shaders/ssao/ao.frag @@ -1,7 +1,6 @@ #version 150 core in vec2 TexCoord; -in vec2 ViewRay; out vec4 fragColor;