同上篇的三角形一样,虽然只是2个普通的方块,但它们确需要很高端的显卡。全OpenGL 3.3/4.1 Core Profile编程,文末附Shader.
#version 330
uniform mat4 projection_matrix;
uniform mat4 modelview_matrix;
in vec3 Vertex;
in vec3 Normal;
out vec3 fragment_normal;
void main(void)
{
fragment_normal=(modelview_matrix*vec4(Normal,0.0)).xyz;
gl_Position=projection_matrix*modelview_matrix*vec4(Vertex,1.0);
}
fragment_shader:
#version 330
in vec3 fragment_normal;
uniform vec4 color;
layout(location = 0, index = 0) out vec4 fragColor;
void main(void)
{
float intensity=max(dot(fragment_normal,vec3(0.0,0.0,1.0)),0.0);
fragColor=color*intensity;
}