新渲染器OpenGL Core Profile模式基础物终于完成

30 1 月, 2011 by admin Leave a reply »

同上篇的三角形一样,虽然只是2个普通的方块,但它们确需要很高端的显卡。全OpenGL 3.3/4.1 Core Profile编程,文末附Shader.


vertex_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;
}

Advertisement

发表回复

You must be logged in to post a comment.
鄂ICP备09027626号