motion blur

This commit is contained in:
milek7
2018-07-23 01:22:36 +02:00
parent cfb066f678
commit d5ce1d57e7
32 changed files with 358 additions and 159 deletions

View File

@@ -11,5 +11,6 @@ uniform sampler2D tex1;
void main()
{
vec4 tex_color = texture(tex1, f_coord);
gl_FragColor = tex_color * param[0];
gl_FragData[0] = tex_color * param[0];
gl_FragData[1] = vec4(0.0f);
}

View File

@@ -6,5 +6,6 @@ in vec3 f_color;
void main()
{
gl_FragColor = vec4(f_color, 1.0f);
gl_FragData[0] = vec4(f_color, 1.0f);
gl_FragData[1] = vec4(0.0f);
}

View File

@@ -2,6 +2,9 @@
#include <common>
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
void main()
{
float x = (gl_PointCoord.x - 0.5f) * 2.0f;
@@ -9,5 +12,11 @@ void main()
float dist2 = abs(x * x + y * y);
if (dist2 > 0.5f * 0.5f)
discard;
gl_FragColor = vec4(param[0].rgb * emission, 1.0f);
gl_FragData[0] = vec4(param[0].rgb * emission, 1.0f);
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
gl_FragData[1] = vec4(a - b, 0.0f, 0.0f);
}
}

View File

@@ -6,7 +6,13 @@ layout(location = 2) in vec2 v_coord;
#include <common>
out vec4 f_clip_pos;
out vec4 f_clip_future_pos;
void main()
{
gl_Position = (projection * 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);
gl_Position = f_clip_pos;
}

View File

@@ -25,9 +25,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), normalize(-lights[0].dir)), 0.0);
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) * fog_density));
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);
}
@@ -40,7 +40,7 @@ vec2 calc_light(vec3 light_dir)
#else
vec3 normal = normalize(f_normal);
#endif
vec3 view_dir = normalize(vec3(0.0f, 0.0f, 0.0f) - f_pos);
vec3 view_dir = normalize(vec3(0.0f, 0.0f, 0.0f) - f_pos.xyz);
vec3 halfway_dir = normalize(light_dir + view_dir);
float diffuse_v = max(dot(normal, light_dir), 0.0);
@@ -51,10 +51,10 @@ vec2 calc_light(vec3 light_dir)
vec2 calc_point_light(light_s light)
{
vec3 light_dir = normalize(light.pos - f_pos);
vec3 light_dir = normalize(light.pos - f_pos.xyz);
vec2 val = calc_light(light_dir);
float distance = length(light.pos - f_pos);
float distance = length(light.pos - f_pos.xyz);
float atten = 1.0f / (1.0f + light.linear * distance + light.quadratic * (distance * distance));
return val * atten;
@@ -62,7 +62,7 @@ vec2 calc_point_light(light_s light)
vec2 calc_spot_light(light_s light)
{
vec3 light_dir = normalize(light.pos - f_pos);
vec3 light_dir = normalize(light.pos - f_pos.xyz);
float theta = dot(light_dir, normalize(-light.dir));
float epsilon = light.in_cutoff - light.out_cutoff;

View File

@@ -2,7 +2,7 @@
in vec3 f_normal;
in vec2 f_coord;
in vec3 f_pos;
in vec4 f_pos;
#texture (tex1, 0, sRGB_A)
uniform sampler2D tex1;
@@ -12,5 +12,6 @@ uniform sampler2D tex1;
void main()
{
vec4 tex_color = texture(tex1, f_coord);
gl_FragColor = tex_color * param[0];
gl_FragData[0] = tex_color * param[0];
gl_FragData[1] = vec4(0.0f);
}

View File

@@ -2,9 +2,12 @@
in vec3 f_normal;
in vec2 f_coord;
in vec3 f_pos;
in vec4 f_pos;
in vec4 f_light_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
#param (color, 0, 0, 4, diffuse)
@@ -22,7 +25,7 @@ void main()
vec4 tex_color = vec4(param[0].rgb, 1.0f);
vec3 normal = normalize(f_normal);
vec3 refvec = reflect(f_pos, normal);
vec3 refvec = reflect(f_pos.xyz, normal);
vec3 envcolor = texture(envmap, refvec).rgb;
vec3 result = ambient * 0.5 + param[0].rgb * emission;
@@ -49,5 +52,11 @@ void main()
result += light.color * (part.x * param[1].x + part.y * param[1].y);
}
gl_FragColor = vec4(apply_fog(result * tex_color.rgb), tex_color.a);
gl_FragData[0] = vec4(apply_fog(result * tex_color.rgb), tex_color.a);
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
gl_FragData[1] = vec4(a - b, 0.0f, 0.0f);
}
}

View File

@@ -2,9 +2,12 @@
in vec3 f_normal;
in vec2 f_coord;
in vec3 f_pos;
in vec4 f_pos;
in vec4 f_light_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
#param (color, 0, 0, 4, diffuse)
@@ -28,7 +31,7 @@ void main()
discard;
vec3 normal = normalize(f_normal);
vec3 refvec = reflect(f_pos, normal);
vec3 refvec = reflect(f_pos.xyz, normal);
vec3 envcolor = texture(envmap, refvec).rgb;
vec3 result = ambient * 0.5 + param[0].rgb * emission;
@@ -55,5 +58,13 @@ void main()
result += light.color * (part.x * param[1].x + part.y * param[1].y);
}
gl_FragColor = vec4(apply_fog(result * tex_color.rgb), tex_color.a);
gl_FragData[0] = vec4(apply_fog(result * tex_color.rgb), tex_color.a);
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
gl_FragData[1] = vec4(a - b, 0.0f, tex_color.a < 0.9f ? 0.0f : 1.0f);
}
}

