![]()
学以致用。:)
不过略有不同的是我没有采用根据光线强度设置纹理坐标的方式,而是根据光线强度直接确定的当前象素的颜色值。
SHADER代码如下:
VertexShader
//-----------------------------------------------------------------------------
// vertex shader
//-----------------------------------------------------------------------------
![]()
uniform vec3 LightPosition;
varying float diffuse;
![]()
![]()
void main(void)
{
vec3 ecPosition = vec3 (gl_ModelViewMatrix * gl_Vertex);
vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);
vec3 lightVec = normalize(LightPosition - ecPosition);
diffuse = max(dot(lightVec, tnorm), 0.0);
![]()
gl_Position = ftransform();
}
FragmentShader
//-----------------------------------------------------------------------------
// fragment shader
//-----------------------------------------------------------------------------
![]()
varying float diffuse;
![]()
![]()
void main(void)
{
vec4 color;
![]()
if (diffuse > 0.66)
color = vec4(0.75, 0.75, 0.75, 1);
else if (diffuse > 0.33)
color = vec4(0.63, 0.63, 0.63, 1);
else
color = vec4(0.50, 0.50, 0.50, 1);
![]()
gl_FragColor = color;
}
下一步是勾边。
posted @
2004-08-19 22:46
Pointer
阅读(
637)
评论()
收藏
举报