aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2022-06-19 21:18:45 +0200
committermakamys <makamys@outlook.com>2022-06-19 21:18:45 +0200
commit5c706c39846ccb47307f2c410e53f24d58980673 (patch)
treec8af5e4b3e1482b36557bc306b69945a80a50183 /src/main
parenta621264ea3bbeab895b561c32ec0974e0fd58a9e (diff)
downloadNeodymium-5c706c39846ccb47307f2c410e53f24d58980673.tar.gz
Neodymium-5c706c39846ccb47307f2c410e53f24d58980673.tar.bz2
Neodymium-5c706c39846ccb47307f2c410e53f24d58980673.zip
Merge foggy and fogless fragment shader
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/makamys/neodymium/renderer/NeoRenderer.java11
-rw-r--r--src/main/resources/shaders/chunk.frag7
-rw-r--r--src/main/resources/shaders/chunk.vert19
-rw-r--r--src/main/resources/shaders/chunk_fog.frag34
4 files changed, 25 insertions, 46 deletions
diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
index ef5c9bd..5a20eae 100644
--- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
+++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
@@ -320,8 +320,13 @@ public class NeoRenderer {
glGetFloat(GL_FOG_COLOR, fogColorBuf);
fogColorBuf.limit(4);
- fogStartEnd.put(glGetFloat(GL_FOG_START));
- fogStartEnd.put(glGetFloat(GL_FOG_END));
+ if(Config.renderFog) {
+ fogStartEnd.put(glGetFloat(GL_FOG_START));
+ fogStartEnd.put(glGetFloat(GL_FOG_END));
+ } else {
+ fogStartEnd.put(-1);
+ fogStartEnd.put(-1);
+ }
fogStartEnd.flip();
glUniformMatrix4(u_modelView, false, modelView);
@@ -440,7 +445,7 @@ public class NeoRenderer {
int fragmentShader;
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(fragmentShader, Util.readFile(Config.renderFog ? "shaders/chunk_fog.frag" : "shaders/chunk.frag"));
+ glShaderSource(fragmentShader, Util.readFile("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 fae64b5..b11fcc8 100644
--- a/src/main/resources/shaders/chunk.frag
+++ b/src/main/resources/shaders/chunk.frag
@@ -9,6 +9,7 @@ in vec4 Viewport;
in mat4 ProjInv;
in vec4 FogColor;
in vec2 FogStartEnd;
+in float FogFactor;
flat in vec2 ProvokingTexCoord;
uniform sampler2D atlas;
@@ -29,5 +30,9 @@ void main()
vec4 rasterColor = ((texColor * colorMult) * lightyColor);
- FragColor = rasterColor;
+ if(FogFactor >= 0){
+ FragColor = vec4(mix(FogColor.xyz, rasterColor.xyz, FogFactor), rasterColor.w);
+ } else {
+ FragColor = rasterColor;
+ }
}
diff --git a/src/main/resources/shaders/chunk.vert b/src/main/resources/shaders/chunk.vert
index 573acdd..44101bb 100644
--- a/src/main/resources/shaders/chunk.vert
+++ b/src/main/resources/shaders/chunk.vert
@@ -36,14 +36,17 @@ void main()
ProjInv = projInv;
FogColor = fogColor;
- float s = fogStartEnd.x;
- float e = fogStartEnd.y;
- vec4 eyePos = (modelView * (vec4(aPos - playerPos, 1.0) + vec4(0, 0.12, 0, 0)));
-
- float fogFactor = clamp((e - length(eyePos)) / (e - s), 0, 1);
-
- FogFactor = fogFactor;
-
+ if(fogStartEnd.x >= 0 && fogStartEnd.y >= 0){
+ float s = fogStartEnd.x;
+ float e = fogStartEnd.y;
+ vec4 eyePos = (modelView * (vec4(aPos - playerPos, 1.0) + vec4(0, 0.12, 0, 0)));
+
+ float fogFactor = clamp((e - length(eyePos)) / (e - s), 0, 1);
+
+ FogFactor = fogFactor;
+ } else {
+ FogFactor = -1;
+ }
FogStartEnd = fogStartEnd;
ProvokingTexCoord = aTexCoord;
diff --git a/src/main/resources/shaders/chunk_fog.frag b/src/main/resources/shaders/chunk_fog.frag
deleted file mode 100644
index ade0881..0000000
--- a/src/main/resources/shaders/chunk_fog.frag
+++ /dev/null
@@ -1,34 +0,0 @@
-#version 330 core
-out vec4 FragColor;
-
-in vec2 TexCoord;
-in vec2 BTexCoord;
-in vec4 Color;
-in vec4 SPos;
-in vec4 Viewport;
-in mat4 ProjInv;
-in vec4 FogColor;
-in vec2 FogStartEnd;
-in float FogFactor;
-flat in vec2 ProvokingTexCoord;
-
-uniform sampler2D atlas;
-uniform sampler2D lightTex;
-
-void main()
-{
- float wrappedU = mod(SPos.x, 1.0);
- float wrappedV = mod(SPos.y, 1.0);
-
- vec2 goodTexCoord = ProvokingTexCoord.xy + (((TexCoord.xy - ProvokingTexCoord.xy) / SPos.zw) * vec2(wrappedU, wrappedV));
-
- vec4 texColor = texture(atlas, goodTexCoord);
-
- vec4 colorMult = Color/256.0;
-
- vec4 lightyColor = texture(lightTex, (BTexCoord + 8.0) / 256.0);
-
- vec4 rasterColor = ((texColor * colorMult) * lightyColor);
-
- FragColor = vec4(mix(FogColor.xyz, rasterColor.xyz, FogFactor), rasterColor.w);
-}