DemoCoder said:I still don't see where these oodles of shaders come from. There are a finiite number of material types and lighting equations, I simply don't see the combinatorial explosion.
Are there any games today that use 10,000 textures?
The ideal is perfectly optimised unique shading, each surface executes the shortest program that can generate the correct fragments.
We don't do that (for resource generation issues, more than any other reason). We do have a long list of visual fragments, i.e. diffuse lighting, specular lighting, bump map, fog, env map, etc. Each fragment has a list of input paramters used, the artists fiddle, decide what looks 'right' and then we compute the required shader code. With say 10 fragments + 5 parameters each you get 50 fragments, probably 2 shaders per fragment (1 vertex and 1 pixel shader) + per-object data (bones, tweened, vertex compression, different combination of lights etc). So 50 shaders with 20 different objects, gives you 1000 'short' shaders. Or you have a shader with all fragments using branches (or 0's to remove that component) with 20 different objects, gives you 20 'long' shaders. As shaders get more powerfull, the number of fragment will increase quickly, even with exclusivity between certain peices, its still going to be loads of shaders.
Now of course, not all are in use at one time BUT potentially over a big game, lots could be used.
Even today in CGI, nobody applies a single Renderman shader to each surface, they layer multiple shaders together (one layer metal, next layer rust, add a relectivity layer (due to a water etc), then several shadow map layers). Were doing basically the same thing but with performance being our number 1 priority.
The visual affect is the same, the small fragment method may reduce run-time but it may also increase run-time due to less batching. But then we don't batch anywhere near as much as IHV's would like due to using real art and not benchmarks, so as long as the small shader method doesn't reduce batching below the level with the 'long' shaders, small shaders should be a win (ignoring driver issues).
We have over 30,000 resources at the moment (a resource being a texture, model, sound etc). We recently removed using filenames to access them as that was taking several megabytes on there own (now a 4 byte ID to refer to each resource).