I’ve seen that in the Monogame base effect shader files (basically the same like XNA) there are dozens of different permutations of shader functions eg
TECHNIQUE( BasicEffect_PixelLighting, VSBasicPixelLighting, PSBasicPixelLighting ); 484 TECHNIQUE( BasicEffect_PixelLighting_NoFog, VSBasicPixelLighting, PSBasicPixelLighting ); 485 TECHNIQUE( BasicEffect_PixelLighting_VertexColor, VSBasicPixelLightingVc, PSBasicPixelLighting ); 486 TECHNIQUE( BasicEffect_PixelLighting_VertexColor_NoFog, VSBasicPixelLightingVc, PSBasicPixelLighting );
Is there a more elegant way? Can I have #defines and #ifdef Ubershader style which I incorporate into different Techniques and make them use the same VertexShaders/Pixelshaders but with different #defines?
I know big engines like CryEngine create giant shader files with all the different permutations into different shaders.
It’s really wierd to find basically no useful information on Ubershaders at all on google, and some advice on best practice would be appreciated
And how taxing is it to have multiple [branch] ifs for different settings that I want to change in runtime for let’s say different shadowing and lighting techniques?
You don´t want to branch in shader. Definitely not multiple branching. Altho modern GPUs can deal slightly better with predictive instructions it is still not something you would like to do.
#ifdef is preprocessor keyworld. So you basically want to compile shader many times with different ifdef settings, what’s the gain here compared to use of techniques? Anyway since XNA shader’s are greatly outdated I wouldn’t worry about it too much, imho, thus you can pick whatever you like in your own shaders but personally I am using techniques too… apart from FXAA where I stick with original ifdef for different pefromance profiles (which also means I need two or three compiled versions of that shader).
Anyway my personal opinion: If you want to see nice, elegant solutions that are actually really usable then look into UE, not CE.
In the custom engine we used at my previous job, we used a customised shader syntax that extended the technique syntax so we could specify separate #defines for each technique in a shader file. I’ve been trying to think how that could be added to our system, but it’s not a simple task with our pre-processing of the shader code.
that was exactly what I was looking for, but I guess that’s quite some work to implement, right?