Custom Shader Builder

Started by
4 comments, last by Hodgman 7 years, 7 months ago

Hi everyone,

I want to make a custom shader builder for my shaders, so that I can build multiple times the same file setting different #defines... this way I can write a shader once, with multiple #defines setting the behaivor for when the engine provides a normalmap or uses x number of lights, if it has transparency, etc.

I believe this is called an Ubershader.

Has anyone built a custom builder in VisualStudio to do something like this? Or does anyone know of examples at how it can be done?.. I have no idea how to tell VisualStudio to build multiple times the same file passing different arguments.

Thanks!

"lots of shoulddas, coulddas, woulddas in the air, thinking about things they shouldda couldda wouldda donne, however all those shoulddas coulddas woulddas ran away when they saw the little did to come"
Advertisement

The file could be #included into many other source files, with the relevant #defines in place before the #include in each case.

I use this preprocessor for GLSL (which has no #include built in): http://mcpp.sourceforge.net/

Took some time to figure out how to get it to work with non C code, so here is example bat file:

(Still producing warnings, but it works)


del gi-visibility_brute-64.comp
del gi-visibility_brute-128.comp
del gi-visibility_brute-256.comp
mcpp -a -D "BIN = 0" -D "WG_WIDTH = 64"  gi\visibility_brute.comp.glsl -P gi-visibility_brute-64.comp
mcpp -a -D "BIN = 1" -D "WG_WIDTH = 128" gi\visibility_brute.comp.glsl -P gi-visibility_brute-128.comp
mcpp -a -D "BIN = 2" -D "WG_WIDTH = 256" gi\visibility_brute.comp.glsl -P gi-visibility_brute-256.comp

So this creates 3 shaders from one source file, automatically replacing BIN and WG_WIDTH with given values.

In the sdk, there's a command line tool called FXC.exe, which is the offline shader compiler. You can run "FXC /?" to see the command line options.

I wrote a C# app which scans my shader files for information about ubershader options, etc, and then it launches FXC repeatedly with the appropriate options.

Thanks Hodgman,

That's sounds exactly for what I was looking for. So I just have to create a C# app which runs the fx compiler with the different arguments, and tell Visual Studio to use that app when building the solution, instead of fxc.exe... sounds much easier than I initially thought.

I thought I'd have to build some kind of VisualStudio macro of such.

Thanks!

"lots of shoulddas, coulddas, woulddas in the air, thinking about things they shouldda couldda wouldda donne, however all those shoulddas coulddas woulddas ran away when they saw the little did to come"

Oh, sorry. No I don't build shaders from within visual studio.

I treat shaders like data, not code, so they get compiled at the same time as textures, meshes, materials do, not the same time as the C++ code.

This topic is closed to new replies.

Advertisement