same shader for all objects but with different values

Hello, i m noobie with shaders, ibeen experimenting with them lately. My question is this:
I need to create a group of objects , each object is a sphere with the same shader but the shader has different values in each object.

Ive done this loading the shader for each object, so i have a ofShader object for each object(sphere). I was wondering myself if this practice is good practice, i ask this because when i create a 100 or more of spheres(objects) the app became slow.

I was wondering that maye i just need to lead one shader for all my objects that share the same shader, is this true? if so , how can i have each object with difrent shader value if i just have one shader object for all my spheres objects?

thanks

M.

Creating a shader per object is not a good idea as it will become expensive. It’s better to create a generalised shader which you pass in variables to to alter values based on which object it relates to. You need to probably pass in Uniforms which are basically shader variables you can control from your app.

http://www.lighthouse3d.com/opengl/glsl-…-ogluniform

hi, i know uniform variables, but is it possible to have one shader for all my objects and that the variables of the shader are different in each object?
is that possible?

thanks

Yes it’s possible, depends on how many variables you want though.
You can use a uniform array…and then another uniform which specifies the index into the array, or something like that.

Hi Matias,

That concept of use same shader using uniform variables could be great example to looks how it run, I would like to try that process. Could you publish some part of that shader example?

Thanks