Using #include inside shaders?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
idbrii
Prole
Posts: 34
Joined: Sat Jun 12, 2021 5:07 am

Using #include inside shaders?

Post by idbrii »

How can I #include or require() one glsl shader inside another in love2d so I don't need to copypaste common functions between shaders?

I use:

Code: Select all

#include "ladybug.glsl"
and I get:

> ERROR: '#include' : required extension not requested: GL_GOOGLE_include_directive

This answer hints that I need to set an include directive to enable the feature. I tried this and it seems to accept it:

Code: Select all

#extension GL_GOOGLE_include_directive : require
#include "ladybug.glsl"
But gives a new error:

> '#include' : Could not process include directive for header name: ladybug.glsl

I'm not sure what to do with that error message. ladybug.glsl is in the same directory as the current shader. I also tried the path from the folder containing main.lua.

This thread implies that I need to use a shader compiler, but what's the point of the include directive if that's the case?
User avatar
slime
Solid Snayke
Posts: 3142
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Using #include inside shaders?

Post by slime »

#include is not directly supported by love at the moment. It's not a native feature of GLSL either.

One option for you is to write a parser for your shaders to deal with #includes yourself, or a simpler (but less generic) option could be to manually concatenate the file contents you want together.
User avatar
idbrii
Prole
Posts: 34
Joined: Sat Jun 12, 2021 5:07 am

Re: Using #include inside shaders?

Post by idbrii »

slime wrote: Sun May 01, 2022 12:28 am One option for you is to write a parser for your shaders to deal with #includes yourself
Thanks for the suggestion! It worked great and I've finally extracted my solution and posted it online: shaderscan. In addition to handling includes, it outputs filenames in errors and auto reloads shaders on save.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 6 guests