# Change value of uniform for each VAO

I've heard from several sources that it's a better approach to pass the model matrix to a shader via a uniform rather than an attribute.

I also know that the idea of a uniform is, that it has the same value for each frame.

If so, how can i change the uniforms value for each object i have in the scene?

## 1 Answer

You can make a uniform for as many things as you want, including per object. If you want object A) to have a different uniform then object B), then create one for each item and bind it to the shader when it is time for that object to render. Any given object in a scene can have many uniform variables.

This technique applies also to any sort of post-processing effects like lighting, in which each light may have its own color/direction/position, and can set its own uniforms for when it is going to render.

void RenderObjectA()
{
GLuint shaderID = getShaderProgramID();
GLuint uniformID = glGetUniformLocation(shaderID,"<desired uniform's name>");
glUniform<varies based on type used>(uniformID, <desired uniform>)
}

void RenderObjectB()
{
GLuint shaderID = getShaderProgramID();
GLuint uniformID = glGetUniformLocation(shaderID,"<desired uniform 2's name>");
glUniform<varies based on type used>(uniformID, <desired uniform 2>)
}