I am having some problems understanding how lighting works in OpenGL (especially understanding the pre-defined variables. is there a list of them somewhere?). I have been messing around in my Vertex Shader file to shade my shpere. So I managed to shade it but I don't know what I did. Here is the code:
Vertex Shader:
#version 330
precision highp float;
in vec3 in_Position; //declare position
in vec3 in_Color; //color passed from the cpp file
//mycode
in vec3 in_Normal;
// mvpmatrix is the result of multiplying the model, view, and projection matrices */
uniform mat4 MVP_matrix;
vec3 ambient;
out vec3 ex_Color;
void main(void) {
// Multiply the MVP_ matrix by the vertex to obtain our final vertex position (mvp was created in *.cpp)
gl_Position = MVP_matrix * vec4(in_Position, 1.0);
//mycode
ambient = vec3(0.0f,0.1f,1.0f); // just a test vector
ambient = ambient * in_Position ; // HERE IS WHAT I DONT GET!
ex_Color = ambient;
}
I am multiplying each point on the sphere with a MVP matrix, and then with an ambient variable.
Fragment Shader:
#version 330
precision highp float;
in vec3 ex_Color;
out vec4 gl_FragColor;
void main(void) {
gl_FragColor = vec4(ex_Color,1.0);
}
What does "precision highp float;" does? I know that the vertex file passes the color to the fragment shader and then that fragment gets "interpolated". Ok how does interpolation works? How does Opengl know where to stop the interpolation ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…