From e796bd0e697c7b9567a3264a4d743666f5df52a8 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 17 Sep 2021 19:16:57 +0300 Subject: [PATCH] Improved fog quality --- res/main.glslf | 5 ++++- res/main.glslv | 10 ++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/res/main.glslf b/res/main.glslf index 42e5d7ae..7528e68a 100644 --- a/res/main.glslf +++ b/res/main.glslf @@ -2,13 +2,16 @@ in vec4 a_color; in vec2 a_texCoord; +in float a_distance; out vec4 f_color; uniform sampler2D u_texture0; +uniform vec3 u_fogColor; void main(){ vec4 tex_color = texture(u_texture0, a_texCoord); if (tex_color.a < 0.5) discard; - f_color = a_color * tex_color; + float depth = (a_distance/256.0)*(a_distance/256.0)*256.0; + f_color = mix(a_color * tex_color, vec4(u_fogColor,1.0), min(1.0, depth/256.0)); } diff --git a/res/main.glslv b/res/main.glslv index 1e1cb98a..a0513030 100644 --- a/res/main.glslv +++ b/res/main.glslv @@ -6,17 +6,19 @@ layout (location = 2) in vec4 v_light; out vec4 a_color; out vec2 a_texCoord; +out float a_distance; uniform mat4 u_model; -uniform mat4 u_projview; +uniform mat4 u_proj; +uniform mat4 u_view; uniform vec3 u_skyLightColor; uniform float u_gamma; void main(){ - vec4 position = u_projview * u_model * vec4(v_position, 1.0); + vec4 viewmodelpos = u_view * u_model * vec4(v_position, 1.0); a_color = vec4(pow(v_light.rgb, vec3(u_gamma)),1.0f); a_texCoord = v_texCoord; a_color.rgb += u_skyLightColor * v_light.a*0.5; - a_color.rgb *= 1.0-position.z*0.0025; - gl_Position = position; + a_distance = length(viewmodelpos); + gl_Position = u_proj * viewmodelpos; }