Page 1 of 1

ShaderScan - better iteration with shaders

Posted: Mon Aug 29, 2022 4:41 am
by idbrii
ShaderScan provides a better iteration workflow with shaders. The library is a single file with no external dependencies.

Features:
  • reloads shaders when they're saved
  • include shaders into other shaders
  • handles circular include dependencies
  • errors output correct filename and line number
  • send uniforms to shaders and ignore unused errors

ShaderScan on GitHub
Direct link to file
Example
MIT License

Live Reload

See shader changes live in your game.

Code: Select all

local ShaderScan = require 'shaderscan'
shaders = ShaderScan()
shaders:load_shader('splitcolor', 'shaders/splitcolor.glsl')
function love.update(dt)
    -- Reloads shaders if the file changed. Keeps the original shader
    -- if there was an error. Omit this line from production builds.
    shaders:update(dt)
end
function love.draw()
    love.graphics.setShader(shaders.s.splitcolor)
    love.graphics.circle('fill', 400, 400, 500, 500)
end
Adds #include

Use #include directives to organize your shader code. All includes are relative to your project's root (the location of main.lua). They're processed at runtime and error reporting will report the correct file and line number.

Code: Select all

#include "example/lib/math.glsl"

Better Errors

Get errors with file, line number, and the specific line that failed:

Code: Select all

Error: shaderscan.lua:129: Loading 'splitcolor' failed: Error validating pixel shader code:
example/splitcolor.glsl:26: in 'splitcolor' ERROR: 'progres' : undeclared identifier
example/splitcolor.glsl:26: in 'splitcolor' ERROR: '' : compilation terminated
ERROR: 2 compilation errors.  No code generated.
File: example/splitcolor.glsl
Line:
    return mix(left, right, smoothstep01(progres));
Even works in included files!

Re: ShaderScan - better iteration with shaders

Posted: Mon Aug 29, 2022 4:48 am
by idbrii
Awhile back I was trying to follow Painting a Landscape with Maths in lua and wrote ShaderScan to make the workflow more enjoyable. I love hot reload, and it's even easier with shaders since they don't make your game crash! I use vim, so when the output includes the file and line number I can easily jump to the errors.

Along the way, made some foolish mistakes (not knowing about #pragma language glsl3) and had lots of code to implement newer language features. But also, as my project grew more complex, it was awkward to navigate. So now ShaderScan supports includes and I can organize my shader into multiple files.

I haven't worked on my shader project for a few months, but had some time to pull this out into a separate project. I hope it's useful to someone!

Re: ShaderScan - better iteration with shaders

Posted: Mon Aug 29, 2022 10:03 pm
by ReFreezed
As a fellow fan of hot-loading, this is indeed a useful library!

I noticed a couple of unhandled cases: commented out includes, and things after the #include string.

Code: Select all

// Both gets included.
#include "foo1.glsl"
// #include "foo2.glsl"

// Error.
#include "foo.glsl" // "quote"
(Also, funnily enough, I just recently saw that very YouTube video by following a link from Shadertoy. It's very cool.)

Re: ShaderScan - better iteration with shaders

Posted: Tue Aug 30, 2022 1:30 am
by yetneverdone
This is cool, I'll check if i can add this to my project with a lot of shaders

Re: ShaderScan - better iteration with shaders

Posted: Tue Aug 30, 2022 6:39 am
by idbrii
ReFreezed wrote: Mon Aug 29, 2022 10:03 pm As a fellow fan of hot-loading, this is indeed a useful library!

I noticed a couple of unhandled cases: commented out includes, and things after the #include string.
Thanks! I'll make a note about those issues.