shader-school是glsl语言入门基础的好教程,我简单分享一下自己做的答案。
题目是vertex shader的the basics,简单用旋转矩阵就过了。
代码如下:
precision highp float;
uniform float theta;
attribute vec2 position;
void main() {
//TODO: rotate position by theta radians about the origin
float newx=cos(theta)*position.x-sin(theta)*position.y;//新X坐标
float newy=sin(theta)*position.x+cos(theta)*position.y;//新Y坐标
gl_Position = vec4(newx,newy, 0, 1.0);
}