1.函数
precision lowp float; //不指定精度会报错
vec4 color2(){
vec4 v4 = vec4(1.0,0.0,0.0,1.0);
return v4;
}
void main(){
if(true) {
gl_FragColor= color2();
}else{
gl_FragColor= vec4(1.0,1.0,1.0,1.0);
}
}
2.结构体
struct myVec4{
float fl;
vec4 v4;
}; //注意结构体有分号
void main(){
myVec4 myV= myVec4(2.0,vec4(1.0,1.0,1.0,1.0));
gl_FragColor= myV.v4;
}
3.for循环
int temp =0;
for(int i=0; i<2; i++) {
temp++;
}
if(temp==2) {
gl_FragColor= myV.v4;
}
4.数组
floatc[4]; 数组不能在声明时被一次性地初始化,而必须显式地对每个元素进行初始化
c[0] =1.0;
c[1] =1.0;
c[2] =1.0;
c[3] =1.0;
gl_FragColor=vec4(c[0],c[1],c[2],c[3]);