From 779d2c5f64e321cc126b3e3abed9e37fd30edb1b Mon Sep 17 00:00:00 2001 From: Lars Hofhansl Date: Thu, 20 Oct 2016 22:21:49 -0700 Subject: [PATCH] Shaders: Harmonize Irrlicht and shader fog calculations --- client/shaders/nodes_shader/opengl_fragment.glsl | 8 ++++---- client/shaders/water_surface_shader/opengl_fragment.glsl | 8 ++++---- client/shaders/wielded_shader/opengl_fragment.glsl | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/client/shaders/nodes_shader/opengl_fragment.glsl b/client/shaders/nodes_shader/opengl_fragment.glsl index 654b1396d..299de2749 100644 --- a/client/shaders/nodes_shader/opengl_fragment.glsl +++ b/client/shaders/nodes_shader/opengl_fragment.glsl @@ -197,14 +197,14 @@ void main(void) #if MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT float alpha = gl_Color.a; if (fogDistance != 0.0) { - float d = max(0.0, min(length(eyeVec) / fogDistance * 1.5 - 0.6, 1.0)); - alpha = mix(alpha, 0.0, d); + float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0); + alpha = mix(0.0, alpha, d); } col = vec4(col.rgb, alpha); #else if (fogDistance != 0.0) { - float d = max(0.0, min(length(eyeVec) / fogDistance * 1.5 - 0.6, 1.0)); - col = mix(col, skyBgColor, d); + float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0); + col = mix(skyBgColor, col, d); } col = vec4(col.rgb, base.a); #endif diff --git a/client/shaders/water_surface_shader/opengl_fragment.glsl b/client/shaders/water_surface_shader/opengl_fragment.glsl index 1aa721f83..8321ddf93 100644 --- a/client/shaders/water_surface_shader/opengl_fragment.glsl +++ b/client/shaders/water_surface_shader/opengl_fragment.glsl @@ -153,14 +153,14 @@ vec4 base = texture2D(baseTexture, uv).rgba; #if MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE float alpha = gl_Color.a; if (fogDistance != 0.0) { - float d = max(0.0, min(length(eyeVec) / fogDistance * 1.5 - 0.6, 1.0)); - alpha = mix(alpha, 0.0, d); + float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0); + alpha = mix(0.0, alpha, d); } col = vec4(col.rgb, alpha); #else if (fogDistance != 0.0) { - float d = max(0.0, min(length(eyeVec) / fogDistance * 1.5 - 0.6, 1.0)); - col = mix(col, skyBgColor, d); + float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0); + col = mix(skyBgColor, col, d); } col = vec4(col.rgb, base.a); #endif diff --git a/client/shaders/wielded_shader/opengl_fragment.glsl b/client/shaders/wielded_shader/opengl_fragment.glsl index afb8cc32d..bd9741441 100644 --- a/client/shaders/wielded_shader/opengl_fragment.glsl +++ b/client/shaders/wielded_shader/opengl_fragment.glsl @@ -107,8 +107,8 @@ void main(void) vec4 col = vec4(color.rgb, base.a); col *= gl_Color; if (fogDistance != 0.0) { - float d = max(0.0, min(length(eyeVec) / fogDistance * 1.5 - 0.6, 1.0)); - col = mix(col, skyBgColor, d); + float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0); + col = mix(skyBgColor, col, d); } gl_FragColor = vec4(col.rgb, base.a); }