View File

@@ -4,5 +4,6 @@
void main()
{
gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);
gl_FragData[0] = vec4(1.0, 0.0, 1.0, 1.0);
gl_FragData[1] = vec4(0.0f);
}

View File

@@ -2,10 +2,13 @@
in vec3 f_normal;
in vec2 f_coord;
in vec3 f_pos;
in vec4 f_pos;
in mat3 f_tbn;
in vec4 f_light_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
#param (color, 0, 0, 4, diffuse)
@@ -33,7 +36,7 @@ void main()
discard;
vec3 normal = f_tbn * normalize(texture(normalmap, f_coord).rgb * 2.0 - 1.0);
vec3 refvec = reflect(f_pos, normal);
vec3 refvec = reflect(f_pos.xyz, normal);
vec3 envcolor = texture(envmap, refvec).rgb;
vec3 result = ambient * 0.5 + param[0].rgb * emission;
@@ -60,5 +63,11 @@ void main()
result += light.color * (part.x * param[1].x + part.y * param[1].y);
}
gl_FragColor = vec4(apply_fog(result * tex_color.rgb), tex_color.a);
gl_FragData[0] = vec4(apply_fog(result * tex_color.rgb), tex_color.a);
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
gl_FragData[1] = vec4(a - b, 0.0f, 0.0f);
}
}

View File

@@ -2,9 +2,12 @@
in vec3 f_normal;
in vec2 f_coord;
in vec3 f_pos;
in vec4 f_pos;
in vec4 f_light_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
#param (color, 0, 0, 4, diffuse)
@@ -31,7 +34,7 @@ void main()
discard;
vec3 normal = normalize(f_normal);
vec3 refvec = reflect(f_pos, normal);
vec3 refvec = reflect(f_pos.xyz, normal);
vec3 envcolor = texture(envmap, refvec).rgb;
vec3 result = ambient * 0.5 + param[0].rgb * emission;
@@ -58,5 +61,12 @@ void main()
result += light.color * (part.x * param[1].x + part.y * param[1].y);
}
gl_FragColor = vec4(apply_fog(result * tex_color.rgb), tex_color.a);
gl_FragData[0] = vec4(apply_fog(result * tex_color.rgb), tex_color.a);
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
gl_FragData[1] = vec4(a - b, 0.0f, 0.0f);
}
}

View File

@@ -13,5 +13,6 @@ void main()
discard;
// color data is shared with normals, ugh
gl_FragColor = vec4(f_normal_raw.bgr, 1.0f);
gl_FragData[0] = vec4(f_normal_raw.bgr, 1.0f);
gl_FragData[1] = vec4(0.0f);
}

View File

@@ -0,0 +1,30 @@
#version 330 core
in vec2 f_coords;
#texture (color_tex, 0, RGB)
uniform sampler2D color_tex;
#texture (velocity_tex, 1, RG)
uniform sampler2D velocity_tex;
#include <common>
void main()
{
vec2 texelSize = 1.0 / vec2(textureSize(color_tex, 0));
vec2 velocity = texture(velocity_tex, f_coords).rg * param[0].r;
float speed = length(velocity / texelSize);
int nSamples = clamp(int(speed), 1, 64);
vec4 oResult = texture(color_tex, f_coords);
for (int i = 1; i < nSamples; ++i)
{
vec2 offset = velocity * (float(i) / float(nSamples - 1) - 0.5);
oResult += texture(color_tex, f_coords + offset);
}
oResult /= float(nSamples);
gl_FragData[0] = oResult;
}

View File

@@ -2,7 +2,16 @@
#include <common>
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
void main()
{
gl_FragColor = param[0];
gl_FragData[0] = param[0];
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
gl_FragData[1] = vec4(a - b, 0.0f, 0.0f);
}
}

View File

@@ -6,7 +6,13 @@ layout(location = 2) in vec2 v_coord;
#include <common>
out vec4 f_clip_pos;
out vec4 f_clip_future_pos;
void main()
{
gl_Position = (projection * 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);
gl_Position = f_clip_pos;
}

View File

@@ -8,22 +8,29 @@ layout(location = 3) in vec4 v_tangent;
out vec3 f_normal;
flat out vec3 f_normal_raw;
out vec2 f_coord;
out vec3 f_pos;
out vec4 f_pos;
out mat3 f_tbn;
out vec4 f_tangent;
out vec4 f_light_pos;
out vec4 f_clip_pos;
out vec4 f_clip_future_pos;
#include <common>
void main()
{
gl_Position = (projection * modelview) * vec4(v_vert, 1.0f);
f_normal = modelviewnormal * v_normal;
f_normal_raw = v_normal;
f_coord = v_coord;
f_tangent = v_tangent;
f_pos = vec3(modelview * vec4(v_vert, 1.0f));
f_light_pos = lightview * vec4(f_pos, 1.0f);
f_pos = modelview * vec4(v_vert, 1.0f);
f_light_pos = lightview * f_pos;
f_clip_pos = (projection * modelview) * vec4(v_vert, 1.0f);
f_clip_future_pos = (projection * future * modelview) * vec4(v_vert, 1.0f);
gl_Position = f_clip_pos;
vec3 T = normalize(modelviewnormal * v_tangent.xyz);
vec3 B = normalize(modelviewnormal * cross(v_normal, v_tangent.xyz) * v_tangent.w);