diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-05-04 18:36:40 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-05-04 18:42:22 +0300 |
commit | 5601a62179642f53ef9b04826c4c9ca5437c0097 (patch) | |
tree | 3afad2be78d1369eb611ec6976fb3ead187001ad /source/blender/draw/engines/eevee/shaders | |
parent | a3d8ef059cf831ec032977079a837214e7c92122 (diff) |
Eevee: Simple Camera Motion Blur.
Disabled by default. Set ENABLE_EFFECT_MOTION_BLUR to 1 to enable.
No fancy motion blur. Use depth and camera matrix to get the motion vectors. Then blur in this direction.
Only available in camera view.
Only Camera animation is supported, does not take into account the parents motion
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders')
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/effect_motion_blur_frag.glsl | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/effect_motion_blur_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_motion_blur_frag.glsl new file mode 100644 index 00000000000..e603769c9c8 --- /dev/null +++ b/source/blender/draw/engines/eevee/shaders/effect_motion_blur_frag.glsl @@ -0,0 +1,59 @@ + +uniform sampler2D colorBuffer; +uniform sampler2D depthBuffer; + +uniform float blurAmount; + +/* current frame */ +uniform mat4 currInvViewProjMatrix; + +/* past frame frame */ +uniform mat4 pastViewProjMatrix; + +in vec4 uvcoordsvar; + +out vec4 FragColor; + +#define MAX_SAMPLE 16 + +float wang_hash_noise(uint s) +{ + uint seed = (uint(gl_FragCoord.x) * 1664525u + uint(gl_FragCoord.y)) + s; + + seed = (seed ^ 61u) ^ (seed >> 16u); + seed *= 9u; + seed = seed ^ (seed >> 4u); + seed *= 0x27d4eb2du; + seed = seed ^ (seed >> 15u); + + float value = float(seed); + value *= 1.0 / 4294967296.0; + return fract(value); +} + +void main() +{ + vec3 ndc_pos; + ndc_pos.xy = uvcoordsvar.xy; + ndc_pos.z = texture(depthBuffer, uvcoordsvar.xy).x; + + float noise = 2.0 * wang_hash_noise(0u) / MAX_SAMPLE; + + /* Normalize Device Coordinates are [-1, +1]. */ + ndc_pos = ndc_pos * 2.0 - 1.0; + + vec4 p = currInvViewProjMatrix * vec4(ndc_pos, 1.0); + vec3 world_pos = p.xyz / p.w; /* Perspective divide */ + + /* Now find where was this pixel position + * inside the past camera viewport */ + vec4 old_ndc = pastViewProjMatrix * vec4(world_pos, 1.0); + old_ndc.xyz /= old_ndc.w; /* Perspective divide */ + + vec2 motion = (ndc_pos.xy - old_ndc.xy) * blurAmount; + + const float inc = 2.0 / MAX_SAMPLE; + for (float i = -1.0 + noise; i < 1.0; i += inc) { + FragColor += texture(colorBuffer, uvcoordsvar.xy + motion * i) / MAX_SAMPLE; + } +} |