aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2022-06-30 12:32:20 +0200
committermakamys <makamys@outlook.com>2022-06-30 12:32:20 +0200
commitc25a4aa69cbababb6c961bcb665841db3ebf127d (patch)
treebe949a9974f525cf911078da3c3404d182a2615d /src
parent88622cb5c118bb73a30da4716f8e4f8c677622a7 (diff)
downloadNeodymium-c25a4aa69cbababb6c961bcb665841db3ebf127d.tar.gz
Neodymium-c25a4aa69cbababb6c961bcb665841db3ebf127d.tar.bz2
Neodymium-c25a4aa69cbababb6c961bcb665841db3ebf127d.zip
Implement exponential fog
Diffstat (limited to 'src')
-rw-r--r--src/main/java/makamys/neodymium/renderer/NeoRenderer.java4
-rw-r--r--src/main/resources/shaders/chunk.vert7
2 files changed, 10 insertions, 1 deletions
diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
index 6a1c1e9..8d15eed 100644
--- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
+++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
@@ -332,6 +332,8 @@ public class NeoRenderer {
int u_projInv = glGetUniformLocation(shaderProgram, "projInv");
int u_fogColor = glGetUniformLocation(shaderProgram, "fogColor");
int u_fogStartEnd = glGetUniformLocation(shaderProgram, "fogStartEnd");
+ int u_fogMode = glGetUniformLocation(shaderProgram, "fogMode");
+ int u_fogDensity = glGetUniformLocation(shaderProgram, "fogDensity");
glUniformMatrix4(u_modelView, false, modelView);
glUniformMatrix4(u_proj, false, projBuf);
@@ -339,6 +341,8 @@ public class NeoRenderer {
glUniform4f(u_viewport, viewportBuf.get(0),viewportBuf.get(1),viewportBuf.get(2),viewportBuf.get(3));
glUniform4(u_fogColor, fogColorBuf);
glUniform2(u_fogStartEnd, fogStartEnd);
+ glUniform1i(u_fogMode, glGetInteger(GL_FOG_MODE));
+ glUniform1f(u_fogDensity, glGetFloat(GL_FOG_DENSITY));
glUniform3f(u_playerPos, (float)eyePosX, (float)eyePosY, (float)eyePosZ);
diff --git a/src/main/resources/shaders/chunk.vert b/src/main/resources/shaders/chunk.vert
index 823b546..f983323 100644
--- a/src/main/resources/shaders/chunk.vert
+++ b/src/main/resources/shaders/chunk.vert
@@ -14,6 +14,8 @@ uniform mat4 projInv;
uniform vec4 viewport;
uniform vec4 fogColor;
uniform vec2 fogStartEnd;
+uniform int fogMode;
+uniform float fogDensity;
uniform vec3 playerPos;
@@ -49,7 +51,10 @@ void main()
vec4 eyePos = (modelView * (vec4(aPos - playerPos, 1.0) + vec4(0, 0.12, 0, 0)));
float c = length(eyePos);
- float fogFactor = clamp((e - c) / (e - s), 0, 1);
+ float fogFactor = fogMode == 0x2601
+ ? clamp((e - c) / (e - s), 0, 1) /* GL_LINEAR */
+ : exp(-fogDensity * c); /* GL_EXP */
+
FogFactor = fogFactor;
} else {