diff options
author | makamys <makamys@outlook.com> | 2022-06-08 23:12:52 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2022-06-08 23:37:36 +0200 |
commit | aa4ef7da768ea2f2f3c4e025d28fe3edb2ae4ea9 (patch) | |
tree | a092af7056cfb6967873251fadd2ae8db8a1295d /src | |
parent | 39bbc34b7f9ce1cad8889c4e9c5a082b223574e3 (diff) | |
download | Neodymium-aa4ef7da768ea2f2f3c4e025d28fe3edb2ae4ea9.tar.gz Neodymium-aa4ef7da768ea2f2f3c4e025d28fe3edb2ae4ea9.tar.bz2 Neodymium-aa4ef7da768ea2f2f3c4e025d28fe3edb2ae4ea9.zip |
Optimize fog
Now it gets me as much FPS as no fog! (370 fps; prior to this commit
fog reduced it to 230)
Diffstat (limited to 'src')
-rw-r--r-- | src/main/resources/shaders/chunk.vert | 10 | ||||
-rw-r--r-- | src/main/resources/shaders/chunk_fog.frag | 18 |
2 files changed, 12 insertions, 16 deletions
diff --git a/src/main/resources/shaders/chunk.vert b/src/main/resources/shaders/chunk.vert index 9901ef3..75ee0ab 100644 --- a/src/main/resources/shaders/chunk.vert +++ b/src/main/resources/shaders/chunk.vert @@ -20,6 +20,7 @@ out vec4 Viewport; out mat4 ProjInv; out vec4 FogColor; out vec2 FogStartEnd; +out float FogFactor; void main() { @@ -30,5 +31,14 @@ void main() Viewport = viewport; 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; + FogStartEnd = fogStartEnd; }
\ No newline at end of file diff --git a/src/main/resources/shaders/chunk_fog.frag b/src/main/resources/shaders/chunk_fog.frag index 36c10af..160ae65 100644 --- a/src/main/resources/shaders/chunk_fog.frag +++ b/src/main/resources/shaders/chunk_fog.frag @@ -8,6 +8,7 @@ in vec4 Viewport; in mat4 ProjInv; in vec4 FogColor; in vec2 FogStartEnd; +in float FogFactor; uniform sampler2D atlas; uniform sampler2D lightTex; @@ -21,20 +22,5 @@ void main() 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); + FragColor = vec4(mix(FogColor.xyz, rasterColor.xyz, FogFactor), rasterColor.w); } |