Files

45 lines
1.2 KiB
GLSL

// MinecraftPT — MotionBlur_FS
// Per-pixel camera motion blur using motion vectors.
#include "/Lib/Settings.glsl"
#include "/Lib/Utilities.glsl"
#include "/Lib/BasicFunctions/TemporalNoise.glsl"
uniform sampler2D colortex12;
uniform sampler2D colortex10;
layout(location = 0) out vec4 colorOut;
void main(){
vec2 texelCoord = gl_FragCoord.xy;
vec3 color = texelFetch(colortex12, ivec2(texelCoord), 0).rgb;
#ifdef MOTION_BLUR
if (MOTION_BLUR > 0){
vec2 motion = texelFetch(colortex10, ivec2(texelCoord * 0.5), 0).xy * 2.0;
float speed = length(motion);
if (speed > 0.5){
// Shutter angle sampling
float shutterAngle = mix(90.0, 360.0, MOTION_BLUR_SUTTER_SPEED);
float samples = float(MOTION_BLUR_QUALITY);
float dither = BlueNoiseTemporal();
vec2 dir = normalize(motion);
float length = min(speed, 32.0) * 0.5;
vec3 acc = vec3(0.0);
for (int i = 0; i < MOTION_BLUR_QUALITY; i++){
float t = (float(i) + dither) / samples - 0.5;
vec2 sampleCoord = texelCoord + dir * length * t;
acc += textureLod(colortex12, sampleCoord / screenSize, 0.0).rgb;
}
color = acc / samples;
}
}
#endif
colorOut = vec4(color, 1.0);
}