Merging together multiple text files for GLSL Episode 7
Hi everyone,
Wow, what a week its been. I started with the idea to make a basic shader stitcher into a max package as my goal of the week.
It basically works like this, get a few text files from a folder, merge them into one big file using the text object, send that to a shader. Edit any single file, it re compiles your shader.
so:
01-XML-header.jxs
02-UniformsAndGLSL-Library.jxs
03-MainRenderFunction.jxs
04-XML-Footer.jxs
Becomes just one long text/jxs file top to bottom.
This is pretty much the only work flow with lots of GLSL scripts, scrolling through 500 lines of text to change a variable is just unhandy and a real slow way to work.
Then I discovered that this is a lot harder than it seems in Max due to reserved symbols and keywords.
Basically you want to work with GLSL data in Max ? then your in for a world of pain...
So XML needs this to stay intact
<jittershader name= "Shaping Functions" >
Max removes the quotation marks as thats reserved for a symbol.
So you have to go into your xml file and add a backslash by hand for every quotation mark to keep the symbols
<jittershader name= \"Shaping Functions\" >
Not handy, but if its only for a XML header, sure thing. This isn't 500 lines of text so lets just say that parts solved. Got a solution for me in a patching form ? , please add it to the patch and I'll say thanks on my tombstone.
next problem, the word float....
Its used all the time in GLSL, like this:
float circularInOut(float t) {
return t < 0.5000
? 0.5000 * (1.0 - sqrt(1.0 - 4.0000 * t * t))
: 0.5000 * (sqrt((3.0 - 2.0000 * t) * (2.0 * t - 1.0)) + 1.0);
}
This is where Max starts to freak out, understandable, its a reserved keyword. Put this into pretty much any object and max says:
float circularInOut , wow wait circularInOut is a symbol not a float. Busted.
The only way i could get around this is by getting the output of the text object which prepends the word set in front of every line, like this
set float circularInOut(float t)
set { return t < 0.5000 ? 0.5000 * (1.0 - sqrt(1.0 - 4.0000 * t * t))
set : 0.5000 * (sqrt((3.0 - 2.0000 * t) * (2.0 * t - 1.0)) + 1.0);
set }
To a substitue object like this:
substitute set " "
Those quotation marks with a space, swap the word set for an actual empty space to the front of every line and Max says "sure thats cool, move along", lets mark that one solved as well.
And last but not least, and this is where I'm stuck and no-one has a solution.
The semicolon
this symbol ;
I used to like this little guy....
This is also a reserved symbol in max. Check that previous function. You can't just add one at the end of every line because they're not on the end of every line.
Max drops this symbol like its hot when it gos into the text object, fus-ro-dah, just gone.
GLSL needs that just like every other programming language to know that the end of that piece of code has been reached.
So character handling in Max already sucks to an unknown level of suckability.
I get it, when cycling 74 started, GPU's were non-existent and you have to reserve keywords to do certain actions.
I also get cycling 74 ain't gonna break backwards comptatibility.
But i also get that this is something (at least for jitter GLSL users) that needs to be addressed.
With pure data I can send data unaltered, with Touch designer as well (check the merge object, so much wow), last but not least vvvv.
Max has a whole lotta nope. Can't we have some safe word like:
text @DoNotAlterDataThanksAndSoLongForAllTheFish 1
Which means, get data, don't alter.
People said, change your source data.
I'm not gonna change up to 50 files with some having over 400 lines of data by hand like
\"
and
"float BuddyKeepMyDataIntact(float x);"
It would break all my other software and Is just not an option.
I ain't doing it in Javascript due to horrible documentation and examples and thats pretty much the default answer for "our object can't do that so build it and learn a new programming language at the same time".
So the patch is close...Like real close, I've labelled it all as clearly as possible. Theres a copy compressed version, download those 4 .jxs files put in a folder and start it up.
If anyone can help me nail this me and very other Jitter/GLSL user will be eternally grateful.
Cycling 74. This is also a feature request. An object which can merge multiple text files together with all data intact or an extra mode for the text object.
Thanks for your time.
If you made it this far then your a winner !
Annnd it's a bump.