Per-Material Parameterised Shaders?

Started by Draghi, May 12, 2014, 15:12:41

Previous topic - Next topic

Draghi

At the moment I'm working on implementing sub-systems for my game engine (I'm writing this in java using LWJGL in OpenGL 4.3, more or less as a learning project)

In particular I'm looking at Shaders and Materials in regard to how they'll interact with one another.

Presently, I'm passing data as uniforms left right and center to change how the global shader operates, however, what I'm looking to do is turn it into a system where each material has it's own shader.
This shader is, normally, based off of a larger, bulkier, "Main" shader, where it is somewhat preprocessed according to a param file before being sent off for compilation.
Sort of like compiler directives almost.


Here's my proposed param file for my current shader: Link

I feel that given the number of 'if' statements that the shader would need and the amount of data it would be sent warrants the increased memory consumption, the overhead of shader program state changes of this system and the initialization overhead of these shaders (however that could be minimized by saving that computed src and using that from there-after)


However, before I proceed with implementing it, I was hoping for some feedback, criticisms etc.

Would there be any noticeable performance increase? (or decrease for that matter)
Is there a better system than this? (As in faster, not necessarily simpler)
If you've implemented a system like this before, any warnings or suggestions?
What's the cost of an active shader state change vs changing a uniform?
Are if statements still expensive on GPUs? (I heard that, on mobile devices, it's very limiting in that respect)

Also, pardon me if this is all a bit incoherent, I wrote this all down on the back of a napkin and it's getting late. I'll have another read in the morning and expand/straighten things out.

Thanks for your time,
Draghi

(This has been cross-posted on another forum, for those interested: OpenGL Forum)