In the olden DX8 days a common technique was to compile shaders at runtime using assembly instructions in strings. You would composite sections of pre-written shader based on how many lights were active, what type of material you were lighting and any other properties that would affect rendering.
This had two problems, in order of effect:
- You'd have to pass the assembly code onto the DX8 runtime which would then parse and compile it.
- You're doing a whole bunch of string concatenations everywhere. With dynamic register allocation, that means sprintf calls.
The reason runtime compilation was common was that precompiling all combinations offline was prohibitive as the total count would be in the 10s of thousands.
Anyway, I was never happy with the performance of compiling shaders at runtime; there'd be noticable hitching as the game would spend upwards of 100ms compiling. There were imperfect ways of stepping around the issue, like precompiling all shaders on specific offline camera paths, but you'd st