PDA

View Full Version : Shaders/Materials



AdrianPi
11-01-2009, 11:27 AM
I imagine the number of shaders we can compile is a finite resource. I couldn't find a GetInteger for it.
However I can think of situations where the shader is the same, but only some uniforms or textures change.
For instance, we can have a bumpmap shader for all walls and floors in a FPS, but of course they use different textures or different bump factors (a uniform).
What would be the best approach?
To compile different shaders for each case, or to have a common shader and a sort of "material" entity, that refers to a particular shaders and contains a set of uniforms/textures to use?
Isn't settings uniforms painly slow?

Alfonse Reinheart
11-01-2009, 12:05 PM
I couldn't find a GetInteger for it.

Nor will you find a GetInteger for the number of buffer objects, textures, or any other object that you can create.


Isn't settings uniforms painly slow?

No more than any other state change would be.

You should not create a program for every instance of an object. You will simply have to set the uniforms and textures for each instance as needed. Uniform Buffers make this a bit easier, allowing you to allocate per-instance storage for each use of that shader.

Remember: every OpenGL game that uses shaders has to do this. So it's not the slowest thing in the world.

AdrianPi
11-01-2009, 12:59 PM
Thanks for your answer. At first I thought it would have required a big refactor, but now I'm just caching ShaderPrograms with vertexSourceFileName "+" fragmentSourceFileName as key when loading shaders.