motionblur.lua 549 B

123456789101112131415161718192021
  1. local MotionBlur = {}
  2. MotionBlur.code = 'motionBlur'
  3. function MotionBlur:init()
  4. self:resize()
  5. end
  6. function MotionBlur:update()
  7. local v = ctx.view
  8. if v.target then
  9. local d = math.sqrt(math.abs(math.distance(v.x, v.y, v.target.x, v.target.y) - math.distance(v.prevx, v.prevy, v.target.x, v.target.y)))
  10. local dir = math.direction(v.x, v.y, v.prevx, v.prevy)
  11. self.shader:send('velocity', {math.dx(d, dir), math.dy(d, dir)})
  12. end
  13. end
  14. function MotionBlur:resize()
  15. self.shader = data.media.shaders.motionBlur
  16. end
  17. return MotionBlur