From 37155ddf6b010946e7c85fa0cf332898ed4eeea6 Mon Sep 17 00:00:00 2001 From: Lubos Lenco Date: Wed, 23 Mar 2016 00:17:21 +0100 Subject: [PATCH] Begin motion blur. --- Assets/motion_blur_material.json | 16 ++++++++ raw/compile.py | 4 ++ raw/deferred/deferred.frag.glsl | 4 +- raw/deferred_light/deferred_light.frag.glsl | 2 +- .../motion_blur_pass.frag.glsl | 28 ++++++++++++++ .../motion_blur_pass.shader.json | 38 +++++++++++++++++++ .../motion_blur_pass.vert.glsl | 18 +++++++++ 7 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 Assets/motion_blur_material.json create mode 100644 raw/motion_blur_pass/motion_blur_pass.frag.glsl create mode 100755 raw/motion_blur_pass/motion_blur_pass.shader.json create mode 100644 raw/motion_blur_pass/motion_blur_pass.vert.glsl diff --git a/Assets/motion_blur_material.json b/Assets/motion_blur_material.json new file mode 100644 index 00000000..93cf22f7 --- /dev/null +++ b/Assets/motion_blur_material.json @@ -0,0 +1,16 @@ +{ + "material_resources": [ + { + "contexts": [ + { + "bind_constants": [], + "bind_textures": [ + ], + "id": "motion_blur_pass" + } + ], + "id": "motion_blur_material", + "shader": "motion_blur_pass/motion_blur_pass" + } + ] +} diff --git a/raw/compile.py b/raw/compile.py index 1735029a..3e9de7d6 100644 --- a/raw/compile.py +++ b/raw/compile.py @@ -35,6 +35,10 @@ os.chdir('../blur_pass') make_resources.make('blur_pass.shader.json') make_variants.make('blur_pass.shader.json') +os.chdir('../motion_blur_pass') +make_resources.make('motion_blur_pass.shader.json') +make_variants.make('motion_blur_pass.shader.json') + # os.chdir('../combine_pass') # make_resources.make('combine_pass.shader.json') # make_variants.make('combine_pass.shader.json') diff --git a/raw/deferred/deferred.frag.glsl b/raw/deferred/deferred.frag.glsl index a8c26779..d0fbf398 100644 --- a/raw/deferred/deferred.frag.glsl +++ b/raw/deferred/deferred.frag.glsl @@ -81,7 +81,7 @@ void main() { // occlusion - gl_FragData[0] = vec4(normal.x * 0.5 + 0.5, normal.y * 0.5 + 0.5, normal.z * 0.5 + 0.5, depth); - gl_FragData[1] = vec4(position.xyz, roughness); + gl_FragData[0] = vec4(normal.xyz * 0.5 + 0.5, depth); + gl_FragData[1] = vec4(position.xyz * 0.5 + 0.5, roughness); gl_FragData[2] = vec4(baseColor.rgb, metalness); } diff --git a/raw/deferred_light/deferred_light.frag.glsl b/raw/deferred_light/deferred_light.frag.glsl index 3008ade8..7218e84c 100644 --- a/raw/deferred_light/deferred_light.frag.glsl +++ b/raw/deferred_light/deferred_light.frag.glsl @@ -141,7 +141,7 @@ void main() { float ao = texture(ssaotex, texCoord).r; // Normals, depth vec3 n = g0.rgb * 2.0 - 1.0; - vec3 p = g1.rgb; + vec3 p = g1.rgb * 2.0 - 1.0; //n = normalize(n); vec3 baseColor = g2.rgb; diff --git a/raw/motion_blur_pass/motion_blur_pass.frag.glsl b/raw/motion_blur_pass/motion_blur_pass.frag.glsl new file mode 100644 index 00000000..d0bef0e1 --- /dev/null +++ b/raw/motion_blur_pass/motion_blur_pass.frag.glsl @@ -0,0 +1,28 @@ +#version 450 + +#ifdef GL_ES +precision mediump float; +#endif + +uniform sampler2D gbuffer0; +uniform sampler2D gbuffer1; +uniform sampler2D gbuffer2; + +uniform sampler2D tex; +uniform mat4 prevVP; + +in vec2 texCoord; + +void main() { + vec4 col = texture(tex, texCoord); + + vec4 g0 = texture(gbuffer0, texCoord); + vec4 g1 = texture(gbuffer0, texCoord); + float depth = g0.a; + // vec3 p = getViewPos(texCoord, depth); + vec3 p = g1.rgb * 2.0 - 1.0; + + + + gl_FragColor = col; +} diff --git a/raw/motion_blur_pass/motion_blur_pass.shader.json b/raw/motion_blur_pass/motion_blur_pass.shader.json new file mode 100755 index 00000000..2ed310f1 --- /dev/null +++ b/raw/motion_blur_pass/motion_blur_pass.shader.json @@ -0,0 +1,38 @@ +{ + "contexts": [ + { + "id": "motion_blur_pass", + "params": [ + { + "id": "depth_write", + "value": "true" + }, + { + "id": "compare_mode", + "value": "always" + }, + { + "id": "cull_mode", + "value": "none" + }, + { + "id": "blend_source", + "value": "blend_one" + }, + { + "id": "blend_destination", + "value": "blend_zero" + } + ], + "links": [ + { + "id": "prevVP", + "link": "_prevViewProjectionMatrix" + } + ], + "texture_params": [], + "vertex_shader": "motion_blur_pass.vert.glsl", + "fragment_shader": "motion_blur_pass.frag.glsl" + } + ] +} diff --git a/raw/motion_blur_pass/motion_blur_pass.vert.glsl b/raw/motion_blur_pass/motion_blur_pass.vert.glsl new file mode 100644 index 00000000..e1cc9c08 --- /dev/null +++ b/raw/motion_blur_pass/motion_blur_pass.vert.glsl @@ -0,0 +1,18 @@ +#version 450 + +#ifdef GL_ES +precision highp float; +#endif + +in vec2 pos; + +out vec2 texCoord; + +const vec2 madd = vec2(0.5, 0.5); + +void main() { + // Scale vertex attribute to [0-1] range + texCoord = pos.xy * madd + madd; + + gl_Position = vec4(pos.xy, 0.0, 1.0); +}