I'm trying to learn how to program vertex shaders. In Apple's sample project they have a line to set a
glUniform1f(uniforms[UNIFORM_TRANSLATE], (Glfloat)transY);
Then this value is used in
// value passt in f
// glUniform1f(uniforms[UNIFORM_TRANSLATE](Glfloat)transY);
uniform float translate;
void main()
{
gl_Position.y+=sin( translate);
…
I was unable to find a list of all uniforms of all the uniforms.
Does any one know where I can find a list of all the uniforms and a good book or tutorial on learning how to program vertex shaders.
Uniforms are intended to be set by the user from OpenGL, rather than within the shader. However, you can initialize them to a default value using standard GLSL initalizer syntax: uniform vec3 initialUniform = vec3(1.0, 0.0, 0.0); This will cause the uniform to have this vector as its value, until the user changes it.
After linking has occurred, the command glGetUniformLocation can be used to obtain the location of a uniform variable. This location value can then be passed to glGetUniform or glGetnUniform in order to query the current value of the uniform variable.
Vertex shader executes 3 X 5 = 15 times. Geometry shader executes only 3 times. Fragment shader executes as many as the involved pixels count.
The Vertex Shader is the programmable Shader stage in the rendering pipeline that handles the processing of individual vertices. Vertex shaders are fed Vertex Attribute data, as specified from a vertex array object by a drawing command.
Uniform parameter is a data passed to GL shader, which doesn't change during the draw call.
You can query a linked GLSL program for a list of active uniforms with the following code:
int total = -1;
glGetProgramiv( program_id, GL_ACTIVE_UNIFORMS, &total );
for(int i=0; i<total; ++i) {
int name_len=-1, num=-1;
GLenum type = GL_ZERO;
char name[100];
glGetActiveUniform( program_id, GLuint(i), sizeof(name)-1,
&name_len, &num, &type, name );
name[name_len] = 0;
GLuint location = glGetUniformLocation( program_id, name );
}
This code retrieves a number of active uniforms and iterates though them, extracting name, type, number of values and uniform locations.
In addition to kvark's answer. You can add these lines of code to get a nice and beautiful readable format of the most common uniforms:
std::cout << "Uniform Info Name: " << name << " Location: " << location << " Type: ";
if (type == GL_FLOAT_MAT4)
std::cout << "mat4";
else if (type == GL_FLOAT_VEC3)
std::cout << "vec3";
else if (type == GL_FLOAT_VEC4)
std::cout << "vec4";
else if (type == GL_FLOAT)
std::cout << "float";
else if (type == GL_INT)
std::cout << "int";
else if (type == GL_BOOL)
std::cout << "bool";
else if (type == GL_SAMPLER_2D)
std::cout << "sampler2d";
else
std::cout << type;
std::cout << std::endl;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With