Skip to content
FloatingBanana edited this page Mar 18, 2021 · 5 revisions

Introduction

chainshaders.lua lets you use two or more shaders at once. Can also be used to apply shaders as post processing effect.

Example

chain = require "grove.chainshaders"

otherChain = nil
image = love.graphics.newImage("image.png")

--Shaders
ctr = love.graphics.newShader("shaders/ctr.shader")
dessaturate = love.graphics.newShader("shaders/dessaturate.shader")
boxblur = love.graphics.newShader("shaders/boxblur.shader")
filmgrain = love.graphics.newShader("shaders/filmgrain.shader")

function love.load()
    chain.append(crt)

    --Creating other instances
    otherChain = chain()
end

function love.draw()
    chain.start(dessaturate)
      love.graphics.setColor(1,0,0)
      love.graphics.circle("fill", 100, 100, 50, 5)

      --Nested chain
      otherChain:start(boxblur, filmgrain)
        love.graphics.setColor(1,1,1)
        love.graphics.draw(image, 200, 100)
      otherChain:stop()

    chain.stop()
end

Functions

chain.start(...)

Start applying shaders.

... (shaders): Shaders to be applied.


chain.stop()

Stop applying shaders and draw the results to screen.


chain.append(...)

Appends one or more shaders. These will aways be applied before the shaders passed to chain.start().

... (shaders): Shaders to be appended.


chain.removeAppended(...)

Remove specified appended shaders.

... (shaders): Shaders to be removed.


chain.clearAppended()

Remove all appended shaders.


chain.resize(width, height)

Resize the effective area.

width (number): The width of the area. Defaults to love.graphics.getWidth().

heigh (number): The height of the area. Defaults to love.graphics.getHeight().


chain(width, height)

Create another chain instance. Remember to call the functions with the : operator. Ex: instance:start().

width (number): The width of the area. Defaults to love.graphics.getWidth().

heigh (number): The height of the area. Defaults to love.graphics.getHeight().