diff options
author | makamys <makamys@outlook.com> | 2022-06-08 00:50:54 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2022-06-08 00:50:54 +0200 |
commit | 8fddcbe0cbfd760c3d0f70864072edbb8cb09de0 (patch) | |
tree | a8f662bb59e85d45b3940ed43f9e2ff2073337a1 | |
parent | 3f0baea0952b7cb3e3eebe5d3a0bd0387c91b547 (diff) | |
download | Neodymium-8fddcbe0cbfd760c3d0f70864072edbb8cb09de0.tar.gz Neodymium-8fddcbe0cbfd760c3d0f70864072edbb8cb09de0.tar.bz2 Neodymium-8fddcbe0cbfd760c3d0f70864072edbb8cb09de0.zip |
Reenable fog but add option to disable it
-rw-r--r-- | src/main/java/makamys/lodmod/LODMod.java | 2 | ||||
-rw-r--r-- | src/main/java/makamys/lodmod/renderer/LODRenderer.java | 2 | ||||
-rw-r--r-- | src/main/resources/shaders/chunk.frag | 18 | ||||
-rw-r--r-- | src/main/resources/shaders/chunk_fog.frag | 40 |
4 files changed, 43 insertions, 19 deletions
diff --git a/src/main/java/makamys/lodmod/LODMod.java b/src/main/java/makamys/lodmod/LODMod.java index 30b708e..f86c695 100644 --- a/src/main/java/makamys/lodmod/LODMod.java +++ b/src/main/java/makamys/lodmod/LODMod.java @@ -71,6 +71,7 @@ public class LODMod public static boolean fogEventWasPosted; public static boolean ofFastRender; + public static boolean enableFog; @EventHandler public void preInit(FMLPreInitializationEvent event) @@ -113,6 +114,7 @@ public class LODMod sortFrequency = config.getInt("sortFrequency", "render", 1, 1, Integer.MAX_VALUE, ""); gcRate = config.getInt("gcRate", "render", 1, 1, Integer.MAX_VALUE, "Maximum number of meshes to relocate each frame."); VRAMSize = config.getInt("VRAMSize", "render", 1, 1, Integer.MAX_VALUE, "VRAM buffer size."); + enableFog = config.getBoolean("enableFog", "render", true, ""); if(config.hasChanged()) { config.save(); diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java index d194fe5..dec8276 100644 --- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java +++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java @@ -420,7 +420,7 @@ public class LODRenderer { int fragmentShader; fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(fragmentShader, Util.readFile("shaders/chunk.frag")); + glShaderSource(fragmentShader, Util.readFile(LODMod.enableFog ? "shaders/chunk_fog.frag" : "shaders/chunk.frag")); glCompileShader(fragmentShader); if(glGetShaderi(fragmentShader, GL_COMPILE_STATUS) == 0) { diff --git a/src/main/resources/shaders/chunk.frag b/src/main/resources/shaders/chunk.frag index 0f23b5f..cc03a70 100644 --- a/src/main/resources/shaders/chunk.frag +++ b/src/main/resources/shaders/chunk.frag @@ -21,23 +21,5 @@ void main() vec4 rasterColor = ((texColor * colorMult) * lightyColor); - // TODO reimplement fog in a way that's not a performance hog - /*float s = FogStartEnd.x; - float e = FogStartEnd.y; - - vec4 ndcPos; - ndcPos.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * Viewport.xy)) / (Viewport.zw) - 1; - ndcPos.z = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) / - (gl_DepthRange.far - gl_DepthRange.near); - ndcPos.w = 1.0; - - vec4 clipPos = ndcPos / gl_FragCoord.w; - vec4 eyePos = ProjInv * clipPos; - - float z = length(eyePos); - float f = (e - z) / (e - s); - f = clamp(f, 0, 1); - FragColor = mix(FogColor, rasterColor, f);*/ - FragColor = rasterColor; } diff --git a/src/main/resources/shaders/chunk_fog.frag b/src/main/resources/shaders/chunk_fog.frag new file mode 100644 index 0000000..ab188ab --- /dev/null +++ b/src/main/resources/shaders/chunk_fog.frag @@ -0,0 +1,40 @@ +#version 330 core +out vec4 FragColor; + +in vec2 TexCoord; +in vec2 BTexCoord; +in vec4 DaColor; +in vec4 Viewport; +in mat4 ProjInv; +in vec4 FogColor; +in vec2 FogStartEnd; + +uniform sampler2D atlas; +uniform sampler2D lightTex; + +void main() +{ + vec4 texColor = texture(atlas, TexCoord); + vec4 colorMult = DaColor/256.0; + + vec4 lightyColor = texture(lightTex, (BTexCoord + 8.0) / 256.0); + + vec4 rasterColor = ((texColor * colorMult) * lightyColor); + + float s = FogStartEnd.x; + float e = FogStartEnd.y; + + vec4 ndcPos; + ndcPos.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * Viewport.xy)) / (Viewport.zw) - 1; + ndcPos.z = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) / + (gl_DepthRange.far - gl_DepthRange.near); + ndcPos.w = 1.0; + + vec4 clipPos = ndcPos / gl_FragCoord.w; + vec4 eyePos = ProjInv * clipPos; + + float z = length(eyePos); + float f = (e - z) / (e - s); + f = clamp(f, 0, 1); + FragColor = mix(FogColor, rasterColor, f); +} |