From 8aca8bffe4e3a0a7a0731b025b3a847696f2eecb Mon Sep 17 00:00:00 2001 From: stele Date: Mon, 24 Dec 2018 23:50:17 +0100 Subject: [PATCH] Fog applied to line objects. --- shaders/apply_fog.glsl | 9 +++++++++ shaders/light_common.glsl | 12 ++---------- shaders/traction.frag | 4 +++- shaders/traction.vert | 2 ++ 4 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 shaders/apply_fog.glsl diff --git a/shaders/apply_fog.glsl b/shaders/apply_fog.glsl new file mode 100644 index 00000000..fc58fb15 --- /dev/null +++ b/shaders/apply_fog.glsl @@ -0,0 +1,9 @@ +vec3 apply_fog(vec3 color) +{ + float sun_amount = 0.0; + if (lights_count >= 1U && lights[0].type == LIGHT_DIR) + sun_amount = max(dot(normalize(f_pos.xyz), normalize(-lights[0].dir)), 0.0); + vec3 fog_color_v = mix(fog_color, lights[0].color, pow(sun_amount, 30.0)); + float fog_amount_v = 1.0 - min(1.0, exp(-length(f_pos.xyz) * fog_density)); + return mix(color, fog_color_v, fog_amount_v); +} \ No newline at end of file diff --git a/shaders/light_common.glsl b/shaders/light_common.glsl index 5d53a25d..aed7d107 100644 --- a/shaders/light_common.glsl +++ b/shaders/light_common.glsl @@ -1,3 +1,5 @@ +#include + float calc_shadow() { #if SHADOWMAP_ENABLED @@ -23,16 +25,6 @@ float calc_shadow() #endif } -vec3 apply_fog(vec3 color) -{ - float sun_amount = 0.0; - if (lights_count >= 1U && lights[0].type == LIGHT_DIR) - sun_amount = max(dot(normalize(f_pos.xyz), normalize(-lights[0].dir)), 0.0); - vec3 fog_color_v = mix(fog_color, lights[0].color, pow(sun_amount, 30.0)); - float fog_amount_v = 1.0 - min(1.0, exp(-length(f_pos.xyz) * fog_density)); - return mix(color, fog_color_v, fog_amount_v); -} - // [0] - diffuse, [1] - specular // do magic here vec2 calc_light(vec3 light_dir) diff --git a/shaders/traction.frag b/shaders/traction.frag index af40e8e3..f80639df 100644 --- a/shaders/traction.frag +++ b/shaders/traction.frag @@ -1,5 +1,6 @@ #include +in vec4 f_pos; in vec4 f_clip_pos; in vec4 f_clip_future_pos; @@ -9,10 +10,11 @@ layout(location = 1) out vec4 out_motion; #endif #include +#include void main() { - vec4 color = vec4(pow(param[0].rgb, vec3(2.2)), param[0].a); + vec4 color = vec4(apply_fog(pow(param[0].rgb, vec3(2.2))), param[0].a); #if POSTFX_ENABLED out_color = color; #else diff --git a/shaders/traction.vert b/shaders/traction.vert index 87ff1fa4..55d5bd9a 100644 --- a/shaders/traction.vert +++ b/shaders/traction.vert @@ -6,9 +6,11 @@ layout(location = 2) in vec2 v_coord; out vec4 f_clip_pos; out vec4 f_clip_future_pos; +out vec4 f_pos; void main() { + f_pos = modelview * vec4(v_vert, 1.0f); f_clip_pos = (projection * modelview) * vec4(v_vert, 1.0f); f_clip_future_pos = (projection * future * modelview) * vec4(v_vert, 1.0f);