[LIBRARY] POSTER v0.3 - Post processing shaders made simple.
Posted: Tue Oct 05, 2021 10:55 pm
Hello! So i was working on some stuff and ended up completely abandoning it to go on a huge detour into shaders. That detour resulted in this library which i've decided to call POSTER. I want to say that the name stands for "Post processing On STERoids", Cause that would be quite clever, But i don't think this library lives up to such a name. So it's just POSTER. All caps for style.
It's kind of an extension to pp.lua which i made recently, But it comes with a collection of shaders and some more stuff. So its more akin to something like moonshine
It aims to make applying post processing shaders to your game straight forward, While being pretty flexible.
As usually, It's properly documented over on github. It's a bit of a work in progress, I'd love it if you could try it out, And let me know what features it's missing and whats broken etc.
First, Here's what it can do:
Turn this garbage Into this Which i think we can all agree looks better
Basic usage:
Load it:
Make a canvas:
Draw your game, Or whatever you want to the canvas like
or
Draw your canvas and apply lovely post processing shaders to the canvas like:
The draw function can either take a mix of strings, Referencing the built in shaders and/or references to your own shaders, Or chains, Which i'll get to in a moment
To control the built in shaders, You need to send them some uniforms(externs), Which shaders need what uniforms exactly is also explained on github. To send data to shaders you use the following funciton:
where shader is a string, Referencing the shader, Uniform is also a string, Referencing the specific uniform, And data is the data.
You can also pass it a table with a format like
But those uniforms will be global, A better way is using the aforementioned chains. Which i'll explain now.
To create a new chain you can either
Or a slightly "cleaner" but less compact
Or some combination of the 2 methods
Then you apply the chains with the draw function
One thing that's obviously missing from this at the moment is a way to animate chained shaders, I have some ideas for that that i still have to iron out. It's pretty easy to do so globally, Just continuously update a uniform with poster:send(). If you have any other ideas for features or changes, I'm all ears. Thank you!
EDIT: I think i've fixed the issue of not being able to animate chained shaders. I added "macros" to the chain system. You can define a macro like this:
Where macroName is the name used to refer to the macro, And targets is a table like
Then you can control the macro with
It's kind of an extension to pp.lua which i made recently, But it comes with a collection of shaders and some more stuff. So its more akin to something like moonshine
It aims to make applying post processing shaders to your game straight forward, While being pretty flexible.
As usually, It's properly documented over on github. It's a bit of a work in progress, I'd love it if you could try it out, And let me know what features it's missing and whats broken etc.
First, Here's what it can do:
Turn this garbage Into this Which i think we can all agree looks better
Basic usage:
Load it:
Code: Select all
poster = require("poster")
Code: Select all
canvas = poster.new() -- I should probably rename this to "newCanvas". Just realized.
Code: Select all
canvas:drawTo(function()
-- Draw stuff
end)
Code: Select all
canvas:set()
-- Draw stuff
canvas:unset()
Code: Select all
canvas:draw("rgbMix", "saturation", "verticalBlur")
To control the built in shaders, You need to send them some uniforms(externs), Which shaders need what uniforms exactly is also explained on github. To send data to shaders you use the following funciton:
Code: Select all
poster:send(shader, uniform, data)
You can also pass it a table with a format like
Code: Select all
{
{shader, uniform, data},
{shader, uniform, data},
{shader, uniform, data},
...
}
To create a new chain you can either
Code: Select all
blur = poster.newChain({"verticalBlur", "horizontalBlur"}, {{"verticalBlur", "amount", 3}, {"horizontalBlur", "amount", 3}})
Or a slightly "cleaner" but less compact
Code: Select all
blur = poster.
blur:addShader("verticalBlur", "horizontalBlur")
blur:addSetting("verticalBlur", "amount", 3)
blur:addSetting("horizontalBlur", "amount", 3)
Then you apply the chains with the draw function
Code: Select all
canvas:draw(blur)
One thing that's obviously missing from this at the moment is a way to animate chained shaders, I have some ideas for that that i still have to iron out. It's pretty easy to do so globally, Just continuously update a uniform with poster:send(). If you have any other ideas for features or changes, I'm all ears. Thank you!
EDIT: I think i've fixed the issue of not being able to animate chained shaders. I added "macros" to the chain system. You can define a macro like this:
Code: Select all
chain:addMacro(macroName, Targets)
Code: Select all
{
{shader, uniform, multiplier},
{shader, uniform, multiplier},
...
}
Code: Select all
chain:setMacro(macroName, value)