gl_ModelViewProjectionMatrix vs gl_ModelViewMatrix

2019-06-08 11:10发布

问题:

I am beginner at GLSL. I was reading a vertex shader code and I don't understande this part of code:

out vec3 position;
...
gl_Position=gl_ModelViewProjectionMatrix*gl_Vertex; 
position=vec3(gl_ModelViewMatrix*gl_Vertex); 

What are the differences between gl_ModelViewProjectionMatrix and gl_ModelViewMatrix?

What are the differences between gl_Position and position?

回答1:

As you might suspect, gl_ModelViewProjectionMatrix is gl_ModelViewMatrix with the addition of the projection -- that is, the perspective camera distortion.

gl_Position is a predefined variable meaning "the projected result of this vertex shader" (all vertex shaders are required to assign a value to gl_Position), while the value "position" is an extra programmer-defined value that comes along for the ride (why is impossible to say, depends on the entire shader)



标签: glsl shader