#include <metal_stdlib>
using namespace metal;

struct FragmentIn {
  float4 position [[position]];
  float2 uv;
};

struct Uniforms {
  float decay;
  float3 padding;
};

fragment float4 fragment_main(
  FragmentIn in [[stage_in]],
  texture2d<float> current_tex [[texture(0)]],
  texture2d<float> accum_tex [[texture(1)]],
  sampler samp [[sampler(0)]],
  constant Uniforms &u [[buffer(0)]]
) {
  float4 current = current_tex.sample(samp, in.uv);
  float4 accum = accum_tex.sample(samp, in.uv);
  
  // Ghosting style motion blur
  return max(current, accum * u.decay);
}
