I made a thing!
I’ve been creating an ever expanding Uber shader and needed better systems to manage it’s complexity. Specifically being able to share ShaderLab properties between shaders and complex preprocessor logic.
Behold!
~~~ ShaderLab…Lab ~~~
GitHub - TechArtistG/ShaderLabLab: A system using T4 Templates to generate Unity ShaderLab code in the Editor
It uses T4 Templating (Mono.TextTemplating) along with a custom asset import hook to create shaders from templates. Details in the readme on Github.
For example, this:
<#
for(int c = 0; c < 5; c++)
{
#>
_commonProp<#=c#> ("included prop <#=c#>", Float) = 0
<#
}
#>
Results in this:
_commonProp0 ("included prop 0", Float) = 0
_commonProp1 ("included prop 1", Float) = 0
_commonProp2 ("included prop 2", Float) = 0
_commonProp3 ("included prop 3", Float) = 0
_commonProp4 ("included prop 4", Float) = 0
Think of it as ASP.NET or PHP for shaders.
This could easily be expanded to a general Unity templating system but want to keep it shader specific.
I started this at about 9:30pm and its now 1:00am so there’s probably going to be some mistakes somewhere.
Happy to implement any suggestions so have at 'er!
TNKS!
Geordie
Technical Art Director
Windows Photos and Videos
Microsoft