ShaderScan - better iteration with shaders

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
idbrii
Prole
Posts: 34
Joined: Sat Jun 12, 2021 5:07 am

ShaderScan - better iteration with shaders

Post 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!
User avatar
idbrii
Prole
Posts: 34
Joined: Sat Jun 12, 2021 5:07 am

Re: ShaderScan - better iteration with shaders

Post 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!
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: ShaderScan - better iteration with shaders

Post 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.)
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: ShaderScan - better iteration with shaders

Post by yetneverdone »

This is cool, I'll check if i can add this to my project with a lot of shaders
User avatar
idbrii
Prole
Posts: 34
Joined: Sat Jun 12, 2021 5:07 am

Re: ShaderScan - better iteration with shaders

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 5 guests