1.代码
#define PI 3.1415926
vec3 FullLineX(vec2 uv,float x){
if(uv.x >= x && uv.x < x + 0.005){
return vec3(1.0,0.0,0.0);
}
return vec3(0.0,0.0,0.0);
}
vec3 FullLineY(vec2 uv,float y){
if(uv.y >= y && uv.y < y + 0.005){
return vec3(1.0,0.0,0.0);
}
return vec3(0.0,0.0,0.0);
}
vec3 GridX(vec2 uv){
vec3 c = vec3(0.0,0.0,0.0);
for(float x = -0.5;x <= 0.5;x += 0.1){
c += FullLineX(uv,x);
}
for(float y = -0.5;y <= 0.5;y += 0.1){
c += FullLineY(uv,y);
}
return c;
}
mat2 rotate2d(float angle)
{
mat2 m = mat2(cos(angle),-sin(angle),sin(angle),cos(angle));
return m;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord.xy / iResolution.xy;
uv -= 0.5;
uv = uv * rotate2d(iTime / PI * 0.5);
vec3 c = GridX(uv);
fragColor = vec4(c,1.0);
}
没变换的:
变换后的