Jump to content
  • Advertisement
Sign in to follow this  
jakovo

Custom Shader Builder

This topic is 839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites

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.

Edited by JoeJ

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!