본문 바로가기
College Study/GLSL

[GLSL] Rotate and Scale

by 2den 2022. 1. 6.
728x90

 


mat2 rotate2d(float _angle){
    return mat2(cos(_angle),-sin(_angle),
                sin(_angle),cos(_angle));
}
 
#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;

float bar (vec2 loc, vec2 size, vec2 coord){
    vec2 lb = loc - size/2.;
    vec2 rt = loc + size/2.;
    
    vec2 st = step(lb, coord) - step(rt, coord);
    
    return st.x * st.y;
}

float cross(vec2 loc, vec2 size, vec2 coord){
    float b1 = bar(loc, size, coord);
    float b2 = bar(loc, vec2(size.y, size.x), coord);
    
    return max(b1, b2);
}

mat2 rotate2d(float _angle){
    return mat2(cos(_angle),-sin(_angle),
                sin(_angle),cos(_angle));
}

void main(){
	vec2 coord = gl_FragCoord.xy/u_resolution;
    coord.x *= u_resolution.x/u_resolution.y;
    coord = coord * 2. - 1.;
    coord *= rotate2d(sin(u_time)*4.)*sin(u_time); // line 34

    vec2 loc = vec2(0.); // + vec2(sin(u_time), cos(u_time))*.5;
    vec2 size = vec2(0.750,0.250);
    vec3 col = vec3(cross(loc, size, coord));
    
	gl_FragColor = vec4(col, 1.0);
}
 

In the line 34, multiply rotate2d matrix to coord for rotation, and multiply number for scaling.

 

 

728x90

'College Study > GLSL' 카테고리의 다른 글

[GLSL] Random  (0) 2022.01.06
[GLSL] Patterns  (0) 2022.01.06
[GLSL] Translate  (0) 2022.01.06
[GLSL] Polar Shapes  (0) 2022.01.06
[GLSL] Circle Shapes  (0) 2022.01.06

댓글