blog.csdn.net/qq_43758883…

- 原始的MatCap在左侧,生成的着色表面在右侧。
- 可以跟UV无关
Vertex Shader
- 顶点着色器用来将模型顶点的法向量转化为视点坐标系下的法向量,并获得该法线中的xy分量
varying vec2 Point;
void main()
{
vec3 vNormal = ( mat3( modelViewMatrix ) * normal );
vNormal = normalize(vNormal);
// vNormal 的 x, y分量
Point.x = vNormal.x * 0.5 + 0.5; //把normal区间缩放到[0,1]之间
Point.y = vNormal.y * 0.5 + 0.5;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
Fragment Shader
uniform sampler2D Matcap; // Matcap纹理
varying vec2 Point;
void main(void){
// texture2D()获取颜色值
vec4 color = texture2D(Matcap, Point);
// 改片元的颜色值为对应坐标下的MatCap的颜色值
gl_FragColor = color;
}