bloom.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. Bloom = {}
  2. local g = love.graphics
  3. function Bloom:init()
  4. self:resize()
  5. self.alpha = .1
  6. end
  7. function Bloom:update()
  8. self.alpha = math.lerp(self.alpha, ctx.player.dead and .9 or .1, .6 * tickRate)
  9. end
  10. function Bloom:applyEffect(source, target)
  11. g.setCanvas(self.canvas)
  12. g.push()
  13. g.scale(.25)
  14. g.draw(source)
  15. g.pop()
  16. self.hblur:send('amount', .005)
  17. self.vblur:send('amount', .005)
  18. g.setColor(255, 255, 255)
  19. for i = 1, 6 do
  20. g.setShader(self.hblur)
  21. self.working:renderTo(function()
  22. g.draw(self.canvas)
  23. end)
  24. g.setShader(self.vblur)
  25. self.canvas:renderTo(function()
  26. g.draw(self.working)
  27. end)
  28. end
  29. g.setShader()
  30. g.setCanvas(target)
  31. g.draw(source)
  32. table.each(ctx.particles.particles, function(particle)
  33. if getmetatable(particle).__index == JujuSex then
  34. particle:draw()
  35. end
  36. end)
  37. local factor = ctx.player.dead and 1 or 1
  38. love.graphics.setColor(255, 255, 255, self.alpha * 100 * factor)
  39. g.setBlendMode('additive')
  40. g.draw(self.canvas, 0, 0, 0, 4, 4)
  41. local x = ctx.player.dead and math.clamp(ctx.player.ghost.x, 300, 500) or 400
  42. local y = ctx.player.dead and math.clamp(ctx.player.ghost.y, 0, 600) or 300
  43. for i = 6, 1, -1 do
  44. g.draw(self.canvas, x, y, 0, 4 + i * 1.25 * factor, 4 + i * 1.25 * factor, self.canvas:getWidth() / 2, self.canvas:getHeight() / 2)
  45. end
  46. g.setBlendMode('alpha')
  47. if ctx.player.dead then
  48. ctx.player.ghost:draw()
  49. table.each(ctx.jujus.jujus, function(juju) juju:draw() end)
  50. end
  51. g.setCanvas()
  52. self.canvas:clear()
  53. self.working:clear()
  54. end
  55. function Bloom:resize()
  56. local w, h = g.getDimensions()
  57. self.canvas = g.newCanvas(w / 4, h / 4)
  58. self.working = g.newCanvas(w / 4, h / 4)
  59. self.threshold = love.graphics.newShader('media/shaders/threshold.shader')
  60. self.hblur = love.graphics.newShader('media/shaders/horizontalBlur.shader')
  61. self.vblur = love.graphics.newShader('media/shaders/verticalBlur.shader')
  62. end